SHOW:
|
|
- or go back to the newest paste.
1 | /***********************/ | |
2 | - | /* GROOVY - Varios */ |
2 | + | /* GROOVY - Users */ |
3 | /***********************/ | |
4 | ||
5 | - | // Lanzar excepción (validador) |
5 | + | // Obtener el usuario logado |
6 | - | // Obtener el action que se está ejecutando en una PF |
6 | + | // Obtener un usuario por username |
7 | - | // Mostrar popup flag |
7 | + | // Ejecutar una acción como usuario administrador |
8 | // Consultar si un usuario pertenece a un determinado rol | |
9 | // Obtener / Setear las propiedades de usuario nativas de Jira | |
10 | ||
11 | - | // Lanzar excepción (validador) |
11 | + | |
12 | - | throw new InvalidInputException("customfield_20109", "Default value must be modified") |
12 | + | |
13 | // Obtener el usuario logado | |
14 | def userLogged = ComponentAccessor.jiraAuthenticationContext.loggedInUser | |
15 | - | // Obtener el action que se está ejecutando en una PF |
15 | + | |
16 | - | def actionID = transientVars["actionId"] |
16 | + | |
17 | - | JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue) |
17 | + | // Obtener un usuario por username |
18 | - | def wfd = workflow.getDescriptor() |
18 | + | def userAdmin = ComponentAccessor.getUserManager().getUserByName("admin") |
19 | - | def actionName = wfd.getAction(transientVars["actionId"]).getName() |
19 | + | |
20 | ||
21 | // Ejecutar una acción como usuario administrador | |
22 | - | // Mostrar popup flag |
22 | + | def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext |
23 | - | import com.onresolve.scriptrunner.runner.util.UserMessageUtil |
23 | + | def adminUser = ComponentAccessor.getUserManager().getUserByName("admin") |
24 | - | UserMessageUtil.success('Good job! ') |
24 | + | def originalUser = jiraAuthenticationContext.loggedInUser |
25 | - | UserMessageUtil.info("Something interesting") |
25 | + | ..... |
26 | - | UserMessageUtil.warning("Danger") |
26 | + | jiraAuthenticationContext.setLoggedInUser(adminUser) |
27 | - | UserMessageUtil.error("Error") |
27 | + | issue.setCustomFieldValue(previousStatusCF, issue.getStatus().getName()) |
28 | ComponentAccessor.getIssueManager().updateIssue(adminUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false) | |
29 | - | //// Opcion 2 |
29 | + | jiraAuthenticationContext.setLoggedInUser(originalUser) |
30 | - | import com.onresolve.scriptrunner.runner.util.UserMessageUtil |
30 | + | |
31 | - | def flag = [ |
31 | + | |
32 | - | type: "warning", // Other possible options are "info", "success", "error" |
32 | + | // Consultar si un usuario pertenece a un determinado rol |
33 | - | body: "Please Request for retrofit codes if not already done.", |
33 | + | def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager) |
34 | - | close: "manual", // Other option is "auto" |
34 | + | def roleAdministrators = projectRoleManager.getProjectRole("Administrators") |
35 | - | ] |
35 | + | if (projectRoleManager.isUserInProjectRole(userLogged, roleAdministrators, issue.getProjectObject())) { ..... } |
36 | - | UserMessageUtil.flag(flag) |
36 | + | |
37 | ||
38 | // Obtener / Setear las propiedades de usuario nativas de Jira | |
39 | final userPropertyKey = "jira.meta.favoritePlugin" | |
40 | final userPropertyValue = "ScriptRunner" | |
41 | def user = ComponentAccessor.userManager.getUserByName("username") | |
42 | ..... | |
43 | ComponentAccessor.userPropertyManager.getPropertySet(user).setString(userPropertyKey, userPropertyValue) | |
44 | ComponentAccessor.userPropertyManager.getPropertySet(user).getString(userPropertyKey) | |
45 | /************************************/ | |
46 |