Commit 8eec0924 authored by Filipa Lacerda's avatar Filipa Lacerda

Sets callout dissmiss cookie per project using a path

parent 89e5bc5e
...@@ -156,7 +156,7 @@ import initChangesDropdown from './init_changes_dropdown'; ...@@ -156,7 +156,7 @@ import initChangesDropdown from './init_changes_dropdown';
new UsersSelect(); new UsersSelect();
break; break;
case 'projects:merge_requests:index': case 'projects:merge_requests:index':
new UserCallout(); new UserCallout({ setCalloutPerProject: true });
break; break;
case 'projects:merge_requests:index': case 'projects:merge_requests:index':
case 'projects:issues:index': case 'projects:issues:index':
...@@ -346,7 +346,7 @@ import initChangesDropdown from './init_changes_dropdown'; ...@@ -346,7 +346,7 @@ import initChangesDropdown from './init_changes_dropdown';
case 'projects:show': case 'projects:show':
shortcut_handler = new ShortcutsNavigation(); shortcut_handler = new ShortcutsNavigation();
new NotificationsForm(); new NotificationsForm();
new UserCallout(); new UserCallout({ setCalloutPerProject: true });
if ($('#tree-slider').length) new TreeView(); if ($('#tree-slider').length) new TreeView();
if ($('.blob-viewer').length) new BlobViewer(); if ($('.blob-viewer').length) new BlobViewer();
...@@ -367,7 +367,7 @@ import initChangesDropdown from './init_changes_dropdown'; ...@@ -367,7 +367,7 @@ import initChangesDropdown from './init_changes_dropdown';
new NewBranchForm($('.js-new-pipeline-form')); new NewBranchForm($('.js-new-pipeline-form'));
break; break;
case 'projects:pipelines:index': case 'projects:pipelines:index':
new UserCallout(); new UserCallout({ setCalloutPerProject: true });
break; break;
case 'projects:pipelines:builds': case 'projects:pipelines:builds':
case 'projects:pipelines:failures': case 'projects:pipelines:failures':
...@@ -426,7 +426,7 @@ import initChangesDropdown from './init_changes_dropdown'; ...@@ -426,7 +426,7 @@ import initChangesDropdown from './init_changes_dropdown';
new TreeView(); new TreeView();
new BlobViewer(); new BlobViewer();
new NewCommitForm($('.js-create-dir-form')); new NewCommitForm($('.js-create-dir-form'));
new UserCallout(); new UserCallout({ setCalloutPerProject: true });
$('#tree-slider').waitForImages(function() { $('#tree-slider').waitForImages(function() {
gl.utils.ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath); gl.utils.ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
}); });
......
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
export default class UserCallout { export default class UserCallout {
constructor(className = 'user-callout') { constructor(options = {}) {
this.options = options;
const className = this.options.className || 'user-callout';
this.userCalloutBody = $(`.${className}`); this.userCalloutBody = $(`.${className}`);
this.cookieName = this.userCalloutBody.data('uid'); this.cookieName = this.userCalloutBody.data('uid');
this.isCalloutDismissed = Cookies.get(this.cookieName); this.isCalloutDismissed = Cookies.get(this.cookieName);
...@@ -17,7 +21,11 @@ export default class UserCallout { ...@@ -17,7 +21,11 @@ export default class UserCallout {
dismissCallout(e) { dismissCallout(e) {
const $currentTarget = $(e.currentTarget); const $currentTarget = $(e.currentTarget);
Cookies.set(this.cookieName, 'true', { expires: 365 }); if (this.options.setCalloutPerProject) {
Cookies.set(this.cookieName, 'true', { expires: 365, path: gon.project_url });
} else {
Cookies.set(this.cookieName, 'true', { expires: 365 });
}
if ($currentTarget.hasClass('close')) { if ($currentTarget.hasClass('close')) {
this.userCalloutBody.remove(); this.userCalloutBody.remove();
......
...@@ -5,6 +5,7 @@ class Projects::ApplicationController < ApplicationController ...@@ -5,6 +5,7 @@ class Projects::ApplicationController < ApplicationController
before_action :redirect_git_extension before_action :redirect_git_extension
before_action :project before_action :project
before_action :repository before_action :repository
before_action :add_gon_project_variables
layout 'project' layout 'project'
helper_method :repository, :can_collaborate_with_project? helper_method :repository, :can_collaborate_with_project?
......
...@@ -28,5 +28,9 @@ module Gitlab ...@@ -28,5 +28,9 @@ module Gitlab
gon.current_user_avatar_url = current_user.avatar_url gon.current_user_avatar_url = current_user.avatar_url
end end
end end
def add_gon_project_variables
gon.project_url = project_url(project)
end
end end
end end
...@@ -33,4 +33,26 @@ describe('UserCallout', function () { ...@@ -33,4 +33,26 @@ describe('UserCallout', function () {
this.userCalloutBtn.click(); this.userCalloutBtn.click();
expect(Cookies.get(USER_CALLOUT_COOKIE)).toBe('true'); expect(Cookies.get(USER_CALLOUT_COOKIE)).toBe('true');
}); });
describe('Sets cookie with setCalloutPerProject', () => {
let originalGon;
beforeEach(() => {
originalGon = window.gon;
window.gon = Object.assign({}, {
project_url: 'http://localhost:3000/gitlab-org/gitlab-ce',
});
this.userCallout = new UserCallout({ setCalloutPerProject: true });
});
afterEach(() => {
window.gon = originalGon;
});
it('sets a cookie when the user clicks the close button', () => {
this.userCalloutBtn.click();
// Note the path of a cookie is not accessible via JS, we can not test for that
// We can test if a cookie is set when an option is provided
expect(Cookies.get(USER_CALLOUT_COOKIE)).toBe('true');
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment