1 package org.itracker.model; 2 3 /** 4 * Enumeration for permission types. 5 * 6 * @author johnny 7 */ 8 public enum PermissionType implements IntCodeEnum<PermissionType> { 9 10 /** 11 * User Admin Permission. 12 * Currently this is equivalent to super user, since the permission can't be granted, 13 * and is only available to an admin. 14 */ 15 USER_ADMIN(-1), 16 17 /** 18 * Product Admin Permission 19 */ 20 PRODUCT_ADMIN(1), 21 22 /** 23 * Issue Create Permission 24 */ 25 ISSUE_CREATE(2), 26 27 /** 28 * Issue Edit Permission. 29 * Users with this permission can edit any issue in the project. 30 */ 31 ISSUE_EDIT_ALL(3), 32 33 /** 34 * Issue Close Permission. 35 * Users with this permission can close issues in the project. 36 */ 37 ISSUE_CLOSE(4), 38 39 /** 40 * Issue Assign to Self Permission. 41 * Users with this permission can assign issues to themselves. 42 */ 43 ISSUE_ASSIGN_SELF(5), 44 45 /** 46 * Issue Assign to Others Permissions. 47 * Users with this permission can assign issues to anyone, 48 * given than those users have the ability to recieve the assignment. 49 */ 50 ISSUE_ASSIGN_OTHERS(6), 51 52 /** 53 * View All Issues Permission. Users can view all issues in the project. 54 */ 55 ISSUE_VIEW_ALL(7), 56 57 /** 58 * View Users Issues Permission. Users can view thier own issues. 59 * This includes ones they are the creator or owner of. 60 */ 61 ISSUE_VIEW_USERS(8), 62 63 /** 64 * Edit Users Issues Permission. 65 * Users with this permission can edit any issue they created or own. 66 * They are limited to editing the description, adding history entries, 67 * and adding attachments. 68 */ 69 ISSUE_EDIT_USERS(9), 70 71 /** 72 * Issue Unassign Self Permission. 73 * Users with this permission can unassign issues they own. 74 */ 75 ISSUE_UNASSIGN_SELF(10), 76 77 /** 78 * Issue Assignable. 79 * Users with this permission can be assigned any issue in the system. 80 * To determine if a user can be assigned an issue, 81 * it will be a combination of users with EDIT_ALL, 82 * users with EDIT_USERS if they are the creator, 83 * and users with this permission and EDIT_USERS. 84 */ 85 ISSUE_ASSIGNABLE(11), 86 87 /** 88 * Create for Others. 89 * Users with this permission are allowed to create issues on behalf of other users. 90 * The system will treat the issue as if the other user had created it. 91 * The actual creator will be logged in the audit log. 92 */ 93 ISSUE_CREATE_OTHERS(12), 94 95 /** 96 * Full edit permission. 97 * This defines what levelof editing a user has for an issue. 98 * Without this permission, users will 99 * be limited to editing only the description, attachments, custom fields, 100 * and history of an issue. 101 */ 102 ISSUE_EDIT_FULL(13); 103 104 /* The project value matches the enum order (except for USER_ADMIN which is at position 0) */ 105 private static final PermissionType[] PERMISSION_TYPES = values(); 106 107 /** 108 * The integer value of this enum member. 109 */ 110 private final int code; 111 112 /** 113 * Creates a new instance of this enum. 114 * 115 * @param code unique value representing this instance 116 */ 117 PermissionType(Integer code) { 118 this.code = code; 119 } 120 121 /** 122 * Returns the integer value representing this enum member. 123 * 124 * @return unique value representing this instance 125 */ 126 public Integer getCode() { 127 return code; 128 } 129 130 public static PermissionType valueOf(Integer type) { 131 return values()[0].fromCode(type); 132 } 133 134 @Deprecated 135 public static PermissionType[] valueOf(int[] type) { 136 if (null == type) { 137 return null; 138 } 139 final PermissionTypermissionType">PermissionType[] result = new PermissionType[type.length]; 140 int c = 0; 141 for (Integer i: type) { 142 result[c++] = valueOf(i); 143 } 144 return result; 145 } 146 147 148 /** 149 * Returns the enum instance matching the integer value. 150 * 151 * @param code unique value of the enum instance to return 152 * @return enum instance matching the int value 153 */ 154 public PermissionType fromCode(Integer code) { 155 if (code == 0 || code < -1 || code > 13) { 156 throw new IllegalArgumentException("Unknown PermissionType code " + code); 157 } 158 if (code == -1) { 159 return PERMISSION_TYPES[0]; 160 } 161 return PERMISSION_TYPES[code]; 162 } 163 164 public String name(Project project) { 165 if (null != project) { 166 if (project.isNew()) { 167 throw new IllegalStateException("New project can't be granted."); 168 } 169 return name() + "#" + project.getId(); 170 } 171 return name(); 172 } 173 174 }