Skip to content

The Unified and Autonomous Development Platform

Rename some properties of branch/tag protection to avoid confusion

Robin Shen67911e3432ff
diff --git a/server-core/src/main/java/io/onedev/server/git/GitPreReceiveCallback.java b/server-core/src/main/java/io/onedev/server/git/GitPreReceiveCallback.java
index 5b780a2778..29118df8d0 100644
--- a/server-core/src/main/java/io/onedev/server/git/GitPreReceiveCallback.java
+++ b/server-core/src/main/java/io/onedev/server/git/GitPreReceiveCallback.java
@@ -140,12 +140,12 @@ public class GitPreReceiveCallback extends HttpServlet {
List<String> errorMessages = new ArrayList<>();
BranchProtection protection = project.getBranchProtection(branchName, user);
if (oldObjectId.equals(ObjectId.zeroId())) {
- if (protection.isNoCreation())
+ if (protection.isPreventCreation())
errorMessages.add("Can not create this branch according to branch protection setting");
} else if (newObjectId.equals(ObjectId.zeroId())) {
- if (protection.isNoDeletion())
+ if (protection.isPreventDeletion())
errorMessages.add("Can not delete this branch according to branch protection setting");
- } else if (protection.isNoForcedPush()
+ } else if (protection.isPreventForcedPush()
&& !GitUtils.isMergedInto(project.getRepository(), gitEnvs, oldObjectId, newObjectId)) {
errorMessages.add("Can not force-push to this branch according to branch protection setting");
} else if (protection.isReviewRequiredForPush(user, project, branchName, oldObjectId, newObjectId, gitEnvs)) {
@@ -171,12 +171,12 @@ public class GitPreReceiveCallback extends HttpServlet {
List<String> errorMessages = new ArrayList<>();
TagProtection protection = project.getTagProtection(tagName, user);
if (oldObjectId.equals(ObjectId.zeroId())) {
- if (protection.isNoCreation())
+ if (protection.isPreventCreation())
errorMessages.add("Can not create this tag according to tag protection setting");
} else if (newObjectId.equals(ObjectId.zeroId())) {
- if (protection.isNoDeletion())
+ if (protection.isPreventDeletion())
errorMessages.add("Can not delete this tag according to tag protection setting");
- } else if (protection.isNoUpdate()) {
+ } else if (protection.isPreventUpdate()) {
errorMessages.add("Can not update this tag according to tag protection setting");
}
if (errorMessages.isEmpty() && newObjectId.equals(ObjectId.zeroId())) {
diff --git a/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java b/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
index 16d3c910ad..d79e81c4dc 100644
--- a/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
+++ b/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
@@ -1377,4 +1377,26 @@ public class DataMigrator {
}
}
}
+
+ private void migrate33(File dataDir, Stack<Integer> versions) {
+ for (File file: dataDir.listFiles()) {
+ if (file.getName().startsWith("Projects.xml")) {
+ VersionedDocument dom = VersionedDocument.fromFile(file);
+ for (Element element: dom.getRootElement().elements()) {
+ for (Element branchProtectionElement: element.element("branchProtections").elements()) {
+ branchProtectionElement.element("noCreation").setName("preventCreation");
+ branchProtectionElement.element("noDeletion").setName("preventDeletion");
+ branchProtectionElement.element("noForcedPush").setName("preventForcedPush");
+ }
+ for (Element tagProtectionElement: element.element("tagProtections").elements()) {
+ tagProtectionElement.element("noCreation").setName("preventCreation");
+ tagProtectionElement.element("noDeletion").setName("preventDeletion");
+ tagProtectionElement.element("noUpdate").setName("preventUpdate");
+ }
+ }
+ dom.writeToFile(file, false);
+ }
+ }
+ }
+
}
diff --git a/server-core/src/main/java/io/onedev/server/model/Project.java b/server-core/src/main/java/io/onedev/server/model/Project.java
index 5ca8f0c4cf..ec8a29ad2a 100644
--- a/server-core/src/main/java/io/onedev/server/model/Project.java
+++ b/server-core/src/main/java/io/onedev/server/model/Project.java
@@ -1143,16 +1143,16 @@ public class Project extends AbstractEntity {
if (protection.isEnabled()
&& UserMatch.fromString(protection.getUserMatch()).matches(this, user)
&& PatternSet.parse(protection.getTags()).matches(new PathMatcher(), tagName)) {
- noCreation = noCreation || protection.isNoCreation();
- noDeletion = noDeletion || protection.isNoDeletion();
- noUpdate = noUpdate || protection.isNoUpdate();
+ noCreation = noCreation || protection.isPreventCreation();
+ noDeletion = noDeletion || protection.isPreventDeletion();
+ noUpdate = noUpdate || protection.isPreventUpdate();
}
}
TagProtection protection = new TagProtection();
- protection.setNoCreation(noCreation);
- protection.setNoDeletion(noDeletion);
- protection.setNoUpdate(noUpdate);
+ protection.setPreventCreation(noCreation);
+ protection.setPreventDeletion(noDeletion);
+ protection.setPreventUpdate(noUpdate);
return protection;
}
@@ -1168,9 +1168,9 @@ public class Project extends AbstractEntity {
if (protection.isEnabled()
&& UserMatch.fromString(protection.getUserMatch()).matches(this, user)
&& PatternSet.parse(protection.getBranches()).matches(new PathMatcher(), branchName)) {
- noCreation = noCreation || protection.isNoCreation();
- noDeletion = noDeletion || protection.isNoDeletion();
- noForcedPush = noForcedPush || protection.isNoForcedPush();
+ noCreation = noCreation || protection.isPreventCreation();
+ noDeletion = noDeletion || protection.isPreventDeletion();
+ noForcedPush = noForcedPush || protection.isPreventForcedPush();
jobNames.addAll(protection.getJobNames());
fileProtections.addAll(protection.getFileProtections());
reviewRequirement.mergeWith(protection.getParsedReviewRequirement());
@@ -1180,9 +1180,9 @@ public class Project extends AbstractEntity {
BranchProtection protection = new BranchProtection();
protection.setFileProtections(fileProtections);
protection.setJobNames(new ArrayList<>(jobNames));
- protection.setNoCreation(noCreation);
- protection.setNoDeletion(noDeletion);
- protection.setNoForcedPush(noForcedPush);
+ protection.setPreventCreation(noCreation);
+ protection.setPreventDeletion(noDeletion);
+ protection.setPreventForcedPush(noForcedPush);
protection.setParsedReviewRequirement(reviewRequirement);
return protection;
diff --git a/server-core/src/main/java/io/onedev/server/model/support/BranchProtection.java b/server-core/src/main/java/io/onedev/server/model/support/BranchProtection.java
index e8a53943d5..04c634a5a1 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/BranchProtection.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/BranchProtection.java
@@ -48,11 +48,11 @@ public class BranchProtection implements Serializable {
private String userMatch = new Anyone().toString();
- private boolean noForcedPush = true;
+ private boolean preventForcedPush = true;
- private boolean noDeletion = true;
+ private boolean preventDeletion = true;
- private boolean noCreation = true;
+ private boolean preventCreation = true;
private String reviewRequirement;
@@ -97,31 +97,31 @@ public class BranchProtection implements Serializable {
this.userMatch = userMatch;
}
- @Editable(order=200, description="Check this to not allow forced push")
- public boolean isNoForcedPush() {
- return noForcedPush;
+ @Editable(order=200, description="Check this to prevent forced push")
+ public boolean isPreventForcedPush() {
+ return preventForcedPush;
}
- public void setNoForcedPush(boolean noForcedPush) {
- this.noForcedPush = noForcedPush;
+ public void setPreventForcedPush(boolean preventForcedPush) {
+ this.preventForcedPush = preventForcedPush;
}
- @Editable(order=300, description="Check this to not allow branch deletion")
- public boolean isNoDeletion() {
- return noDeletion;
+ @Editable(order=300, description="Check this to prevent branch deletion")
+ public boolean isPreventDeletion() {
+ return preventDeletion;
}
- public void setNoDeletion(boolean noDeletion) {
- this.noDeletion = noDeletion;
+ public void setPreventDeletion(boolean preventDeletion) {
+ this.preventDeletion = preventDeletion;
}
- @Editable(order=350, description="Check this to not allow branch creation")
- public boolean isNoCreation() {
- return noCreation;
+ @Editable(order=350, description="Check this to prevent branch creation")
+ public boolean isPreventCreation() {
+ return preventCreation;
}
- public void setNoCreation(boolean noCreation) {
- this.noCreation = noCreation;
+ public void setPreventCreation(boolean preventCreation) {
+ this.preventCreation = preventCreation;
}
@Editable(order=400, name="Required Reviewers", description="Optionally specify required reviewers for changes of "
diff --git a/server-core/src/main/java/io/onedev/server/model/support/TagProtection.java b/server-core/src/main/java/io/onedev/server/model/support/TagProtection.java
index 2c2811669f..bfd311af80 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/TagProtection.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/TagProtection.java
@@ -28,11 +28,11 @@ public class TagProtection implements Serializable {
private String userMatch = new Anyone().toString();
- private boolean noUpdate = true;
+ private boolean preventUpdate = true;
- private boolean noDeletion = true;
+ private boolean preventDeletion = true;
- private boolean noCreation = true;
+ private boolean preventCreation = true;
public boolean isEnabled() {
return enabled;
@@ -69,31 +69,31 @@ public class TagProtection implements Serializable {
this.userMatch = userMatch;
}
- @Editable(order=200, description="Check this to not allow tag update")
- public boolean isNoUpdate() {
- return noUpdate;
+ @Editable(order=200, description="Check this to prevent tag update")
+ public boolean isPreventUpdate() {
+ return preventUpdate;
}
- public void setNoUpdate(boolean noUpdate) {
- this.noUpdate = noUpdate;
+ public void setPreventUpdate(boolean preventUpdate) {
+ this.preventUpdate = preventUpdate;
}
- @Editable(order=300, description="Check this to not allow tag deletion")
- public boolean isNoDeletion() {
- return noDeletion;
+ @Editable(order=300, description="Check this to prevent tag deletion")
+ public boolean isPreventDeletion() {
+ return preventDeletion;
}
- public void setNoDeletion(boolean noDeletion) {
- this.noDeletion = noDeletion;
+ public void setPreventDeletion(boolean preventDeletion) {
+ this.preventDeletion = preventDeletion;
}
- @Editable(order=400, description="Check this to not allow tag creation")
- public boolean isNoCreation() {
- return noCreation;
+ @Editable(order=400, description="Check this to prevent tag creation")
+ public boolean isPreventCreation() {
+ return preventCreation;
}
- public void setNoCreation(boolean noCreation) {
- this.noCreation = noCreation;
+ public void setPreventCreation(boolean preventCreation) {
+ this.preventCreation = preventCreation;
}
public void onRenameGroup(String oldName, String newName) {
diff --git a/server-core/src/main/java/io/onedev/server/util/SecurityUtils.java b/server-core/src/main/java/io/onedev/server/util/SecurityUtils.java
index 2d29e323ff..6f309e0e39 100644
--- a/server-core/src/main/java/io/onedev/server/util/SecurityUtils.java
+++ b/server-core/src/main/java/io/onedev/server/util/SecurityUtils.java
@@ -107,21 +107,21 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
public static boolean canDeleteBranch(Project project, String branchName) {
if (canWriteCode(project))
- return !project.getBranchProtection(branchName, getUser()).isNoDeletion();
+ return !project.getBranchProtection(branchName, getUser()).isPreventDeletion();
else
return false;
}
public static boolean canCreateTag(Project project, String tagName) {
if (canWriteCode(project))
- return !project.getTagProtection(tagName, getUser()).isNoCreation();
+ return !project.getTagProtection(tagName, getUser()).isPreventCreation();
else
return false;
}
public static boolean canCreateBranch(Project project, String branchName) {
if (canWriteCode(project))
- return !project.getBranchProtection(branchName, getUser()).isNoCreation();
+ return !project.getBranchProtection(branchName, getUser()).isPreventCreation();
else
return false;
}
diff --git a/server-core/src/main/java/io/onedev/server/web/component/branch/create/CreateBranchPanel.java b/server-core/src/main/java/io/onedev/server/web/component/branch/create/CreateBranchPanel.java
index 2874cf220f..b5b6d4454d 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/branch/create/CreateBranchPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/branch/create/CreateBranchPanel.java
@@ -85,7 +85,7 @@ abstract class CreateBranchPanel extends Panel {
User user = Preconditions.checkNotNull(SecurityUtils.getUser());
BranchProtection protection = project.getBranchProtection(branchName, user);
- if (protection.isNoCreation()) {
+ if (protection.isPreventCreation()) {
form.error("Unable to create protected branch");
target.focusComponent(nameInput);
target.add(form);
diff --git a/server-core/src/main/java/io/onedev/server/web/component/createtag/CreateTagPanel.java b/server-core/src/main/java/io/onedev/server/web/component/createtag/CreateTagPanel.java
index 532b3f3048..f50834176e 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/createtag/CreateTagPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/createtag/CreateTagPanel.java
@@ -114,7 +114,7 @@ public abstract class CreateTagPanel extends Panel {
User user = Preconditions.checkNotNull(SecurityUtils.getUser());
TagProtection protection = project.getTagProtection(tagName, user);
- if (protection.isNoCreation()) {
+ if (protection.isPreventCreation()) {
form.error("Unable to create protected tag");
target.focusComponent(nameInput);
target.add(form);
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/branches/ProjectBranchesPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/branches/ProjectBranchesPage.java
index 3b21fd6d74..2503c22cd9 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/branches/ProjectBranchesPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/branches/ProjectBranchesPage.java
@@ -437,7 +437,7 @@ public class ProjectBranchesPage extends ProjectPage {
} else {
Project project = getProject();
BranchProtection protection = project.getBranchProtection(branchName, getLoginUser());
- if (protection.isNoCreation()) {
+ if (protection.isPreventCreation()) {
form.error("Unable to create protected branch");
target.focusComponent(nameInput);
target.add(form);
@@ -735,7 +735,7 @@ public class ProjectBranchesPage extends ProjectPage {
if (project.getDefaultBranch().equals(branch))
setEnabled(false);
else
- setEnabled(!project.getBranchProtection(branch, getLoginUser()).isNoDeletion());
+ setEnabled(!project.getBranchProtection(branch, getLoginUser()).isPreventDeletion());
} else {
setVisible(false);
}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/tags/ProjectTagsPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/tags/ProjectTagsPage.java
index a8ac04d64b..9b29d86eba 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/tags/ProjectTagsPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/tags/ProjectTagsPage.java
@@ -242,7 +242,7 @@ public class ProjectTagsPage extends ProjectPage {
} else {
Project project = getProject();
TagProtection protection = project.getTagProtection(tagName, getLoginUser());
- if (protection.isNoCreation()) {
+ if (protection.isPreventCreation()) {
form.error("Unable to create protected tag");
target.focusComponent(nameInput);
target.add(form);
@@ -393,7 +393,7 @@ public class ProjectTagsPage extends ProjectPage {
Project project = getProject();
if (SecurityUtils.canWriteCode(project))
- setEnabled(!project.getTagProtection(tagName, getLoginUser()).isNoDeletion());
+ setEnabled(!project.getTagProtection(tagName, getLoginUser()).isPreventDeletion());
else
setVisible(false);
}