Delete Own Attachments permission check Edited

Hi all , I'm using jira 6.2.7 and i wanna check programatically if a user has the permission Delete Own Attachments or not , i tried that code but it check only global permissions as i understand :

boolean userHasPermission = ComponentAccessor.getPermissionManager().hasPermission(Permissions.ATTACHMENT_DELETE_OWN, loggedUser);

 

any help ? thanks 

1 answer

0 vote
Alexey Matveev Community Champion Nov 07, 2017

Hello,

Try this code (replace projectKey with the project key you need)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.permission.ProjectPermissions

def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("projectKey");
def tmpUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (ComponentAccessor.permissionManager.hasPermission(ProjectPermissions.DELETE_OWN_ATTACHMENTS , project, tmpUser)) {
log.error("user has permissions");
}

Thanks but this work only on jira 6.3 or above and i'm using jira 6.2.7

Alexey Matveev Community Champion Nov 07, 2017

Show your errors, we will figure it out

i can't use that function in jira 6.2.7 as it's written in the atlasian doc here :

https://docs.atlassian.com/jira/6.3/com/atlassian/jira/security/PermissionManager.html 

hasPermission(...) can't take ProjectPermissions.DELETE_OWN_ATTACHMENTS as first param  before the version 6.3 , and about my first code i got this error 

java.lang.IllegalArgumentException: Expected global permission because the function takes only global permissions

 

it works now just i used 


boolean userHasPermission = permissionManager.hasPermission(Permissions.ATTACHMENT_DELETE_OWN, currentIssue ,loggedUser);

Alexey Matveev Community Champion Nov 07, 2017

Nice to hear. Thankx :)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

758 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you