Modify parent-inherited ACL on creating a page

Vote:
 

Hello,

I am using CMS R2 SP2 to create a page programmatically, but I want the created page to NOT automatically receive all inherited rights and groups from the parent page.

In effect - I have a parent page with groups Administrators, Editors, CompanyGroup and CoachGroup - and I want the page created to just include the Administrators, Editors and CompanyGroup.

I have tried to set 

PageData newPage = EPiServer.DataFactory.Instance.GetDefaultPageData(parentPageLink, pageTypeId);
newPage.PageName = "New Page";
...
DataFactory.Instance.Save(newPage, SaveAction.Publish); 

I have tried within the "..." section to do this:
newPage.ACL.Remove("CoachGroup");
newPage.ACL.Save();

and I have tried to make a clone of the ACL like this:
AccessControlList myAcl = new AccessControlList(newPage.ACL.CreateWritableClone());
myAcl.Remove("CoachGroup");
myAcl.Save();

The former code block happily saves the ACL and it's gone while I debug, but on the next round or in edit mode the group that I don't want on this particular page is there again.
The latter code block throws an exception on myAcl.Save() that method is not supported.

I have tried some other approaches as well, such as grabbing a writeable clone of the page after the creation, and setting newPage.ACL.IsInherited = false, but the ACL won't budge.

Anyone have any ideas to share with me?

Thanks in advance,
/Marten

#33505
Oct 14, 2009 17:11
Vote:
 

Hi!

Attach to the event CreatedPage, that should be raised after the page is created. If you update the ACL for the page there I can't see a reason why it would be overwritten.

Or perhaps this is one of the things that you've already tried that didn't work?

Regards

Per Gunsarfs
EPiServer CMS development team

#33656
Oct 16, 2009 15:03
Vote:
 

Try to move:

newPage.ACL.Remove("CoachGroup");
newPage.ACL.Save();

to _after_ the call to DataFactory.Save()

/johan

#33657
Oct 16, 2009 15:11
Vote:
 

Thanks for your suggestions, but...

@Per: It still does not do anything. The group that I removed is present on the page when I check its rights in edit mode.

@Johan: This throws an exception - Object reference not set to an object - on newPage.ACL.Save() . Same thing when I do newPage.ACL.CreateWriteableClone().Save();

Regards,
/Marten

#33658
Oct 16, 2009 15:26
Vote:
 

OK, never mind.

Seems it works if I call DataFactory.Instance.GetPage on the newly created page and set the ACL from there. A bit strange that I can't set it directly on newPage, but at least it works now.

Thanks for the feedback.
/Marten

#33721
Oct 19, 2009 10:28
Vote:
 

Look at the page in edit/admin mode for handling Access Control List.

Notice that you select lines that you want to add, edit or delete. So you have to Add what you want to delete to the ACL list.

PageAccessControlList acl = new PageAccessControlList(page.PageLink);
acl.Add(new AccessControlEntry("CoachGroup", AccessLevel.NoAccess, SecurityEntityType.Role));
acl.Save();

 

Notice that you must save the page and retreive it from the DataFactore to get a valid PageLink.
#33763
Edited, Oct 19, 2009 22:36
Vote:
 

Thanks Fredrik, that cleared a few things up.

#33879
Oct 21, 2009 16:07
Vote:
 

thanks, Fredrick.  I have been banging my head against a wall with this one all evening!

#37742
Mar 18, 2010 0:28
Vote:
 

You are welcome! Glad to help!

#37841
Mar 22, 2010 15:47
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.