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.UserKey
import com.atlassian.sal.api.user.UserManager
import com.atlassian.bitbucket.auth.AuthenticationContext
import com.atlassian.sal.api.component.ComponentLocator
def currentUser = ComponentLocator.getComponent(AuthenticationContext).currentUser
ComponentLocator.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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 at
PermissionModificationRequestedEvent , CancelableEvent and their implementations
Regards,
Yannis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.