Snippets

Adaptavist Bitbucket - Allow Only From Directory

You are viewing an old version of this snippet. View the current version.
Revised by Jamie Echlin 60ed3ee
package com.onresolve.stash.groovy.test.listeners.STASH_3850_block_personal

import com.atlassian.stash.event.RepositoryCreationRequestedEvent
import com.atlassian.stash.project.ProjectType

def event = event as RepositoryCreationRequestedEvent
def project = event.repository.project

// only allow when user comes from dir X
if (project.type == ProjectType.PERSONAL) {
    // this is unsafe... if you want this let me know and I'll use the long-winded but correct method
    if (event.user?.backingCrowdUser?.directory?.name != "Stash Internal Directory") { // enter directory name
        event.cancel("You don't have permissions to create a personal repository.")
    }
}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.