Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Make TopBar Public By Default
Browse files Browse the repository at this point in the history
  • Loading branch information
codydaig committed Aug 14, 2015
1 parent 86b16c9 commit e68b422
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 58 deletions.
3 changes: 2 additions & 1 deletion modules/articles/client/config/articles.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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']
});
}
]);
3 changes: 2 additions & 1 deletion modules/chat/client/config/chat.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ angular.module('chat').run(['Menus',
// Set top bar menu items
Menus.addMenuItem('topbar', {
title: 'Chat',
state: 'chat'
state: 'chat',
roles: ['user']
});
}
]);
25 changes: 8 additions & 17 deletions modules/core/client/services/menus.client.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ angular.module('core').service('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 {
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;
Expand Down Expand Up @@ -60,7 +56,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
Expand Down Expand Up @@ -92,7 +87,6 @@ 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),
position: options.position || 0,
items: [],
Expand Down Expand Up @@ -124,7 +118,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
Expand Down Expand Up @@ -171,8 +164,6 @@ angular.module('core').service('Menus', [
};

//Adding the topbar menu
this.addMenu('topbar', {
isPublic: false
});
this.addMenu('topbar');
}
]);
47 changes: 8 additions & 39 deletions modules/core/tests/client/menus.client.service.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
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(['*']);
});
Expand All @@ -45,10 +41,6 @@
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();
});
Expand All @@ -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);
});
Expand All @@ -99,12 +80,12 @@
expect(menu.shouldRender()).toBeTruthy();
});

it('should not render if menu is private', function() {
menu = Menus.addMenu('menu1', {
isPublic: false
});
expect(menu.shouldRender()).toBeFalsy();
});
// it('should not render if menu is private', function() {
// menu = Menus.addMenu('menu1', {
// isPublic: false
// });
// expect(menu.shouldRender()).toBeFalsy();
// });
});

describe('when logged in', function() {
Expand Down Expand Up @@ -250,10 +231,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);
});
Expand All @@ -278,8 +255,8 @@
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() {
Expand Down Expand Up @@ -393,10 +370,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);
});
Expand Down Expand Up @@ -424,10 +397,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('');
});
Expand Down

0 comments on commit e68b422

Please sign in to comment.