I'm trying to change the CanViewType on a page and add one or more groups to the ViewerGroups().
Adding the groups with the add-function works fine, but changing the CanViewType doesn't work for me.
This brings me to another thing that I find myself spending time on; write() or writeToStage() and then publish.
I think that writeToStage is only for pages (classes that extends page).
When a class extends DataObject then write() should be good enough... is this correct?
So for the CanViewType I have tried both write() on the page and writeToStage("Stage") and then publish("Stage", "Live") on the page.
Some times I have both a row in the Sitetree and the Sitetree_Live table. Sometimes I manage to get the "OnlyTheseUsers" into the CanViewType, but then its only for the Live table, which is good, but I have the feeling that the CMS uses the non-live table so I would like to keep those in sync.
This is of course used for viewing rights on my site. If a user has no access he/she will be redirected to login page. Is this the desired way to do this? I have also tried using allowed_actions and putting a boolean function to each action. But then I cant control behavior like redirect to login and redirect back on successful login.