Skip to content

Permissions

Lee edited this page Sep 8, 2015 · 2 revisions

Permissions are role based, and you can create as many roles as you wish AND even create your own custom permissions which are automatically picked up by our system.

We have developed a really easy to use permission administration UI, which is allows you to manage roles per category OR globally for the entire site in a very simple manner.

Adding A Custom Permission Type

You can add new permission types very quickly and use it straight away, for example you may want to add a permission that hides the email subscribe/unsubscribe link for a specific role in a specific category.

This is very simple to do, firstly create your 'Permission Type' name by logging into the admin section and going to

Admin > Permissions > Click 'Add New Permission Type'

Add your permission type name 'Hide Subscribe Button' and DON'T check 'Is Global' then click save. The reason for this is we might only want to hide the subscribe button for certain categories. If we make it global, it will be for the entire site.

Key (AppConstants)

Create the following line within your own constants file or static helper file (We have an AppConstants file for these). The value of the string MUST be exactly the same as the DB value you entered. As we use this as the key to look up the permission

public const string PermissionHideSubscribeButton = "Hide Subscribe Button";

That's it. Once that's added just rebuild and you can use your permission just like any other permission. To set the permission to true/false per role/category, in the admin section go to

Admin > Permissions

And click on the role you want to set your permission for, now in the list of check boxes you'll see your new permission and you can check or un-check.

Next is to apply it in your code, and you can use it exactly like the built in permissions out the box. So to use this newly created permission, I would open up the show.cshtml view in the category folder (In the main views folder) and I can do the following

!Model.Permissions[AppConstants.PermissionHideSubscribeButton].IsTicked

I can wrap this around the subscribe link HTML, so if it's been ticked to hide the subscribe it won't show - If it's not ticked then it will show.

If you want to get permissions manually in your code, that's easy too. Just use the RoleService to grab the permissions for a category and a user's role.

var permissions = RoleService.GetPermissions(category, UsersRole);
permissions["YourCustomPermissionName"].IsTicked

Global permissions are returned with the call above, but if you just want to get global permissions you call the same method, but pass in null for the category.

var permissions = RoleService.GetPermissions(null, UsersRole);

Clone this wiki locally