Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

ng-admin role-based system #8

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from

Conversation

akagadovskiy
Copy link

Hi. I've found the tweak for creating ability for role-based access to different parts of functionality in admin. Without any changes in admin-config or ng-admin core repository. Role-based access can be achieved using different configurations for different roles. Naive demo uses simple localStorage without any providers.

if ($window.$get().localStorage.getItem('posters_galore_login') == 'admin') {
//admin config
} else {
//user config
}

admin.addEntity(nga.entity('products').readOnly());

// configure entities
require('./customers/userConfig')(nga, admin);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of duplicating the conf, I'd pass the roles as a parameter to the config function and let it decide how to configure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about creating a provider/wrapper for handling configurations for different roles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying that you shouldn't put the if here, but in the config files. Something like:

const roles = $window.$get().localStorage.getItem('posters_galore_roles')
admin.addEntity(nga.entity('customers'));
require('./customers/config')(nga, admin, roles);

And then, in the config files, decide what to add according to roles.

@fzaninotto
Copy link
Member

That's not a hack, that's the simple way to handle roles in ng-admin!

@akagadovskiy akagadovskiy changed the title Users roles hack ng-admin role-based system Sep 21, 2015
@drorm
Copy link

drorm commented Mar 12, 2016

Unless I'm missing something, this is certainly a hack.

The problem is that you don't know that the user is an admin or not until the app is running at which point ng-admin has already been set up in the controller. So you need to reload the app after log in, and saving the state which is ugly. Same on log out.

@saikiran-sankey-zz
Copy link

Can you plz help me to get the input box on my listview

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants