Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do you get User Context in Bitbucket Server Scriptrunner Script Fragments

David Puchosic Community Leader Jun 18, 2018

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}.*"))
    }
}

 

1 answer

1 accepted

0 votes
Answer accepted
David Puchosic Community Leader Jul 18, 2018

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
    }
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

94 views 0 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you