The Unified and Autonomous Development Platform
Able to enable/disable branch and tag protection setting
Robin Shenca3ceab18708
diff --git a/core/src/main/java/com/gitplex/server/migration/DatabaseMigrator.java b/core/src/main/java/com/gitplex/server/migration/DatabaseMigrator.javaindex 4c569f43cd..47e1cfa4fb 100644--- a/core/src/main/java/com/gitplex/server/migration/DatabaseMigrator.java+++ b/core/src/main/java/com/gitplex/server/migration/DatabaseMigrator.java@@ -405,4 +405,21 @@ public class DatabaseMigrator {}}+ private void migrate12(File dataDir, Stack<Integer> versions) {+ for (File file: dataDir.listFiles()) {+ if (file.getName().startsWith("Projects.xml")) {+ VersionedDocument dom = VersionedDocument.fromFile(file);+ for (Element projectElement: dom.getRootElement().elements()) {+ for (Element branchProtectionElement: projectElement.element("branchProtections").elements()) {+ branchProtectionElement.addElement("enabled").setText("true");+ }+ for (Element tagProtectionElement: projectElement.element("tagProtections").elements()) {+ tagProtectionElement.addElement("enabled").setText("true");+ }+ }+ dom.writeToFile(file, false);+ }+ }+ }+}diff --git a/core/src/main/java/com/gitplex/server/model/Project.java b/core/src/main/java/com/gitplex/server/model/Project.javaindex 19c91f59e8..a1a853791e 100644--- a/core/src/main/java/com/gitplex/server/model/Project.java+++ b/core/src/main/java/com/gitplex/server/model/Project.java@@ -835,7 +835,7 @@ public class Project extends AbstractEntity {@Nullablepublic TagProtection getTagProtection(String tagName) {for (TagProtection protection: tagProtections) {- if (PathUtils.matchChildAware(protection.getTag(), tagName))+ if (protection.isEnabled() && PathUtils.matchChildAware(protection.getTag(), tagName))return protection;}return null;@@ -844,7 +844,7 @@ public class Project extends AbstractEntity {@Nullablepublic BranchProtection getBranchProtection(String branchName) {for (BranchProtection protection: branchProtections) {- if (PathUtils.matchChildAware(protection.getBranch(), branchName))+ if (protection.isEnabled() && PathUtils.matchChildAware(protection.getBranch(), branchName))return protection;}return null;diff --git a/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java b/core/src/main/java/com/gitplex/server/model/support/BranchProtection.javaindex 08e2d05b4a..bb7c480b89 100644--- a/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java+++ b/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java@@ -26,6 +26,8 @@ public class BranchProtection implements Serializable {private static final long serialVersionUID = 1L;+ private boolean enabled = true;+private String branch;private boolean noForcedPush = true;@@ -42,6 +44,14 @@ public class BranchProtection implements Serializable {private List<FileProtection> fileProtections = new ArrayList<>();+ public boolean isEnabled() {+ return enabled;+ }++ public void setEnabled(boolean enabled) {+ this.enabled = enabled;+ }+@Editable(order=100, description="Specify branch to be protected. Wildcard may be used to "+ "specify multiple branches")@BranchPatterndiff --git a/core/src/main/java/com/gitplex/server/model/support/TagProtection.java b/core/src/main/java/com/gitplex/server/model/support/TagProtection.javaindex 960712c501..db273ace0d 100644--- a/core/src/main/java/com/gitplex/server/model/support/TagProtection.java+++ b/core/src/main/java/com/gitplex/server/model/support/TagProtection.java@@ -18,6 +18,8 @@ public class TagProtection implements Serializable {private static final long serialVersionUID = 1L;+ private boolean enabled = true;+private String tag;private boolean noUpdate = true;@@ -26,6 +28,14 @@ public class TagProtection implements Serializable {private TagCreator tagCreator = new ProjectWriters();+ public boolean isEnabled() {+ return enabled;+ }++ public void setEnabled(boolean enabled) {+ this.enabled = enabled;+ }+@Editable(order=100, description="Specify tag to be protected. Wildcard can be used to match multiple tags")@TagPattern@NotEmptydiff --git a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.htmlindex b9a1db1e0e..df02f8e0e5 100644--- a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html+++ b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html@@ -11,11 +11,6 @@<th> </th></thead><tbody>- <!-- Put no-elements row here as Firefox has some issues displaying top border- of no-elements if tbody is empty -->- <tr wicket:id="noElementsRow" class="no-elements">- <td wicket:id="noElementsColumn"><div>No Elements Defined</div></td>- </tr><tr wicket:id="elements"><td wicket:id="properties"><div wicket:id="propertyEditor"></div>@@ -29,7 +24,7 @@</tbody><tfoot><tr class="add-element">- <td wicket:id="newRow" class="add-element"><a wicket:id="addElement" title="Add new element"><span class="fa fa-plus-circle add"></span></a></td>+ <td wicket:id="newRow" class="add-element"><a wicket:id="addElement" title="Add new element" class="btn btn-default"><span class="fa fa-plus-circle add"></span> Add Item</a></td></tr></tfoot></table>diff --git a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.java b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.javaindex d4fd848bf9..d241f030f5 100644--- a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.java+++ b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.java@@ -158,22 +158,6 @@ public class ConcreteListPropertyEditor extends PropertyEditor<List<Serializabletable.setVisible(false);}- final WebMarkupContainer noElementsRow = new WebMarkupContainer("noElementsRow") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(rows.size() == 0);- }-- };- noElementsRow.setOutputMarkupPlaceholderTag(true);- table.add(noElementsRow);-- WebMarkupContainer noElementsColumn = new WebMarkupContainer("noElementsColumn");- noElementsColumn.add(AttributeModifier.append("colspan", propertyContexts.size() + 1));- noElementsRow.add(noElementsColumn);-WebMarkupContainer newRow = new WebMarkupContainer("newRow");newRow.add(AttributeModifier.append("colspan", propertyContexts.size() + 1));newRow.add(new AjaxButton("addElement") {@@ -199,9 +183,6 @@ public class ConcreteListPropertyEditor extends PropertyEditor<List<Serializabletarget.prependJavaScript(script);target.add(newRow);- if (rows.size() == 1)- target.add(noElementsRow);-send(ConcreteListPropertyEditor.this, Broadcast.BUBBLE, new EditorChanged(target));}@@ -229,8 +210,8 @@ public class ConcreteListPropertyEditor extends PropertyEditor<List<Serializable// Do not use code above as removing components outside of a container and add again// can cause the fenced feedback panel not functioning properly- int fromIndex = from.getItemIndex()-1;- int toIndex = to.getItemIndex()-1;+ int fromIndex = from.getItemIndex();+ int toIndex = to.getItemIndex();if (fromIndex < toIndex) {for (int i=0; i<toIndex-fromIndex; i++)rows.swap(fromIndex+i, fromIndex+i+1);diff --git a/web/src/main/java/com/gitplex/server/web/page/base/base.css b/web/src/main/java/com/gitplex/server/web/page/base/base.cssindex 1a02241fc6..f32d59654d 100644--- a/web/src/main/java/com/gitplex/server/web/page/base/base.css+++ b/web/src/main/java/com/gitplex/server/web/page/base/base.css@@ -148,20 +148,7 @@ form>.test-feedback {margin-bottom: 0;}.editable table.list>tfoot>tr.add-element>td {- padding: 4px 0;- vertical-align: middle;-}-.editable table.list>tfoot>tr.add-element>td>a {- display: block;- text-decoration: none;- padding: 4px 8px;-}--.editable table.list>tfoot>tr.add-element>td:hover {- background-color: #F2F2F2;-}-.editable table.list>tbody>tr.no-elements>td {- font-style: italic;+ padding: 12px 0;}.editable>.reflection>table {@@ -219,10 +206,10 @@ form>.test-feedback {.editor>table.list>tbody>tr>td.actions {text-align: right;}-.editor>table.list>tbody>tr>td.actions .fa, .editor>table.list>tfoot>tr>td.add-element .fa {+.editor>table.list>tbody>tr>td.actions .fa {vertical-align: center;- font-size: 20px;- color: #666;+ font-size: 16px;+ color: #444;}.editor>table.list>tbody>tr>td.actions .handle {cursor: move;diff --git a/web/src/main/java/com/gitplex/server/web/page/group/GroupPage.java b/web/src/main/java/com/gitplex/server/web/page/group/GroupPage.javaindex 6a86651de4..b27666f977 100644--- a/web/src/main/java/com/gitplex/server/web/page/group/GroupPage.java+++ b/web/src/main/java/com/gitplex/server/web/page/group/GroupPage.java@@ -47,7 +47,7 @@ public abstract class GroupPage extends LayoutPage {tabs.add(new GroupTab("Profile", "fa fa-fw fa-list-alt", GroupProfilePage.class));tabs.add(new GroupTab("Members", "fa fa-fw fa-user", GroupMembershipsPage.class));if (SecurityUtils.isAdministrator() && !getGroup().isAdministrator())- tabs.add(new GroupTab("Authorized Projects", "fa fa-fw fa-lock", GroupAuthorizationsPage.class));+ tabs.add(new GroupTab("Authorized Projects", "fa fa-fw fa-ext fa-repo", GroupAuthorizationsPage.class));add(new Tabbable("groupTabs", tabs));}diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/ProjectSettingPage.java b/web/src/main/java/com/gitplex/server/web/page/project/setting/ProjectSettingPage.javaindex 911eed415b..094e664179 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/ProjectSettingPage.java+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/ProjectSettingPage.java@@ -36,7 +36,7 @@ public abstract class ProjectSettingPage extends ProjectPage {List<PageTab> tabs = new ArrayList<>();tabs.add(new ProjectSettingTab("General Setting", "fa fa-fw fa-sliders", GeneralSettingPage.class));- tabs.add(new ProjectSettingTab("Authorizations", "fa fa-fw fa-lock", ProjectAuthorizationsPage.class));+ tabs.add(new ProjectSettingTab("Authorizations", "fa fa-fw fa-user", ProjectAuthorizationsPage.class));tabs.add(new ProjectSettingTab("Branch Protection", "fa fa-fw fa-lock", BranchProtectionPage.class));tabs.add(new ProjectSettingTab("Tag Protection", "fa fa-fw fa-lock", TagProtectionPage.class));tabs.add(new ProjectSettingTab("Commit Message Transform", "fa fa-fw fa-exchange", CommitMessageTransformPage.class));diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPage.html b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPage.htmlindex b2fdba35fa..d0ca3059a8 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPage.html+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPage.html@@ -18,6 +18,6 @@</div></wicket:fragment><wicket:fragment wicket:id="addNewLinkFrag">- <a wicket:id="link" class="add-new">Add Protection<i class="fa fa-plus-circle fa-lg"></i></a>+ <a wicket:id="link" class="add-new"><i class="fa fa-plus-circle fa-lg"></i> Add Protection</a></wicket:fragment></wicket:extend>diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.html b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.htmlindex 0e0dad270e..302dad7841 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.html+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.html@@ -4,6 +4,7 @@<span class="drag-handle" title="Drag to reorder protections"><i class="fa fa-arrows"></i></span><a wicket:id="edit" title="Edit this protection"><i class="fa fa-pencil"></i></a><a wicket:id="delete" title="Delete this protection"><i class="fa fa-trash"></i></a>+ <input wicket:id="enable" type="checkbox"></input> Enable</div><div class="panel-body"><div wicket:id="protection"></div>diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.java b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.javaindex 8e4c37413f..53c1a699bc 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.java+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/branchprotection/BranchProtectionPanel.java@@ -4,7 +4,11 @@ import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;+import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;import com.gitplex.server.model.support.BranchProtection;import com.gitplex.server.web.editable.BeanContext;@@ -68,7 +72,29 @@ abstract class BranchProtectionPanel extends Panel {});+ add(new AjaxCheckBox("enable", Model.of(protection.isEnabled())) {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ protection.setEnabled(!protection.isEnabled());+ onSave(target, protection);+ target.add(BranchProtectionPanel.this);+ }++ });+add(BeanContext.viewBean("protection", protection).setOutputMarkupId(true));++ add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ return !protection.isEnabled()? "disabled": "";+ }++ }));++ setOutputMarkupId(true);}protected abstract void onDelete(AjaxRequestTarget target);diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/project-setting.css b/web/src/main/java/com/gitplex/server/web/page/project/setting/project-setting.cssindex cbf32385e9..7514175d71 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/project-setting.css+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/project-setting.css@@ -36,6 +36,9 @@color: #444;margin-right: 8px;}+#project-setting .panel-list .panel-heading input {+ vertical-align: text-top;+}#project-setting .panel-list .add-new {display: block;padding: 16px;@@ -51,15 +54,16 @@background-color: #EBEBEB;border-color: #ADADAD;}-#project-setting .panel-list a.add-new .fa {- margin-left: 8px;-}#project-setting .panel-list .concrete.list td.path,#project-setting .panel-list .concrete.list td.reviewerNames,#project-setting .panel-list .concrete.list td.reviewAppointment {width: 45%;}+#project-setting .disabled .panel {+ color: #999;+}+#project-setting .commit-message-transform>label {float: left;margin-right: 4px;diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPage.html b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPage.htmlindex dff7cda6cf..7aab7069fb 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPage.html+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPage.html@@ -18,6 +18,6 @@</div></wicket:fragment><wicket:fragment wicket:id="addNewLinkFrag">- <a wicket:id="link" class="add-new">Add Protection<i class="fa fa-plus-circle fa-lg"></i></a>+ <a wicket:id="link" class="add-new"><i class="fa fa-plus-circle fa-lg"></i> Add Protection</a></wicket:fragment></wicket:extend>diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.html b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.htmlindex 24cbc940de..c5d11a12d3 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.html+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.html@@ -4,6 +4,7 @@<span class="drag-handle" title="Drag to reorder protections"><i class="fa fa-arrows"></i></span><a wicket:id="edit" title="Edit this protection"><i class="fa fa-pencil"></i></a><a wicket:id="delete" title="Delete this protection"><i class="fa fa-trash"></i></a>+ <input wicket:id="enable" type="checkbox"></input> Enable</div><div class="panel-body"><div wicket:id="protection"></div>diff --git a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.java b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.javaindex a0479630e7..a07781f6f8 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.java+++ b/web/src/main/java/com/gitplex/server/web/page/project/setting/tagprotection/TagProtectionPanel.java@@ -4,7 +4,11 @@ import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;+import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;import com.gitplex.server.model.support.TagProtection;import com.gitplex.server.web.editable.BeanContext;@@ -68,7 +72,29 @@ abstract class TagProtectionPanel extends Panel {});+ add(new AjaxCheckBox("enable", Model.of(protection.isEnabled())) {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ protection.setEnabled(!protection.isEnabled());+ onSave(target, protection);+ target.add(TagProtectionPanel.this);+ }++ });++ add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ return !protection.isEnabled()? "disabled": "";+ }++ }));+add(BeanContext.viewBean("protection", protection).setOutputMarkupId(true));++ setOutputMarkupId(true);}protected abstract void onDelete(AjaxRequestTarget target);diff --git a/web/src/main/java/com/gitplex/server/web/page/user/UserPage.java b/web/src/main/java/com/gitplex/server/web/page/user/UserPage.javaindex 899ac0afac..4793749e6f 100644--- a/web/src/main/java/com/gitplex/server/web/page/user/UserPage.java+++ b/web/src/main/java/com/gitplex/server/web/page/user/UserPage.java@@ -72,7 +72,7 @@ public abstract class UserPage extends LayoutPage {}tabs.add(new UserTab("Belonging Groups", "fa fa-fw fa-group", UserMembershipsPage.class));if (SecurityUtils.isAdministrator())- tabs.add(new UserTab("Authorized Projects", "fa fa-fw fa-lock", UserAuthorizationsPage.class));+ tabs.add(new UserTab("Authorized Projects", "fa fa-fw fa-ext fa-repo", UserAuthorizationsPage.class));if (SecurityUtils.canManage(getUser()))tabs.add(new UserTab("Tasks", "fa fa-fw fa-bell-o", TaskListPage.class));