Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# msekhon 9/24/2008 12:58 AM
Hi all

How can I programmatically alter edit or view permissions on nodes for different roles?
Any pointers to existing threads would be appreciated.

Thanks
# msekhon 9/25/2008 1:24 AM
Hi all

Further to my post yesterday...I need to programmatically remove the view permission for Anonymous users at the click of a button for various sections in the code. Here is what the code looks like:

------
IList sections = this.Node.Sections;
Section section = (Section)sections[0];
IList sectionPermissions = section.SectionPermissions;
SectionPermission sp = (SectionPermission)sectionPermissions[0];
sp.ViewAllowed = false;
------

The code executes alright, but Anonymous users are still able to view the section.
What am I doing wrong?

Thanks.


# martijnb 9/25/2008 9:33 AM
Did you check if the correct permissions where removed after all?

Just fetching the first SectionPermission from the list isn't really a guarantee that you're dealing with anonymous users. You'd better iterate the list and check the role that is connected to SectionPermission.
# msekhon 9/25/2008 1:18 PM
Thanks for the reply martijnb ..

I've checked the permission for anonoymous users, and the permission to view is being removed. Maybe I need to explicitly write the changes to the db or update the cache?

Btw, what is the best way to get the permissions related to the anonymous users? In this case it is the first SectionPermission, but as you suggest, this may not be the case all the time.

Thanks

# msekhon 9/29/2008 2:04 AM (edited 9/29/2008 2:12 AM)
I have been able to programmatically set permissions on sections, but not on nodes.
For sections it was just a matter of calling base.CoreRepository.FlushSession(); to write changes to the db.

However, the same does not apply to nodes..

------
foreach (NodePermission np in this.Node.NodePermissions)
{
if (np.Role.Name.Equals("Anonymous user" ) )
{
np.ViewAllowed = false;
}
}
base.CoreRepository.FlushSession()
------

The above code does not alter the current node's permissions. Anonymous users can still view the node. Any clues?