You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.