diff --git a/modules/articles/client/config/articles.client.config.js b/modules/articles/client/config/articles.client.config.js index 5ad71e82dd..c44990dc9e 100644 --- a/modules/articles/client/config/articles.client.config.js +++ b/modules/articles/client/config/articles.client.config.js @@ -7,7 +7,8 @@ angular.module('articles').run(['Menus', Menus.addMenuItem('topbar', { title: 'Articles', state: 'articles', - type: 'dropdown' + type: 'dropdown', + roles: ['*'] }); // Add the dropdown list item @@ -19,7 +20,8 @@ angular.module('articles').run(['Menus', // Add the dropdown create item Menus.addSubMenuItem('topbar', 'articles', { title: 'Create Articles', - state: 'articles.create' + state: 'articles.create', + roles: ['user'] }); } ]); diff --git a/modules/core/client/services/menus.client.service.js b/modules/core/client/services/menus.client.service.js index df9b5eafe2..4273fbe927 100644 --- a/modules/core/client/services/menus.client.service.js +++ b/modules/core/client/services/menus.client.service.js @@ -4,27 +4,26 @@ angular.module('core').service('Menus', [ function () { // Define a set of default roles - this.defaultRoles = ['*']; + this.defaultRoles = ['user', 'admin']; // Define the menus object this.menus = {}; // A private function for rendering decision var shouldRender = function (user) { - if (user) { - if (!!~this.roles.indexOf('*')) { - return true; - } else { - for (var userRoleIndex in user.roles) { - for (var roleIndex in this.roles) { - if (this.roles[roleIndex] === user.roles[userRoleIndex]) { - return true; - } + if (!!~this.roles.indexOf('*')) { + return true; + } else { + if(!user) { + return false; + } + for (var userRoleIndex in user.roles) { + for (var roleIndex in this.roles) { + if (this.roles[roleIndex] === user.roles[userRoleIndex]) { + return true; } } } - } else { - return this.isPublic; } return false; @@ -60,7 +59,6 @@ angular.module('core').service('Menus', [ // Create the new menu this.menus[menuId] = { - isPublic: ((options.isPublic === null || typeof options.isPublic === 'undefined') ? true : options.isPublic), roles: options.roles || this.defaultRoles, items: options.items || [], shouldRender: shouldRender @@ -92,8 +90,7 @@ angular.module('core').service('Menus', [ state: options.state || '', type: options.type || 'item', class: options.class, - isPublic: ((options.isPublic === null || typeof options.isPublic === 'undefined') ? this.menus[menuId].isPublic : options.isPublic), - roles: ((options.roles === null || typeof options.roles === 'undefined') ? this.menus[menuId].roles : options.roles), + roles: ((options.roles === null || typeof options.roles === 'undefined') ? this.defaultRoles : options.roles), position: options.position || 0, items: [], shouldRender: shouldRender @@ -124,7 +121,6 @@ angular.module('core').service('Menus', [ this.menus[menuId].items[itemIndex].items.push({ title: options.title || '', state: options.state || '', - isPublic: ((options.isPublic === null || typeof options.isPublic === 'undefined') ? this.menus[menuId].items[itemIndex].isPublic : options.isPublic), roles: ((options.roles === null || typeof options.roles === 'undefined') ? this.menus[menuId].items[itemIndex].roles : options.roles), position: options.position || 0, shouldRender: shouldRender @@ -172,7 +168,7 @@ angular.module('core').service('Menus', [ //Adding the topbar menu this.addMenu('topbar', { - isPublic: false + roles: ['*'] }); } ]); diff --git a/modules/core/tests/client/menus.client.service.tests.js b/modules/core/tests/client/menus.client.service.tests.js index e693eae448..adb4c76cd6 100644 --- a/modules/core/tests/client/menus.client.service.tests.js +++ b/modules/core/tests/client/menus.client.service.tests.js @@ -17,12 +17,8 @@ expect(Menus.menus.topbar).toBeDefined(); }); - it('should have private topbar', function() { - expect(Menus.menus.topbar.isPublic).toBeFalsy(); - }); - - it('should have default roles to *', function() { - expect(Menus.defaultRoles).toEqual(['*']); + it('should have default roles to user and admin', function() { + expect(Menus.defaultRoles).toEqual(['user', 'admin']); }); describe('addMenu', function() { @@ -45,12 +41,8 @@ expect(menu.items).toEqual([]); }); - it('should be public by default', function() { - expect(menu.isPublic).toBeTruthy(); - }); - it('should set shouldRender to shouldRender function handle', function() { - expect(menu.shouldRender()).toBeTruthy(); + expect(menu.shouldRender()).toBeFalsy(); }); }); @@ -64,17 +56,6 @@ menu = Menus.addMenu('menu1', options); }); - it('should set isPublic to true if options.isPublic equal to null', function() { - var menu = Menus.addMenu('menu1', { - isPublic: null - }); - expect(menu.isPublic).toBeTruthy(); - }); - - it('should set isPublic to true if options.isPublic equal to undefined', function() { - expect(menu.isPublic).toBeTruthy(); - }); - it('should set items to options.items list', function() { expect(menu.items).toBe(options.items); }); @@ -98,13 +79,6 @@ it('should render if menu is public', function() { expect(menu.shouldRender()).toBeTruthy(); }); - - it('should not render if menu is private', function() { - menu = Menus.addMenu('menu1', { - isPublic: false - }); - expect(menu.shouldRender()).toBeFalsy(); - }); }); describe('when logged in', function() { @@ -250,10 +224,6 @@ expect(menuItem.class).toBe(menuItemOptions.class); }); - it('should set menu item isPublic to options isPublic', function() { - expect(menuItem.isPublic).toBe(menuItemOptions.isPublic); - }); - it('should set menu item position to options position', function() { expect(menuItem.position).toBe(menuItemOptions.position); }); @@ -278,12 +248,12 @@ expect(menuItem.title).toBe(''); }); - it('should set menu item isPublic to menu.isPublic', function() { - expect(menuItem.isPublic).toBe(menu.isPublic); + it('should set menu item isPublic to false', function() { + expect(menuItem.isPublic).toBeFalsy(); }); - it('should set menu item roles to menu roles', function() { - expect(menuItem.roles).toEqual(menu.roles); + it('should set menu item roles to default roles', function() { + expect(menuItem.roles).toEqual(Menus.defaultRoles); }); it('should set menu item position to 0', function() { @@ -393,10 +363,6 @@ expect(menuItem1.items.length).toBe(1); }); - it('should set isPublic to options isPublic', function() { - expect(subMenuItem.isPublic).toBe(subItemOptions.isPublic); - }); - it('should set title to options title', function() { expect(subMenuItem.title).toBe(subItemOptions.title); }); @@ -424,10 +390,6 @@ expect(menuItem2.items.length).toBe(1); }); - it('should set isPublic to parent isPublic', function() { - expect(subMenuItem.isPublic).toBe(menuItem2.isPublic); - }); - it('should set title to blank', function() { expect(subMenuItem.title).toBe(''); });