Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.permissions; 16 : 17 : import static java.util.Objects.requireNonNull; 18 : 19 : import com.google.gerrit.entities.RefNames; 20 : import com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission; 21 : import com.google.gerrit.extensions.api.access.GerritPermission; 22 : 23 150 : public enum ProjectPermission implements CoreOrPluginProjectPermission { 24 : /** 25 : * Can access at least one reference or change within the repository. 26 : * 27 : * <p>Checking this permission instead of {@link #READ} may require filtering to hide specific 28 : * references or changes, which can be expensive. 29 : */ 30 150 : ACCESS("access at least one ref"), 31 : 32 : /** 33 : * Can read all references in the repository. 34 : * 35 : * <p>This is a stronger form of {@link #ACCESS} where no filtering is required. 36 : */ 37 150 : READ, 38 : 39 : /** 40 : * Can create at least one reference in the project. 41 : * 42 : * <p>This project level permission only validates the user may create some type of reference 43 : * within the project. The exact reference name must be checked at creation: 44 : * 45 : * <pre>permissionBackend 46 : * .user(user) 47 : * .project(proj) 48 : * .ref(ref) 49 : * .check(RefPermission.CREATE); 50 : * </pre> 51 : */ 52 150 : CREATE_REF, 53 : 54 : /** 55 : * Can create at least one tag reference in the project. 56 : * 57 : * <p>This project level permission only validates the user may create some tag reference within 58 : * the project. The exact reference name must be checked at creation: 59 : * 60 : * <pre>permissionBackend 61 : * .user(user) 62 : * .project(proj) 63 : * .ref(ref) 64 : * .check(RefPermission.CREATE); 65 : * </pre> 66 : */ 67 150 : CREATE_TAG_REF, 68 : 69 : /** 70 : * Can create at least one change in the project. 71 : * 72 : * <p>This project level permission only validates the user may create a change for some branch 73 : * within the project. The exact reference name must be checked at creation: 74 : * 75 : * <pre>permissionBackend 76 : * .user(user) 77 : * .project(proj) 78 : * .ref(ref) 79 : * .check(RefPermission.CREATE_CHANGE); 80 : * </pre> 81 : */ 82 150 : CREATE_CHANGE, 83 : 84 : /** Can run receive pack. */ 85 150 : RUN_RECEIVE_PACK("run receive-pack"), 86 : 87 : /** Can run upload pack. */ 88 150 : RUN_UPLOAD_PACK("run upload-pack"), 89 : 90 : /** Allow read access to refs/meta/config. */ 91 150 : READ_CONFIG("read " + RefNames.REFS_CONFIG), 92 : 93 : /** Allow write access to refs/meta/config. */ 94 150 : WRITE_CONFIG("write " + RefNames.REFS_CONFIG), 95 : 96 : /** Allow banning commits from Gerrit preventing pushes of these commits. */ 97 150 : BAN_COMMIT, 98 : 99 : /** Allow accessing the project's reflog. */ 100 150 : READ_REFLOG, 101 : 102 : /** Can push to at least one reference within the repository. */ 103 150 : PUSH_AT_LEAST_ONE_REF("push to at least one ref"); 104 : 105 : private final String description; 106 : 107 150 : ProjectPermission() { 108 150 : this.description = null; 109 150 : } 110 : 111 150 : ProjectPermission(String description) { 112 150 : this.description = requireNonNull(description); 113 150 : } 114 : 115 : @Override 116 : public String describeForException() { 117 15 : return description != null ? description : GerritPermission.describeEnumValue(this); 118 : } 119 : }