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.extensions.api.access.GerritPermission; 20 : 21 150 : public enum RefPermission implements GerritPermission { 22 150 : READ, 23 150 : CREATE, 24 : 25 : /** 26 : * Before checking this permission, the caller needs to verify the branch is deletable and reject 27 : * early if the branch should never be deleted. For example, the refs/meta/config branch should 28 : * never be deleted because deleting this branch would destroy all Gerrit specific metadata about 29 : * the project, including its access rules. If a project is to be removed from Gerrit, its 30 : * repository should be removed first. 31 : */ 32 150 : DELETE, 33 150 : UPDATE, 34 150 : FORCE_UPDATE, 35 150 : SET_HEAD("set HEAD"), 36 : 37 150 : FORGE_AUTHOR, 38 150 : FORGE_COMMITTER, 39 150 : FORGE_SERVER, 40 150 : MERGE, 41 : /** 42 : * Before checking this permission, the caller should verify {@code USE_SIGNED_OFF_BY} is false. 43 : * If it's true, the request should be rejected directly without further check this permission. 44 : */ 45 150 : SKIP_VALIDATION, 46 : 47 : /** Create a change to code review a commit. */ 48 150 : CREATE_CHANGE, 49 : 50 : /** Create a tag. */ 51 150 : CREATE_TAG, 52 : 53 : /** Create a signed tag. */ 54 150 : CREATE_SIGNED_TAG, 55 : 56 : /** 57 : * Creates changes, then also immediately submits them during {@code push}. 58 : * 59 : * <p>This is similar to {@link #UPDATE} except it constructs changes first, then submits them 60 : * according to the submit strategy, which may include cherry-pick or rebase. By creating changes 61 : * for each commit, automatic server side rebase, and post-update review are enabled. 62 : */ 63 150 : UPDATE_BY_SUBMIT, 64 : 65 : /** 66 : * Can read all private changes on the ref. Typically granted to CI systems if they should run on 67 : * private changes. 68 : */ 69 150 : READ_PRIVATE_CHANGES, 70 : 71 : /** Read access to ref's config section in {@code project.config}. */ 72 150 : READ_CONFIG("read ref config"), 73 : 74 : /** Write access to ref's config section in {@code project.config}. */ 75 150 : WRITE_CONFIG("write ref config"); 76 : 77 : private final String description; 78 : 79 150 : RefPermission() { 80 150 : this.description = null; 81 150 : } 82 : 83 150 : RefPermission(String description) { 84 150 : this.description = requireNonNull(description); 85 150 : } 86 : 87 : @Override 88 : public String describeForException() { 89 25 : return description != null ? description : GerritPermission.describeEnumValue(this); 90 : } 91 : }