cancel
Showing results for 
Search instead for 
Did you mean: 

Folder permission:how to run custom action as 'another user'

redbull
Champ in-the-making
Champ in-the-making
Hi all, I'll try to explain my problem.
In Alfresco I have two user group each of one have permission to different spaces:
GROUP1 (USER1, USER2, USER3), (SpaceA, SpaceB)
GROUP2 (USER4, USER5) (SpaceC, SpaceE)

I write a custom action applied to GROUP1 spaces that, at the end, should move the content to GROUP2 specific space (SpaceC):

nodeService.moveNode(actionedUponNodeRef, targetNodeRef,
                 ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CHILDREN);

But GROUP1 users don't have "folder permissions" on GROUP2 spaces to execute moveNode method.
Do you have any suggestions on how to handle this? (something like "runas" admin user…)
Thanks!
2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
Go look at:
http://code.google.com/p/alfresco-developer-guide/source/browse/tags/ch7_3.4_community/client-extens...

Which shows how to use AuthenticationUtil.runAs() to run some code as admin.

Jeff

redbull
Champ in-the-making
Champ in-the-making
Jeff, your suggest has been a great help!
Here is the code:

   protected void moveContent(final NodeRef contentRef, final NodeRef targetRef) {
      AuthenticationUtil.runAs(new RunAsWork<String>() {
         @SuppressWarnings("synthetic-access")
         public String doWork() throws Exception {
            // move content to target folder
            nodeService.moveNode(contentRef, targetRef,
                    ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CHILDREN);
            if (logger.isDebugEnabled()) logger.debug("Move set");
            return "";
         }
      },
      "admin");
   }

Thank you very much.