Created
May 8, 2015 04:07
-
-
Save jfut/d386c338244e455bf2fe to your computer and use it in GitHub Desktop.
JIRA: Add group permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.ofbiz.core.entity.EntityUtil | |
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.permission.ProjectPermissionCategory | |
import com.atlassian.jira.scheme.SchemeEntity | |
def projectManager = ComponentAccessor.getProjectManager() | |
def permissionManager = ComponentAccessor.getPermissionManager() | |
def permissionSchemeManager = ComponentAccessor.getPermissionSchemeManager() | |
def targetProjectKey = "SERVER"; | |
def addGroupName = "www"; | |
def permissionCategories = [ | |
ProjectPermissionCategory.PROJECTS, | |
ProjectPermissionCategory.ISSUES, | |
ProjectPermissionCategory.VOTERS_AND_WATCHERS, | |
ProjectPermissionCategory.COMMENTS, | |
ProjectPermissionCategory.ATTACHMENTS, | |
ProjectPermissionCategory.TIME_TRACKING, | |
ProjectPermissionCategory.OTHER | |
] | |
def result = ""; | |
def project = projectManager.getProjectObjByKey(targetProjectKey) | |
result = "[Project $project.name($project.key) id is $project.id]<br />\n"; | |
def scheme = EntityUtil.getOnly( | |
permissionSchemeManager.getSchemes( | |
project.getGenericValue())); | |
for (permissionCategory in permissionCategories) { | |
def permissions = permissionManager.getProjectPermissions( | |
permissionCategory); | |
// パーミッションの空のカテゴリは設定不要のため、そのままにします。 | |
if (permissions.isEmpty() == false) { | |
for (permission in permissions) { | |
def entities = permissionSchemeManager.getEntities( | |
scheme, permission.getKey()); | |
// 目的のグループを既に含むかどうか確認します。 | |
def isContainOwnGroup = false; | |
for (entity in entities) { | |
def parameter = entity.getString("parameter"); | |
if (addGroupName.equals(parameter)) { | |
isContainOwnGroup = true; | |
} | |
} | |
// 目的のグループを既に含む場合 skip します。 | |
if (isContainOwnGroup == true) { | |
result += "- Skip: " + permission.getNameI18nKey() + "<br />\n"; | |
continue; | |
} | |
// 目的のグループを追加します。 | |
result += "- Add: " + permission.getNameI18nKey() + ": " + addGroupName + "<br />\n"; | |
SchemeEntity schemeEntity = new SchemeEntity( | |
"group", addGroupName, permission.getProjectPermissionKey()); | |
permissionSchemeManager.createSchemeEntity(scheme, schemeEntity); | |
} | |
} | |
} | |
return result; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment