I've been working / struggling with Scriptrunner Script Fragments for Bitbucket Server. We have a use case to add restrictions on a set of Projects (regex). We want the users to be Project Admins, but limit the ability to change Permissions or Delete the project itself and repositories.
The Scriptrunner Hide system or plugin UI element seems to have all the Web Items and Panels I need to hide, but I'm having trouble sorting out how current user context to allow Global Admins to still see these options and Project context the Project level permissions.
Is there a simple way to add in the HasGlobalPermissionCondition into existing Web Items? I don't see a jiraHelper which Jira Scriptrunner implements to make things a little smoother.
com.atlassian.bitbucket.server.bitbucket-server-web-fragments:projects-settings-delete-button
com.atlassian.bitbucket.server.bitbucket-server-web-fragments:projects-settings-permissions-tab
package com.onresolve.bitbucket.groovy.test.docs.webitems
import com.atlassian.plugin.PluginParseException
import com.atlassian.plugin.web.Condition
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.project.Project
import groovy.util.logging.Log4j
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Log4j
class OnlySomeProjectsCondition implements Condition {
@Override
void init(Map<String, String> params) throws PluginParseException {
}
@Override
boolean shouldDisplay(Map<String, Object> context) {
def repository = context.repository as Repository
def projKey = repository.project.key.toString()
return !(projKey.matches("AAA-.*\\d{6}.*"))
}
}
I got this sorted out once I got some decent logging output...appears to work well!
package com.onresolve.bitbucket.groovy.test.docs.webitems
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.plugin.PluginParseException
import com.atlassian.plugin.web.Condition
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.bitbucket.project.Project
import groovy.util.logging.Log4j
@Log4j
class OnlySomeProjectsCondition implements Condition {
@Override
void init(Map<String, String> params) throws PluginParseException {
}
@Override
boolean shouldDisplay(Map<String, Object> context) {
def userService = ComponentLocator.getComponent(UserService.class)
def user = context.currentUser as ApplicationUser
def project = context.project as Project
def truthy = false
// if this is NOT a special project let display
if (!project.key.matches("AAA-.*\\d{6}.*")) {
truthy = true
}
// if this IS a special project check for additional permissions
else if ( userService.isUserInGroup(user.username, "bitbucket-admin") ) {
truthy = true
}
return truthy
}
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.