Developer forum

Forum » Development » Permission API - How to

Permission API - How to

Jonas Mersholm
Reply

Hi. I'm having a hard time figuring out the permissions API.

Lets say i have created a new user, and would like to give this user backend permissions to an Area. So that, if he logs into Dynamicweb Backend, that is the only area that he will be presented with.

 

I tried the following:

           User.AreaPermission(Area, Dynamicweb.Modules.UserManagement.PagePermissionLevels.Backend);
            User.Save();

 

Though. It' does'nt change anything to the given users permissions. How does the API work`?

 

best regards.

Jonas


Replies

 
Jonas Mersholm
Reply

Bumping this!

 
Morten Bengtson
Reply
This post has been marked as an answer

+1

The permissions API is a bit difficult to work with. It would be great if Dynamicweb could provide a few code examples that show us how to correctly set and read permission settings (area, page, paragraph).

Jonas...

In your code example you are only getting the area permissions without changing anything. I'm not sure, but I think you need to go through Area instead. Something like this (not tested)...


var area = Dynamicweb.Content.Area.GetAreaById(123);

var permissions = area.UserManagementPermissions[PagePermissionLevels.Backend];

permissions[0] = PagePermissionAccess.Deny;

permissions[user.ID] = PagePermissionAccess.Allow;

area.Save();

... and allow backend access for this user...

user.AllowBackend = true;

user.Save();
Votes for this answer: 1
 
Jonas Mersholm
Reply

Hi Morten, Thank you. The permissions are now set as expected.

Ive ran into another problem though.

Last year, we were using this whole "permission" system, to restrict areas to certain users. Now, with the current stable version, If i grant a user backend and frontend rights to an area (as i did last year), and log-in with that users credientials, the "content" field ( Where the pages are usually listed) Is blank and writes

 

"Access denied" - Do you have any idea about what have been changed? And how to correct it?

 

Thanks in advance.

Jonas

 
Morten Bengtson
Reply

Do you have multiple sites? Maybe that user doesn't have access to the default website.

You can try to select another website from the selector above the content area or enable the website dropdown on the admin login screen (Management Center > System > Solution settings > Customer Access > Show at login > Websites).

 
Jonas Mersholm
Reply

Hi Morten,

We have alot of sites on the solution. The thing is, that not even the "Site selector" above the content area are visible, for the given users , even though they have "site" permissions to a given website instance.

 

It is ofcourse available for users tagged with "admin" or "administrator"

 

Best regards.

Jonas

 
Morten Bengtson
Reply

Hmmm... thats weird.

 

Try the following...

Log in as Administator and go to Modules. Right click on "Websites" and select "Permissions". Do you have any restrictions set up?

By default there is only the "All" virtual user group and all checkboxes are unchecked. If you deny access here, then you will see "Access Denied" when you are logged in as a user which is not marked as an Admin or Administrator user type.

 

Otherwise, it might be the same issue as mentioned in a previous forum post:

http://developer.dynamicweb.com/forum/development/navigation-says-access-denied.aspx

 

websites_permissions.png
 
Jonas Mersholm
Reply

Hey Morten!

Thank you, that did the trick. I suppose the user-group was deleted when we did the update.

 

As a final question, if you dont mind. Is it possible to "hide" all the websites from the "selector" that a given user does not have permissions to edit? So that his default, when he logs in, is his own "place" ?

 

Thanks a bunch!

 

Jonas

 
Morten Bengtson
Reply

Yes, I just tried this...

Change the module permissions for "Websites" and select the "categories" (websites) that a given group or user should be able to access.

In the attached screenshots you can see that I have denied access for "All" and then allowed access for the group "Brugere", but only to one of the two websites. I also had to mark the user group with "Allow backend login" in User Management.

Now you should only see the websites which this user / group has access to.

websites_permissions_all.png websites_permissions_group.png
 
Jonas Mersholm
Reply

Thank you Morten! Works as expected. :D

 
Morten Bengtson
Reply

Great. I'm glad I could help... and I learned a few things myself :)

I only wonder if the backend permissions you can set on each website is superfluous when you can control the access through the module permissions. Oh well, I guess you can never have too many checkboxes ;-)

 
Jonas Mersholm
Reply

Hi Morten. I Indeed wonder about the same thing.

Do you have any idea, on how to also set the "website" module permissions for a given user, programagically? :D

I currently have a group, which is totally restricted. Now i would like to add new users to the permissionlist, granting them access only to their "category". 

I guess its somewhere around  Dynamicweb.Admin.ModulePermissionEdit, but the documentation on the topic is, as you pointed out, missing completely. :)

 

Jonas

 
Jonas Mersholm
Reply

Atlast. Figured it out. Intellisense and pathience was the road.

 

                Dynamicweb.Modules.UserManagement.IDCollection idC = new Dynamicweb.Modules.UserManagement.IDCollection();
                idC.Add(A.ID);                
                
                User.Modules["Area"].Access = Dynamicweb.Modules.UserManagement.ModulePermissionAccess.Allow;
                User.Modules["Area"].Categories = idC;
                User.Save();

 

You must be logged in to post in the forum