Show custom messages in the hooks

To simplify I set up an event handler on the ProjectPermissionGrantRequestedEvent with the following code:

import com.atlassian.bitbucket.event.permission.ProjectPermissionGrantRequestedEvent (event as ProjectPermissionGrantRequestedEvent).cancel("SRBSUP-539 test")

Then I tried to grant some project permissions to a group. The JSON response from the backend was:

{noformat}
{"errors":[
{"context":null,
"message":"Permission grant canceled",
"exceptionName":"com.atlassian.bitbucket.permission.PermissionGrantCanceledException",
"details":["SRBSUP-539 test"]}
]}
{noformat}

which as you can see contains my cancellation message in the details section, but the error was rendered in the UI as follows (image.png)

So we are not able to give the customized message to the end users when the cancelled event is raised.

Steps to recreate .

Create a event handler using scriptrunner plugin ( note that we are not using any of the scritrunner libraries , just using the bitbucket java api

{noformat}
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.permission.PermissionService
import com.atlassian.bitbucket.event.permission.ProjectPermissionModificationRequestedEvent
import com.atlassian.bitbucket.event.permission.ProjectPermissionGrantRequestedEvent
import com.atlassian.bitbucket.event.permission.RepositoryPermissionGrantRequestedEvent
import com.atlassian.bitbucket.event.permission.RepositoryPermissionModificationRequestedEvent
import com.atlassian.bitbucket.permission.Permission

def userService = ComponentLocator.getComponent(UserService.class)
def devAdmins = “******"
def devUsers = ""
def devViewers = "
” //I can not see this group in dev, so just for demo purpose

if(event instanceof ProjectPermissionModificationRequestedEvent)
{
def event = event as ProjectPermissionModificationRequestedEvent
//log.warn(&quot2019-03-20sDebug1"+event.affectedGroup+" “+event.affectedUser)
log.warn(&quot2019-03-20sDebug4”+!userService.isUserInGroup(event.affectedUser,devAdmins))
log.warn(&quot2019-03-20sDebug4"+!userService.isUserInGroup(event.affectedUser,clientdevAdmins))
log.warn(&quot2019-03-20sDebug4"+event.newValue)
def newValue = event.newValue
log.warn(&quot2019-03-20sDebug4"+newValue)

if(newValue == Permission.PROJECT_ADMIN)
{
   log.warn("iaminside") 
   if(!(userService.isUserInGroup(event.affectedUser,devAdmins)) || (userService.isUserInGroup(event.affectedUser,clientdevAdmins))) //! part of devAdmins
	{    log.warn(""+devAdmins+""+clientdevAdmins)
    	event.cancel(" not part of uGLBStashAdminsDev. Raise request for the same")
	} 
}

if(event.newValue == Permission.PROJECT_WRITE) //! part of devAdmins and ! part of devUsers
{
    if((!(userService.isUserInGroup(event.affectedUser,devAdmins)) || (userService.isUserInGroup(event.affectedUser,clientdevAdmins))) && (!(userService.isUserInGroup(event.affectedUser,devUsers)) || (userService.isUserInGroup(event.affectedUser,clientdevUsers))))
    {
        event.cancel("not part of uGLBStashAdminsDev neither part of uGLBStashUsersDev. Raise request for the same")
    }
}

}
{noformat}

In the above script we are giving custom message , but when the hook comes into action , we get the generic message

permission modification cancelled

below is the chrome console output

user-activity-xhr-header.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:1 PUT https://stash-dev.barcapint.com:8443/projects/EV/repos/pullrequestdeletionevent/permissions/users?permission=REPO_WRITE&name=genuser5 400
XMLHttpRequest.send @ user-activity-xhr-header.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:1
send @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:181
ajax @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:174
x @ server.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:7
B @ server.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:9
setPermission @ permission-table.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:2
(anonymous) @ permission-table.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:15
dispatch @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:115
l.handle @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:111
user-activity-xhr-header.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:1 XHR failed loading: PUT "https://stash-dev.barcapint.com:8443/projects/EV/repos/pullrequestdeletionevent/permissions/users?permission=REPO_WRITE&name=genuser5".
XMLHttpRequest.send @ user-activity-xhr-header.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:1
send @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:181
ajax @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:174
x @ server.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:7
B @ server.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:9
setPermission @ permission-table.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:2
(anonymous) @ permission-table.js?_statichash=448df630bf2f8830e30d29b8079f0344-T%2F-1338121493%2Fd728021%2F1%2Fbf65e5fe3906bf463beaa3d8bb18b4af&locale=en-US:15
dispatch @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:115
l.handle @ jquery.js?_statichash=d6cfa8b5217dc6d43b30e4d92b515f97-CDN%2F-1338121493%2Fd728021%2F1%2F154057b82430b23e11bfb75940567a2c&locale=en-US:111

I created a feature request for this you can watch and follow here. I don’t believe there is a workaround at the moment.

https://jira.atlassian.com/browse/BSERV-11671