Hello,
I would like to hide the Project and Repository Permissions page from all users except System Admins. I have been able to find the UI element to hide, but I am not sure how to disable it except for a System Admin. Any suggestions?
I was trying:
Hi @Mike P
The following snippet will return `true` when the logged in user is a global admins and `false` if they are a project or repo admin:
import com.atlassian.sal.api.user.UserKeyimport com.atlassian.sal.api.user.UserManagerimport com.atlassian.bitbucket.auth.AuthenticationContextimport com.atlassian.sal.api.component.ComponentLocatordef currentUser = ComponentLocator.getComponent(AuthenticationContext).currentUserComponentLocator.getComponent(UserManager).isAdmin(new UserKey(currentUser.name))
However, If you just need to prevent project or repo admins from changing permissions, instead of hidding UI elements, you could just reject any permission modification events for non-admin users.
You could use this library script : https://library.adaptavist.com/entity/block-changing-proj-key-from-non-admins
and modify its trigger, using ProjectPermissionModificationRequestedEvent and RepositoryPermissionModificationRequestedEvent instead of ProjectModificationRequestedEvent
Thank you so much Yannis. I will give the code a try.
As for your suggestion, it would be much better if I could gray out all the fields on the page except for system admins/admins. Is there a way to gray out the fields?
Also, how does one know what listener to use? Is there documentation anywhere for them?
thanks!
@Mike P I cannot think of an easy way to gray out fields.
I suggest to do it with event listeners, because this way you can have a clear error message and not confuse users by having an inconsistent UI. Also, this will cover you from users using rest API to change permissions.
For documentation, you could have a look atPermissionModificationRequestedEvent , CancelableEvent and their implementations
Regards,Yannis
It looks like you're new here. Sign in or register to get started.