It's all about the answers!

Ask a question

How Do I Use the getPermittedActions Function?


Nate Decker (37814161) | asked Jul 17 '14, 8:48 a.m.
edited Jul 17 '14, 8:50 a.m.

I am creating a server-side follow-up action that modifies a work item after a user has hit save while making a specific change. My follow-up action modifies the description attribute (which is not the same attribute that the user touched). I want to handle the case where the user had permissions to modify the custom attribute that I care about, but they do not have permissions to modify the description field. In this case, if I don't catch that scenario, my follow-up action will fail and will prevent the user from being able to save the work item. I would prefer for my follow-up action to fail silently and allow the user to commit their save.

In researching this, I found a function that seems promising, the IServerProcess#getPermittedActions function. The description for the function reads:

boolean [] com.ibm.team.process.service.IServerProcess.getPermittedActions(String projectOperationId, String [] actions) throws TeamRepositoryException

Queries whether the current user has permissions to perform each of the given actions for the given project operation. Each entry in the returned array specifies whether the user has permissions for the corresponding action in the given array.

Parameters:
     projectOperationId the identifier of the project operation
     actions the collection of actions to consider

Returns:
     an array of booleans which specifies whether each of the given actions are permitted

Throws:
     TeamRepositoryException

Here is how I've tried to use it so far:

IProcessServerService pss = getService(IProcessServerService.class);
IServerProcess sp = pss.getServerProcess(operation.getProcessArea());
String [] actionList = {"modify/description", "description"};
boolean [] resultPermissions = sp.getPermittedActions("com.ibm.team.workitem.operation.workItemSave", actionList);

I'm not sure if I'm populating my "actionList" with the correct values. The values shown above were to try and catch either possibility. Evidently the function doesn't have issues if you pass it an action that doesn't exist. For the case above, I changed the permissions in my test project area so that I could not modify the description field, then I ran the follow-up action. The resultPermissions array contained "false, false" for both actions. I then changed the permissions to re-enable the ability to modify the description and triggered the follow-up action again. The result was still "false, false". This suggests to me that I have not picked either the correct actions or the correct projectOperationId.

Has anyone used this function before? Can you describe how to use it correctly?

One answer



permanent link
sam detweiler (12.5k6195201) | answered Jul 17 '14, 9:19 a.m.
I don't know how to use this, and will have to read the code that implements the getPermittedActions to figure it out.

you can see the defined operations and actions by looking at the plugin.xml for com.ibm.team.workitem.service in the sdk.

the start of the list is
    <operation
            id="com.ibm.team.workitem.operation.workItemSave"
            name="%SaveWorkItem.operation.name"
            categoryId="com.ibm.team.workitem.category"
            allowsPermissionSpecification="true"
            allowsBehaviorSpecification="true">
            <action id="modify" label="%ModifyWorkItem.action.name">
                <action
                      id="projectArea"
                      label="%ModifyWorkItemProjectArea.action.name">
                       <description>
                      %ModifyWorkItemProjectArea.action.description
                       </description>
                </action>

Looks like you are close, operation_id, followed by array of strings of action_ids
the action id for description is
                <action
                      id="description"
                      label="%ModifyWorkItemDescription.action.name">
                   <description>
                      %ModifyWorkItemDescription.action.description
                   </description>
                </action>

Comments
Nate Decker commented Jul 17 '14, 9:23 a.m.

I also found a page that lists all of the operations and their ids:

https://jazz.net/wiki/bin/view/Main/CustomPreconditionsTable#operations

It looks like "modify/description" should be valid and so should my "com.ibm.team.workitem.operation.workItemSave". So I'm not sure why it doesn't work.


sam detweiler commented Jul 17 '14, 9:34 a.m.

I don't think its "modify/..."   cause that is not one of the id= fields for the actions
only 'description'..

I think the 'modify' is obvious as this is a save operation. so that is the only action you could do.. you cannot delete the attribute


sam detweiler commented Jul 17 '14, 10:24 a.m.

the code for this runs thru all the roles for this user in this project area and then checks the actions.

r u sure that the user has permissions on one of the assigned role(s)

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.