The Unified and Autonomous Development Platform
History protection and gerrit enabling gate keepers.
robin shine9d2a976a5f15
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.javaindex 27f09bfb60..532ad107db 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BranchProtection.java@@ -1,125 +1,87 @@package com.pmease.gitop.core.gatekeeper;-import java.io.Serializable;import java.util.ArrayList;import java.util.List;-import javax.annotation.Nullable;import javax.validation.Valid;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.editable.annotation.OmitName;-import com.pmease.commons.util.trimmable.TrimUtils;-import com.pmease.commons.util.trimmable.Trimmable;import com.pmease.gitop.core.Gitop;-import com.pmease.gitop.core.editable.BranchChoice;import com.pmease.gitop.core.editable.TeamChoice;-import com.pmease.gitop.core.manager.BranchManager;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.TargetBranchSelection;import com.pmease.gitop.core.manager.TeamManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.Team;import com.pmease.gitop.model.User;-import com.pmease.gitop.model.gatekeeper.AndGateKeeper;import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;import com.pmease.gitop.model.gatekeeper.GateKeeper;import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;+import com.pmease.gitop.model.gatekeeper.OrGateKeeper;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@Editable(order=100, icon="icon-lock", description="By default, users with write permission of "+ "the project can push code to all branches. Use this gate keeper to restrict write "- + "access of certain branches to certain teams.")+ + "access of specified branches to specified teams.")public class BranchProtection extends CommonGateKeeper {- private List<Entry> entries = new ArrayList<Entry>();+ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();- public BranchProtection() {- Entry entry = new Entry();- entries.add(entry);- }+ private List<Long> teamIds = new ArrayList<>();- @Editable- @Size(min=1, message="At least one entry has to be specified.")+ @Editable(name="Specify Branches to Be Protected", order=100)@Valid@NotNull- @OmitName- public List<Entry> getEntries() {- return entries;+ public TargetBranchSelection getBranchSelection() {+ return branchSelection;}- public void setEntries(List<Entry> entries) {- this.entries = entries;+ public void setBranchSelection(TargetBranchSelection branchSelection) {+ this.branchSelection = branchSelection;}- @Editable- public static class Entry implements Trimmable, Serializable {-- private Long branchId;-- private Long teamId;-- @Editable(name="Branch To Protect", order=100)- @BranchChoice- @NotNull- public Long getBranchId() {- return branchId;- }-- public void setBranchId(Long branchId) {- this.branchId = branchId;- }-- @Editable(name="Team Can Write", order=200)- @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})- @NotNull- public Long getTeamId() {- return teamId;- }-- public void setTeamId(Long teamId) {- this.teamId = teamId;- }-- @Override- public Object trim(Object context) {- if (Gitop.getInstance(BranchManager.class).get(branchId) == null)- return null;- if (Gitop.getInstance(TeamManager.class).get(teamId) == null)- return null;- return this;- }+ @Editable(name="Restrict Write Access of Above Branches to Below Teams", order=200)+ @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})+ @Size(min=1)+ @NotNull+ public List<Long> getTeamIds() {+ return teamIds;+ }+ public void setTeamIds(List<Long> teamIds) {+ this.teamIds = teamIds;}@Overrideprotected GateKeeper trim(Project project) {- TrimUtils.trim(entries, project);-- if (entries.isEmpty())+ if (branchSelection.trim(project) == null)+ return null;++ Gitop.getInstance(TeamManager.class).trim(teamIds);+ if (teamIds.isEmpty())return null;elsereturn this;}private GateKeeper getGateKeeper() {- AndGateKeeper andGate = new AndGateKeeper();- for (Entry entry: entries) {- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();- IfSubmittedToSpecifiedBranches ifGate = new IfSubmittedToSpecifiedBranches();- ifGate.getBranchIds().add(entry.getBranchId());- ifThenGate.setIfGate(ifGate);-- IfApprovedBySpecifiedTeam thenGate = new IfApprovedBySpecifiedTeam();- thenGate.setTeamId(entry.getTeamId());- ifThenGate.setThenGate(thenGate);-- andGate.getGateKeepers().add(ifThenGate);+ IfThenGateKeeper ifThenGate = new IfThenGateKeeper();+ ifThenGate.setIfGate(branchSelection.getGateKeeper());++ OrGateKeeper orGateKeeper = new OrGateKeeper();+ for (Long teamId: teamIds) {+ IfApprovedBySpecifiedTeam ifApprovedBySpecifiedTeam = new IfApprovedBySpecifiedTeam();+ ifApprovedBySpecifiedTeam.setTeamId(teamId);+ orGateKeeper.getGateKeepers().add(ifApprovedBySpecifiedTeam);}- return andGate;+ ifThenGate.setThenGate(orGateKeeper);++ return ifThenGate;}@Override@@ -128,7 +90,7 @@ public class BranchProtection extends CommonGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {+ protected CheckResult doCheckFile(User user, Branch branch, String file) {return getGateKeeper().checkFile(user, branch, file);}@@ -137,4 +99,9 @@ public class BranchProtection extends CommonGateKeeper {return getGateKeeper().checkCommit(user, branch, commit);}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return getGateKeeper().checkRef(user, project, refName);+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BuildVerificationOfBranch.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BuildVerificationOfBranch.javanew file mode 100644index 0000000000..d3235c8d42--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/BuildVerificationOfBranch.java@@ -0,0 +1,116 @@+package com.pmease.gitop.core.gatekeeper;++import javax.validation.Valid;+import javax.validation.constraints.Min;+import javax.validation.constraints.NotNull;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.TargetBranchSelection;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;+import com.pmease.gitop.model.gatekeeper.GateKeeper;+import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@Editable(icon="icon-lock", order=300, description="This gate keeper can be used to configure certain branches "+ + "to only accept commits passing specified build criteria.")+@SuppressWarnings("serial")+public class BuildVerificationOfBranch extends CommonGateKeeper {++ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();++ private int buildCount = 1;++ private boolean checkMerged = true;++ private boolean blockMode = true;++ @Editable(name="Specify Branches to Be Protected", order=50)+ @Valid+ @NotNull+ public TargetBranchSelection getBranchSelection() {+ return branchSelection;+ }++ public void setBranchSelection(TargetBranchSelection branchSelection) {+ this.branchSelection = branchSelection;+ }++ @Override+ protected GateKeeper trim(Project project) {+ if (branchSelection.trim(project) == null)+ return null;+ else+ return this;+ }++ @Editable(order=100, description="For each specified branch, this specified number of builds has to be "+ + "reported successful for this gate keeper to be passed. Normally this number represents "+ + "number of build configurations setting up to verify the branch.")+ @Min(1)+ public int getBuildCount() {+ return buildCount;+ }++ public void setBuildCount(int buildCount) {+ this.buildCount = buildCount;+ }++ @Editable(order=200, description="Enable this to check the merged commit instead of head commit of the "+ + "pull request.")+ public boolean isCheckMerged() {+ return checkMerged;+ }++ public void setCheckMerged(boolean checkMerged) {+ this.checkMerged = checkMerged;+ }++ @Editable(order=300, description="If this is checked, subsequent gate keepers will not be checked "+ + "while waiting for the build results. This can be used to only notify relevant voters "+ + "when the commit passes build.")+ public boolean isBlockMode() {+ return blockMode;+ }++ public void setBlockMode(boolean blockMode) {+ this.blockMode = blockMode;+ }++ private GateKeeper getGateKeeper() {+ IfThenGateKeeper ifThenGate = new IfThenGateKeeper();+ ifThenGate.setIfGate(branchSelection.getGateKeeper());+ IfVerifiedByBuilds thenGate = new IfVerifiedByBuilds();+ thenGate.setBlockMode(blockMode);+ thenGate.setBuildCount(buildCount);+ thenGate.setCheckMerged(checkMerged);+ ifThenGate.setThenGate(thenGate);++ return ifThenGate;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return getGateKeeper().checkRequest(request);+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return getGateKeeper().checkFile(user, branch, file);+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return getGateKeeper().checkCommit(user, branch, commit);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return getGateKeeper().checkRef(user, project, refName);+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryAndFileProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryAndFileProtection.javanew file mode 100644index 0000000000..19b4297729--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryAndFileProtection.java@@ -0,0 +1,132 @@+package com.pmease.gitop.core.gatekeeper;++import java.util.ArrayList;+import java.util.List;++import javax.annotation.Nullable;+import javax.validation.Valid;+import javax.validation.constraints.NotNull;+import javax.validation.constraints.Size;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.core.editable.TeamChoice;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.TargetBranchSelection;+import com.pmease.gitop.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;+import com.pmease.gitop.core.gatekeeper.helper.pathselection.TargetPathSelection;+import com.pmease.gitop.core.manager.TeamManager;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.Team;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;+import com.pmease.gitop.model.gatekeeper.GateKeeper;+import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;+import com.pmease.gitop.model.gatekeeper.OrGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@SuppressWarnings("serial")+@Editable(order=200, icon="icon-lock", description="By default, users with write permission of "+ + "the project can write to all directories/files. Use this gate keeper to restrict write "+ + "access of certain directories/files of specified branches to certain teams. Note that if "+ + "branch is not specified, the restriction will apply to all branches.")+public class DirectoryAndFileProtection extends CommonGateKeeper {++ private TargetBranchSelection branchSelection;++ private TargetPathSelection pathSelection = new SpecifyTargetPathsByDirectories();++ private List<Long> teamIds = new ArrayList<>();++ @Editable(name="Optionally Specify Applicable Branches", order=100)+ @Valid+ @Nullable+ public TargetBranchSelection getBranchSelection() {+ return branchSelection;+ }++ public void setBranchSelection(TargetBranchSelection branchSelection) {+ this.branchSelection = branchSelection;+ }++ @Editable(name="Specify Directory or File to Protect")+ @Valid+ @NotNull+ public TargetPathSelection getPathSelection() {+ return pathSelection;+ }++ public void setPathSelection(TargetPathSelection pathSelection) {+ this.pathSelection = pathSelection;+ }++ @Editable(name="Restrict Write Access of Above Paths to Below Teams", order=200)+ @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})+ @Size(min=1)+ @NotNull+ public List<Long> getTeamIds() {+ return teamIds;+ }++ public void setTeamIds(List<Long> teamIds) {+ this.teamIds = teamIds;+ }++ @Override+ protected GateKeeper trim(Project project) {+ if (branchSelection.trim(project) == null)+ return null;++ Gitop.getInstance(TeamManager.class).trim(teamIds);+ if (teamIds.isEmpty())+ return null;+ else+ return this;+ }++ private GateKeeper getGateKeeper() {+ IfThenGateKeeper ifThenGate = new IfThenGateKeeper();+ ifThenGate.setIfGate(pathSelection.getGateKeeper());+ ifThenGate.setThenGate(getApprovalGate());++ if (branchSelection != null) {+ IfThenGateKeeper resultGate = new IfThenGateKeeper();+ resultGate.setIfGate(branchSelection.getGateKeeper());+ resultGate.setThenGate(ifThenGate);+ return resultGate;+ } else {+ return ifThenGate;+ }+ }++ private GateKeeper getApprovalGate() {+ OrGateKeeper approvalGate = new OrGateKeeper();+ for (Long teamId: teamIds) {+ IfApprovedBySpecifiedTeam ifApprovedBySpecifiedTeam = new IfApprovedBySpecifiedTeam();+ ifApprovedBySpecifiedTeam.setTeamId(teamId);+ approvalGate.getGateKeepers().add(ifApprovedBySpecifiedTeam);+ }+ return approvalGate;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return getGateKeeper().checkRequest(request);+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return getGateKeeper().checkFile(user, branch, file);+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return getGateKeeper().checkCommit(user, branch, commit);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return getGateKeeper().checkRef(user, project, refName);+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.javadeleted file mode 100644index 926285c03d..0000000000--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/DirectoryProtection.java+++ /dev/null@@ -1,174 +0,0 @@-package com.pmease.gitop.core.gatekeeper;--import java.io.Serializable;-import java.util.ArrayList;-import java.util.Iterator;-import java.util.List;--import javax.annotation.Nullable;-import javax.validation.Valid;-import javax.validation.constraints.NotNull;-import javax.validation.constraints.Size;--import org.hibernate.validator.constraints.NotEmpty;--import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.editable.annotation.OmitName;-import com.pmease.commons.util.trimmable.TrimUtils;-import com.pmease.commons.util.trimmable.Trimmable;-import com.pmease.gitop.core.Gitop;-import com.pmease.gitop.core.editable.BranchChoice;-import com.pmease.gitop.core.editable.DirectoryChoice;-import com.pmease.gitop.core.editable.TeamChoice;-import com.pmease.gitop.core.manager.BranchManager;-import com.pmease.gitop.core.manager.TeamManager;-import com.pmease.gitop.model.Branch;-import com.pmease.gitop.model.Project;-import com.pmease.gitop.model.PullRequest;-import com.pmease.gitop.model.Team;-import com.pmease.gitop.model.User;-import com.pmease.gitop.model.gatekeeper.AndGateKeeper;-import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;-import com.pmease.gitop.model.gatekeeper.GateKeeper;-import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;-import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;--@SuppressWarnings("serial")-@Editable(order=200, icon="icon-lock", description="By default, users with write permission of "- + "the project can write to all directories. Use this gate keeper to restrict write "- + "access of certain directories in specified branches to certain teams. Note that if "- + "branch is not specified, the directory restriction will apply to all branches.")-public class DirectoryProtection extends CommonGateKeeper {-- private List<Long> branchIds = new ArrayList<Long>();-- private List<Entry> entries = new ArrayList<Entry>();-- public DirectoryProtection() {- Entry entry = new Entry();- entries.add(entry);- }-- @Editable(name="Branches To Apply (Optionally)", order=50)- @BranchChoice- @NotNull- public List<Long> getBranchIds() {- return branchIds;- }-- public void setBranchIds(List<Long> branchIds) {- this.branchIds = branchIds;- }-- @Editable(name="Protected Directories", order=100)- @Valid- @Size(min=1, message="At least one entry has to be added.")- @NotNull- @OmitName(OmitName.Place.EDITOR)- public List<Entry> getEntries() {- return entries;- }-- public void setEntries(List<Entry> entries) {- this.entries = entries;- }-- @Editable- public static class Entry implements Trimmable, Serializable {-- private String directory;-- private Long teamId;-- @Editable(name="Directory to Protect", order=100)- @DirectoryChoice- @NotEmpty- public String getDirectory() {- return directory;- }-- public void setDirectory(String directory) {- this.directory = directory;- }-- @Editable(name="Team Can Write", order=200)- @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})- @NotNull- public Long getTeamId() {- return teamId;- }-- public void setTeamId(Long teamId) {- this.teamId = teamId;- }-- @Override- public Object trim(Object context) {- if (Gitop.getInstance(TeamManager.class).get(teamId) == null)- return null;- else- return this;- }-- }-- private GateKeeper getGateKeeper() {- AndGateKeeper andGate = new AndGateKeeper();- for (Entry entry: entries) {- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();- IfTouchesSpecifiedDirectories ifGate = new IfTouchesSpecifiedDirectories();- ifGate.getDirectories().add(entry.getDirectory());- ifThenGate.setIfGate(ifGate);-- IfApprovedBySpecifiedTeam thenGate = new IfApprovedBySpecifiedTeam();- thenGate.setTeamId(entry.getTeamId());- ifThenGate.setThenGate(thenGate);-- andGate.getGateKeepers().add(ifThenGate);- }- if (branchIds.isEmpty()) {- return andGate;- } else {- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();- IfSubmittedToSpecifiedBranches branchGate = new IfSubmittedToSpecifiedBranches();- branchGate.getBranchIds().addAll(branchIds);- ifThenGate.setIfGate(branchGate);- ifThenGate.setThenGate(andGate);- return ifThenGate;- }- }-- @Override- protected GateKeeper trim(Project project) {- if (!branchIds.isEmpty()) {- for (Iterator<Long> it = branchIds.iterator(); it.hasNext();) {- if (Gitop.getInstance(BranchManager.class).get(it.next()) == null)- it.remove();- }- if (branchIds.isEmpty())- return null;- }- TrimUtils.trim(entries, project);-- if (entries.isEmpty())- return null;- else- return this;- }-- @Override- protected CheckResult doCheckRequest(PullRequest request) {- return getGateKeeper().checkRequest(request);- }-- @Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- return getGateKeeper().checkFile(user, branch, file);- }-- @Override- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return getGateKeeper().checkCommit(user, branch, commit);- }--}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/HistoryProtection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/HistoryProtection.javanew file mode 100644index 0000000000..26854e2c9d--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/HistoryProtection.java@@ -0,0 +1,72 @@+package com.pmease.gitop.core.gatekeeper;++import javax.validation.Valid;+import javax.validation.constraints.NotNull;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.TargetBranchSelection;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;+import com.pmease.gitop.model.gatekeeper.GateKeeper;+import com.pmease.gitop.model.gatekeeper.IfThenGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@SuppressWarnings("serial")+@Editable(order=400, icon="icon-lock", description=+ "Use this gate keeper to prevent history of certain branches from being rewritten via forced push.")+public class HistoryProtection extends CommonGateKeeper {++ private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();++ @Editable(name="Specify Branches to Be Protected", order=100)+ @Valid+ @NotNull+ public TargetBranchSelection getBranchSelection() {+ return branchSelection;+ }++ public void setBranchSelection(TargetBranchSelection branchSelection) {+ this.branchSelection = branchSelection;+ }++ @Override+ protected GateKeeper trim(Project project) {+ if (branchSelection.trim(project) == null)+ return null;+ else+ return this;+ }++ private GateKeeper getGateKeeper() {+ IfThenGateKeeper ifThenGate = new IfThenGateKeeper();+ ifThenGate.setIfGate(branchSelection.getGateKeeper());+ ifThenGate.setThenGate(new IfPushWithoutRewritingHistory());++ return ifThenGate;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return getGateKeeper().checkRequest(request);+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return getGateKeeper().checkFile(user, branch, file);+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return getGateKeeper().checkCommit(user, branch, commit);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return getGateKeeper().checkRef(user, project, refName);+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByBranchCreator.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByBranchCreator.javanew file mode 100644index 0000000000..fac31e3bf4--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByBranchCreator.java@@ -0,0 +1,68 @@+package com.pmease.gitop.core.gatekeeper;++import com.google.common.collect.Sets;+import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.core.manager.VoteInvitationManager;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.Vote;+import com.pmease.gitop.model.gatekeeper.ApprovalGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;+import com.pmease.gitop.model.gatekeeper.voteeligibility.CanVoteBySpecifiedUser;++@SuppressWarnings("serial")+@Editable(order=310, icon="icon-user", description=+ "This gate keeper will be passed if the commit is approved by creator of target branch.")+public class IfApprovedByBranchCreator extends ApprovalGateKeeper {++ @Override+ public CheckResult doCheckRequest(PullRequest request) {+ User branchCreator = request.getTarget().getCreator();++ if (branchCreator != null) {+ Vote.Result result = branchCreator.checkVoteSince(request.getBaseUpdate());++ if (result == null) {+ Gitop.getInstance(VoteInvitationManager.class).inviteToVote(request, Sets.newHashSet(branchCreator), 1);+ return pending("To be approved by user '" + branchCreator.getName() + "'.",+ new CanVoteBySpecifiedUser(branchCreator));+ } else if (result.isAccept()) {+ return accepted("Approved by user '" + branchCreator.getName() + "'.");+ } else {+ return rejected("Rejected by user '" + branchCreator.getName() + "'.");+ }+ } else {+ return rejected("Rejected as branch creator is unknown.");+ }+ }++ private CheckResult checkBranch(User user, Branch branch) {+ if (branch.getCreator() != null) {+ if (user.equals(branch.getCreator()))+ return accepted("Approved by branch creator.");+ else+ return pending("Not approved by branch creator.", new CanVoteBySpecifiedUser(branch.getCreator()));+ } else {+ return rejected("Rejected as branch creator is unknown.");+ }+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return checkBranch(user, branch);+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return checkBranch(user, branch);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.javaindex 47f431e290..fd80defbd2 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java@@ -1,9 +1,8 @@package com.pmease.gitop.core.gatekeeper;-import javax.annotation.Nullable;-import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.GateKeeper;@@ -37,7 +36,7 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {+ protected CheckResult doCheckFile(User user, Branch branch, String file) {CheckResult result = getGateKeeper().checkFile(user, branch, file);if (result instanceof Accepted)@@ -60,4 +59,16 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {return result;}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ CheckResult result = getGateKeeper().checkRef(user, project, refName);++ if (result instanceof Accepted)+ result = accepted("Approved by majorities of team '" + getTeam().getName() + "'.");+ else if (result instanceof Rejected)+ result = rejected("Not approved by majorities of team '" + getTeam().getName() + "'.");++ return result;+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectOwner.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectOwner.javaindex 14abfc1b9c..27e9a600e5 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectOwner.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectOwner.java@@ -1,12 +1,11 @@package com.pmease.gitop.core.gatekeeper;-import javax.annotation.Nullable;-import com.google.common.collect.Sets;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.manager.VoteInvitationManager;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.Vote;@@ -36,21 +35,29 @@ public class IfApprovedByProjectOwner extends ApprovalGateKeeper {}}- private CheckResult checkBranch(User user, Branch branch) {- if (user.equals(branch.getProject().getOwner()))+ private CheckResult checkApproval(User user, Project project) {+ if (user.equals(project.getOwner()))return accepted("Approved by project owner.");else- return pending("Not approved by project owner.", new CanVoteBySpecifiedUser(branch.getProject().getOwner()));+ return pending("Not approved by project owner.", new CanVoteBySpecifiedUser(project.getOwner()));}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- return checkBranch(user, branch);+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return checkApproval(user, branch.getProject());}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(user, branch);+ return checkApproval(user, branch.getProject());+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ if (user.equals(project.getOwner()))+ return accepted("Approved by project owner.");+ else+ return rejected("Not approved by project owner.");}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByAuthorizedUsers.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectWriters.javasimilarity index 83%rename from gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByAuthorizedUsers.javarename to gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectWriters.javaindex 7a9e1e236b..70a70de2a3 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByAuthorizedUsers.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedByProjectWriters.java@@ -2,7 +2,6 @@ package com.pmease.gitop.core.gatekeeper;import java.util.Collection;-import javax.annotation.Nullable;import javax.validation.constraints.Min;import com.pmease.commons.editable.annotation.Editable;@@ -10,6 +9,7 @@ import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.manager.AuthorizationManager;import com.pmease.gitop.core.manager.VoteInvitationManager;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.Vote;@@ -22,7 +22,7 @@ import com.pmease.gitop.model.permission.operation.GeneralOperation;@Editable(order=50, icon="icon-group", description="This gate keeper will be passed if the commit is approved by specified number of users with "+ "writing permission.")-public class IfApprovedByAuthorizedUsers extends ApprovalGateKeeper {+public class IfApprovedByProjectWriters extends ApprovalGateKeeper {private int leastApprovals = 1;@@ -68,16 +68,16 @@ public class IfApprovedByAuthorizedUsers extends ApprovalGateKeeper {}}- private CheckResult checkBranch(User user, Branch branch) {+ private CheckResult checkApproval(User user, Project project) {AuthorizationManager authorizationManager = Gitop.getInstance(AuthorizationManager.class);- Collection<User> authorizedUsers = authorizationManager.listAuthorizedUsers(- branch.getProject(), GeneralOperation.WRITE);+ Collection<User> writers = authorizationManager.listAuthorizedUsers(+ project, GeneralOperation.WRITE);int approvals = 0;- int pendings = authorizedUsers.size();+ int pendings = writers.size();- if (authorizedUsers.contains(user)) {+ if (writers.contains(user)) {approvals ++;pendings --;}@@ -94,13 +94,18 @@ public class IfApprovedByAuthorizedUsers extends ApprovalGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- return checkBranch(user, branch);+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return checkApproval(user, branch.getProject());}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(user, branch);+ return checkApproval(user, branch.getProject());+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return checkApproval(user, project);}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedTeam.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedTeam.javaindex e2f9706b9a..daea707024 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedTeam.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedTeam.java@@ -10,6 +10,7 @@ import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.manager.VoteInvitationManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Membership;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.Vote;@@ -67,7 +68,7 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {}}- private CheckResult checkBranch(User user, Branch branch) {+ private CheckResult checkApproval(User user) {Collection<User> members = new HashSet<User>();for (Membership membership : getTeam().getMemberships())members.add(membership.getUser());@@ -96,12 +97,17 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(user, branch);+ return checkApproval(user);}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return checkBranch(user, branch);+ return checkApproval(user);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return checkApproval(user);}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.javaindex 744c39e800..44a3cf6050 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfApprovedBySpecifiedUser.java@@ -1,11 +1,9 @@package com.pmease.gitop.core.gatekeeper;-import javax.annotation.Nullable;import javax.validation.constraints.NotNull;import com.google.common.collect.Sets;import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.loader.AppLoader;import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.editable.UserChoice;import com.pmease.gitop.core.manager.UserManager;@@ -58,14 +56,13 @@ public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {@Overrideprotected GateKeeper trim(Project project) {- UserManager userManager = AppLoader.getInstance(UserManager.class);- if (userManager.get(getUserId()) == null)+ if (Gitop.getInstance(UserManager.class).get(getUserId()) == null)return null;elsereturn this;}- private CheckResult checkBranch(User user, Branch branch) {+ private CheckResult checkApproval(User user) {User approver = Gitop.getInstance(UserManager.class).load(userId);if (approver.getId().equals(user.getId())) {return accepted("Approved by user '" + approver.getName() + "'.");@@ -76,13 +73,18 @@ public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- return checkBranch(user, branch);+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return checkApproval(user);}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(user, branch);+ return checkApproval(user);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return checkApproval(user);}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfCreateSpecifiedBranches.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfCreateSpecifiedBranches.javanew file mode 100644index 0000000000..3a5e8098bd--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfCreateSpecifiedBranches.java@@ -0,0 +1,66 @@+package com.pmease.gitop.core.gatekeeper;++import org.hibernate.validator.constraints.NotEmpty;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.commons.git.Git;+import com.pmease.commons.util.pattern.WildcardUtils;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.BranchGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@Editable(order=210, icon="icon-git-branch-pattern", description=+ "This gate keeper will be passed if the branch to be created matches specified patterns.")+@SuppressWarnings("serial")+public class IfCreateSpecifiedBranches extends BranchGateKeeper {++ private String branchPatterns;++ @Editable(name="Specify Branch Patterns", description="Specify branch patterns to match. Below is some examples:"+ + "<ul>"+ + "<li><i>dev/*</i>: matches all branches directly under dev."+ + "<li><i>dev/**</i>: matches all branches under dev recursively."+ + "<li><i>**</i>: matches all branches."+ + "<li><i>**/bugfix</i>: matches all branches whose last segment is bugfix."+ + "<li><i>-dev/**, **</i>: matches all branches except those under dev."+ + "</ul>")+ @NotEmpty+ public String getBranchPatterns() {+ return branchPatterns;+ }++ public void setBranchPatterns(String branchPatterns) {+ this.branchPatterns = branchPatterns;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ if (refName.startsWith(Git.REFS_HEADS)) {+ if (WildcardUtils.matchPath(Git.REFS_HEADS + getBranchPatterns(), refName))+ return accepted("Branch to be created matches pattern '" + branchPatterns + "'.");+ else+ return rejected("Branch to be created does not match pattern '" + branchPatterns + "'.");+ } else {+ return ignored();+ }+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.javaindex 6c78288dff..78e12a0678 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java@@ -10,6 +10,7 @@ import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.manager.VoteInvitationManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Membership;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.Vote;@@ -105,7 +106,7 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {}}- private CheckResult checkBranch(User user, Branch branch) {+ private CheckResult checkApproval(User user) {Collection<User> members = new HashSet<User>();for (Membership membership : getTeam().getMemberships())members.add(membership.getUser());@@ -132,12 +133,17 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return checkBranch(user, branch);+ return checkApproval(user);}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(user, branch);+ return checkApproval(user);+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return checkApproval(user);}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfNotRejectedBySpecifiedTeam.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfNotRejectedBySpecifiedTeam.javaindex c94ccb4f57..db3e288f0a 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfNotRejectedBySpecifiedTeam.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfNotRejectedBySpecifiedTeam.java@@ -1,10 +1,9 @@package com.pmease.gitop.core.gatekeeper;-import javax.annotation.Nullable;-import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Membership;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.Vote;@@ -28,7 +27,7 @@ public class IfNotRejectedBySpecifiedTeam extends TeamAwareGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {+ protected CheckResult doCheckFile(User user, Branch branch, String file) {return accepted("Not rejected by anyone from team '" + getTeam().getName() + "'.");}@@ -37,4 +36,9 @@ public class IfNotRejectedBySpecifiedTeam extends TeamAwareGateKeeper {return accepted("Not rejected by anyone from team '" + getTeam().getName() + "'.");}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return accepted("Not rejected by anyone from team '" + getTeam().getName() + "'.");+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.javanew file mode 100644index 0000000000..c3b823be81--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.java@@ -0,0 +1,68 @@+package com.pmease.gitop.core.gatekeeper;++import org.hibernate.validator.constraints.NotEmpty;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.commons.git.Git;+import com.pmease.commons.util.pattern.WildcardUtils;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.AbstractGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@Editable(order=200, icon="icon-git-branch-pattern", description=+ "This gate keeper will be passed if push to specified non-branch references. Note that "+ + "touching various branch references under refs/heads will not trigger this gate "+ + "keeper. Use branch related gate keepers if you would like to match desired branches.")+@SuppressWarnings("serial")+public class IfPushToSpecifiedNonBranchRefs extends AbstractGateKeeper {++ private String refPatterns;++ @Editable(name="Specify Non-Branch Ref Patterns", description="Specify non-branch ref patterns to match. Below is some examples:"+ + "<ul>"+ + "<li><i>refs/tags/*</i>: matches all refs directly under refs/tags."+ + "<li><i>refs/tags/**</i>: matches all refs under refs/tags recursively."+ + "<li><i>refs/**</i>: matches all refs."+ + "<li><i>refs/**/1.0</i>: matches all refs whose last segment is 1.0."+ + "<li><i>-refs/tags/release/**, refs/tags/**</i>: matches all refs under refs/tags except those under refs/tags/release."+ + "</ul>")+ @NotEmpty+ public String getRefPatterns() {+ return refPatterns;+ }++ public void setRefPatterns(String refPatterns) {+ this.refPatterns = refPatterns;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ if (refName.startsWith(Git.REFS_HEADS)) {+ return ignored();+ } else {+ if (WildcardUtils.matchPath(getRefPatterns(), refName))+ return accepted("Target ref matches pattern '" + refPatterns + "'.");+ else+ return rejected("Target ref does not match pattern '" + refPatterns + "'.");+ }+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushWithoutRewritingHistory.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushWithoutRewritingHistory.javanew file mode 100644index 0000000000..eaa87f8c50--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfPushWithoutRewritingHistory.java@@ -0,0 +1,40 @@+package com.pmease.gitop.core.gatekeeper;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.AbstractGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@Editable(order=100, icon="icon-repo-lock", description="This gate keeper will be passed if the push operation does not rewrite history "+ + "of target branch. Rewriting history of public branches is dangerous, and it happens when user forces "+ + "a push without merging/rebasing with the branch head.")+@SuppressWarnings("serial")+public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ if (branch.getProject().code().isAncestor(branch.getHeadCommit(), commit))+ return accepted("Push operation does not rewrite history.");+ else+ return rejected("Push operation rewrites history.");+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.javasimilarity index 88%rename from gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.javarename to gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.javaindex a5a89c002c..4d75df1d99 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java@@ -1,12 +1,11 @@package com.pmease.gitop.core.gatekeeper;-import javax.annotation.Nullable;-import org.hibernate.validator.constraints.NotEmpty;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.BranchGateKeeper;@@ -15,7 +14,7 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@Editable(order=200, icon="icon-git-branch-pattern", description="This gate keeper will be passed if the commit is submitted to specified branch pattern.")-public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {+public class IfSubmitToSpecifiedBranchPatterns extends BranchGateKeeper {private String branchPatterns;@@ -45,7 +44,7 @@ public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {+ protected CheckResult doCheckFile(User user, Branch branch, String file) {if (WildcardUtils.matchPath(getBranchPatterns(), branch.getName()))return accepted("Target branch matches pattern '" + branchPatterns + "'.");else@@ -60,4 +59,9 @@ public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {return rejected("Target branch does not match pattern '" + branchPatterns + "'.");}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranches.javasimilarity index 86%rename from gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.javarename to gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranches.javaindex f547516481..d50947bf54 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitToSpecifiedBranches.java@@ -1,10 +1,8 @@package com.pmease.gitop.core.gatekeeper;import java.util.ArrayList;-import java.util.Iterator;import java.util.List;-import javax.annotation.Nullable;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;@@ -25,7 +23,7 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@Editable(order=100, icon="icon-git-branch", description="This gate keeper will be passed if the commit is submitted to specified branches.")-public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {+public class IfSubmitToSpecifiedBranches extends BranchGateKeeper {private List<Long> branchIds = new ArrayList<>();@@ -56,11 +54,7 @@ public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {@Overrideprotected GateKeeper trim(Project project) {- BranchManager branchManager = Gitop.getInstance(BranchManager.class);- for (Iterator<Long> it = branchIds.iterator(); it.hasNext();) {- if (branchManager.get(it.next()) == null)- it.remove();- }+ Gitop.getInstance(BranchManager.class).trim(branchIds);if (branchIds.isEmpty())return null;else@@ -80,7 +74,7 @@ public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {+ protected CheckResult doCheckFile(User user, Branch branch, String file) {return checkBranch(user, branch);}@@ -89,4 +83,9 @@ public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {return checkBranch(user, branch);}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitWithGerritStylePatch.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitWithGerritStylePatch.javanew file mode 100644index 0000000000..2fb5848c40--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmitWithGerritStylePatch.java@@ -0,0 +1,43 @@+package com.pmease.gitop.core.gatekeeper;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;+import com.pmease.gitop.model.PullRequest;+import com.pmease.gitop.model.User;+import com.pmease.gitop.model.gatekeeper.AbstractGateKeeper;+import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;++@Editable(order=150, description="This gate keeper will be passed if the pull request is submitted with "+ + "gerrit style patch, that is, only one commit is submitted for review at a time, and "+ + "subsequent updates to the review should be done by amending previous commit.")+@SuppressWarnings("serial")+public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ String branchHead = request.getTarget().getHeadCommit();+ String requestHead = request.getLatestUpdate().getHeadCommit();+ if (request.getTarget().getProject().code().log(branchHead, requestHead, null, 0, 0).size() > 1) {+ return rejected("Please squash/rebase your commits.");+ } else {+ return accepted("No more than one commit.");+ }+ }++ @Override+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckCommit(User user, Branch branch, String commit) {+ return ignored();+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedDirectories.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedDirectories.javasimilarity index 82%rename from gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedDirectories.javarename to gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedDirectories.javaindex 0a972f9a88..8fb55bd35e 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedDirectories.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedDirectories.java@@ -4,7 +4,6 @@ import java.util.ArrayList;import java.util.Collection;import java.util.List;-import javax.annotation.Nullable;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;@@ -12,6 +11,7 @@ import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitop.core.editable.DirectoryChoice;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.PullRequestUpdate;import com.pmease.gitop.model.User;@@ -21,7 +21,7 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@Editable(order=90, icon="icon-folder-submodule", description="This gate keeper will be passed if any commit files are under specified directories.")-public class IfTouchesSpecifiedDirectories extends FileGateKeeper {+public class IfTouchSpecifiedDirectories extends FileGateKeeper {private List<String> directories = new ArrayList<>();@@ -58,16 +58,12 @@ public class IfTouchesSpecifiedDirectories extends FileGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- if (file != null) {- for (String each: directories) {- if (WildcardUtils.matchPath(each + "/**", file))- return accepted("Touched directory '" + each + "'.");- }- return rejected("Not touched directories '" + getDirectories() + "'.");- } else {- return accepted("Touched specified directories.");+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ for (String each: directories) {+ if (WildcardUtils.matchPath(each + "/**", file))+ return accepted("Touched directory '" + each + "'.");}+ return rejected("Not touched directories '" + getDirectories() + "'.");}@Override@@ -82,4 +78,9 @@ public class IfTouchesSpecifiedDirectories extends FileGateKeeper {return rejected("Not touched directories '" + getDirectories() + "'.");}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedFilePatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedFilePatterns.javasimilarity index 82%rename from gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedFilePatterns.javarename to gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedFilePatterns.javaindex f5905f5222..3255b93ebe 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchesSpecifiedFilePatterns.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfTouchSpecifiedFilePatterns.java@@ -2,13 +2,12 @@ package com.pmease.gitop.core.gatekeeper;import java.util.Collection;-import javax.annotation.Nullable;-import org.hibernate.validator.constraints.NotEmpty;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.PullRequestUpdate;import com.pmease.gitop.model.User;@@ -18,7 +17,7 @@ import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@Editable(order=100, icon="icon-file-text", description="This gate keeper will be passed if any commit file maches specified file patterns.")-public class IfTouchesSpecifiedFilePatterns extends FileGateKeeper {+public class IfTouchSpecifiedFilePatterns extends FileGateKeeper {private String filePatterns;@@ -59,15 +58,11 @@ public class IfTouchesSpecifiedFilePatterns extends FileGateKeeper {}@Override- protected CheckResult doCheckFile(User user, Branch branch, @Nullable String file) {- if (file != null) {- if (WildcardUtils.matchPath(filePatterns, file))- return accepted("Touched files match patterns '" + filePatterns + "'.");- else- return rejected("No touched files match patterns '" + filePatterns + "'.");- } else {- return accepted("Touched specified files.");- }+ protected CheckResult doCheckFile(User user, Branch branch, String file) {+ if (WildcardUtils.matchPath(filePatterns, file))+ return accepted("Touched files match patterns '" + filePatterns + "'.");+ else+ return rejected("No touched files match patterns '" + filePatterns + "'.");}@Override@@ -80,4 +75,9 @@ public class IfTouchesSpecifiedFilePatterns extends FileGateKeeper {return rejected("No touched files match patterns '" + filePatterns + "'.");}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfVerifiedByBuilds.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfVerifiedByBuilds.javaindex 10b789ae12..c819300a34 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfVerifiedByBuilds.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfVerifiedByBuilds.java@@ -10,9 +10,10 @@ import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.manager.BuildResultManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.BuildResult;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;-import com.pmease.gitop.model.gatekeeper.CommonGateKeeper;+import com.pmease.gitop.model.gatekeeper.AbstractGateKeeper;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;import com.pmease.gitop.model.gatekeeper.voteeligibility.NoneCanVote;@@ -21,7 +22,7 @@ import com.pmease.gitop.model.gatekeeper.voteeligibility.NoneCanVote;+ "by specified number of builds. To make this working, your CI system has to "+ "be configured to build against Gitop pull requests.")@SuppressWarnings("serial")-public class IfVerifiedByBuilds extends CommonGateKeeper {+public class IfVerifiedByBuilds extends AbstractGateKeeper {private int buildCount = 1;@@ -29,7 +30,9 @@ public class IfVerifiedByBuilds extends CommonGateKeeper {private boolean blockMode = true;- @Editable(order=100, description="Specify number of passed builds required by this gate keeper.")+ @Editable(order=100, description="This specified number of builds has to be reported successful "+ + "for this gate keeper to be passed. Normally this number represents number of build "+ + "configurations setting up to verify the branch.")@Min(1)public int getBuildCount() {return buildCount;@@ -99,14 +102,10 @@ public class IfVerifiedByBuilds extends CommonGateKeeper {@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- if (file != null) {- if (blockMode)- return pendingAndBlock("Not verified by build.", new NoneCanVote());- else- return pending("Not verified by build.", new NoneCanVote());- } else {- return accepted("Build is not necessary.");- }+ if (blockMode)+ return pendingAndBlock("Not verified by build.", new NoneCanVote());+ else+ return pending("Not verified by build.", new NoneCanVote());}@Override@@ -137,4 +136,9 @@ public class IfVerifiedByBuilds extends CommonGateKeeper {}}+ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.javaindex 6432483e71..a902208300 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/TeamAwareGateKeeper.java@@ -33,8 +33,7 @@ public abstract class TeamAwareGateKeeper extends ApprovalGateKeeper {@Overrideprotected GateKeeper trim(Project project) {- TeamManager teamManager = Gitop.getInstance(TeamManager.class);- if (teamManager.get(getTeamId()) == null)+ if (Gitop.getInstance(TeamManager.class).get(getTeamId()) == null)return null;elsereturn this;diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.javanew file mode 100644index 0000000000..71146f22b0--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByIds.java@@ -0,0 +1,50 @@+package com.pmease.gitop.core.gatekeeper.helper.branchselection;++import java.util.ArrayList;+import java.util.List;++import javax.validation.constraints.NotNull;+import javax.validation.constraints.Size;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.core.editable.BranchChoice;+import com.pmease.gitop.core.gatekeeper.IfSubmitToSpecifiedBranches;+import com.pmease.gitop.core.manager.BranchManager;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@SuppressWarnings("serial")+@Editable(name="Selected Branches", order=100)+public class SpecifyTargetBranchesByIds implements TargetBranchSelection {++ private List<Long> branchIds = new ArrayList<>();++ @Editable(name="Branches", description="Select branches to check.")+ @BranchChoice+ @NotNull+ @Size(min=1)+ public List<Long> getBranchIds() {+ return branchIds;+ }++ public void setBranchIds(List<Long> branchIds) {+ this.branchIds = branchIds;+ }++ @Override+ public GateKeeper getGateKeeper() {+ IfSubmitToSpecifiedBranches gateKeeper = new IfSubmitToSpecifiedBranches();+ gateKeeper.getBranchIds().addAll(branchIds);+ return gateKeeper;+ }++ @Override+ public Object trim(Object context) {+ Gitop.getInstance(BranchManager.class).trim(branchIds);+ if (branchIds.isEmpty())+ return null;+ else+ return this;+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.javanew file mode 100644index 0000000000..ab917d0b6e--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java@@ -0,0 +1,44 @@+package com.pmease.gitop.core.gatekeeper.helper.branchselection;++import org.hibernate.validator.constraints.NotEmpty;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.gatekeeper.IfSubmitToSpecifiedBranchPatterns;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@SuppressWarnings("serial")+@Editable(order=200, name="Branches Matching Specified Patterns")+public class SpecifyTargetBranchesByPatterns implements TargetBranchSelection {++ private String branchPatterns;++ @Editable(name="Patterns", description="Specify branch patterns to match. Below is some examples:"+ + "<ul>"+ + "<li><i>dev/*</i>: matches all branches directly under dev."+ + "<li><i>dev/**</i>: matches all branches under dev recursively."+ + "<li><i>**</i>: matches all branches."+ + "<li><i>**/bugfix</i>: matches all branches whose last segment is bugfix."+ + "<li><i>-dev/**, **</i>: matches all branches except those under dev."+ + "</ul>")+ @NotEmpty+ public String getBranchPatterns() {+ return branchPatterns;+ }++ public void setBranchPatterns(String branchPatterns) {+ this.branchPatterns = branchPatterns;+ }++ @Override+ public Object trim(Object context) {+ return this;+ }++ @Override+ public GateKeeper getGateKeeper() {+ IfSubmitToSpecifiedBranchPatterns gateKeeper = new IfSubmitToSpecifiedBranchPatterns();+ gateKeeper.setBranchPatterns(branchPatterns);+ return gateKeeper;+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/TargetBranchSelection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/TargetBranchSelection.javanew file mode 100644index 0000000000..8c57d170e0--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/branchselection/TargetBranchSelection.java@@ -0,0 +1,13 @@+package com.pmease.gitop.core.gatekeeper.helper.branchselection;++import java.io.Serializable;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.commons.util.trimmable.Trimmable;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@Editable+public interface TargetBranchSelection extends Trimmable, Serializable {++ GateKeeper getGateKeeper();+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.javanew file mode 100644index 0000000000..8da53f6f53--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.java@@ -0,0 +1,39 @@+package com.pmease.gitop.core.gatekeeper.helper.pathselection;++import java.util.ArrayList;+import java.util.List;++import javax.validation.constraints.NotNull;+import javax.validation.constraints.Size;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.editable.DirectoryChoice;+import com.pmease.gitop.core.gatekeeper.IfTouchSpecifiedDirectories;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@SuppressWarnings("serial")+@Editable(name="Selected Directories", order=100)+public class SpecifyTargetPathsByDirectories implements TargetPathSelection {++ private List<String> directories = new ArrayList<>();++ @Editable(name="Directories", description="Use comma to separate multiple directories.")+ @DirectoryChoice+ @NotNull+ @Size(min=1, message="At least one directory has to be specified.")+ public List<String> getDirectories() {+ return directories;+ }++ public void setDirectories(List<String> directories) {+ this.directories = directories;+ }++ @Override+ public GateKeeper getGateKeeper() {+ IfTouchSpecifiedDirectories gateKeeper = new IfTouchSpecifiedDirectories();+ gateKeeper.setDirectories(directories);+ return gateKeeper;+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.javanew file mode 100644index 0000000000..9e48b6b876--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.java@@ -0,0 +1,39 @@+package com.pmease.gitop.core.gatekeeper.helper.pathselection;++import org.hibernate.validator.constraints.NotEmpty;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.core.gatekeeper.IfTouchSpecifiedFilePatterns;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@SuppressWarnings("serial")+@Editable(name="Paths Matching Specified File Patterns", order=200)+public class SpecifyTargetPathsByPatterns implements TargetPathSelection {++ private String filePatterns;++ @Editable(name="File Patterns", description="Specify file patterns to match. Below is some examples:"+ + "<ul>"+ + "<li><i>src/*</i>: matches all files directly under src."+ + "<li><i>src/**</i>: matches all files under src recursively."+ + "<li><i>**</i>: matches all files."+ + "<li><i>**/*.c, **/*.java</i>: matches all C and Java files."+ + "<li><i>-src/**, **</i>: matches all files except those under src."+ + "</ul>")+ @NotEmpty+ public String getFilePatterns() {+ return filePatterns;+ }++ public void setFilePatterns(String filePatterns) {+ this.filePatterns = filePatterns;+ }++ @Override+ public GateKeeper getGateKeeper() {+ IfTouchSpecifiedFilePatterns gateKeeper = new IfTouchSpecifiedFilePatterns();+ gateKeeper.setFilePatterns(filePatterns);+ return gateKeeper;+ }++}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/TargetPathSelection.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/TargetPathSelection.javanew file mode 100644index 0000000000..424d5f29b4--- /dev/null+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/helper/pathselection/TargetPathSelection.java@@ -0,0 +1,11 @@+package com.pmease.gitop.core.gatekeeper.helper.pathselection;++import java.io.Serializable;++import com.pmease.commons.editable.annotation.Editable;+import com.pmease.gitop.model.gatekeeper.GateKeeper;++@Editable+public interface TargetPathSelection extends Serializable {+ GateKeeper getGateKeeper();+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitPostReceiveCallback.java b/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitPostReceiveCallback.javaindex c5212dd355..5007a81eb5 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitPostReceiveCallback.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitPostReceiveCallback.java@@ -24,6 +24,7 @@ import com.pmease.commons.util.StringUtils;import com.pmease.gitop.core.event.BranchRefUpdateEvent;import com.pmease.gitop.core.manager.BranchManager;import com.pmease.gitop.core.manager.ProjectManager;+import com.pmease.gitop.core.manager.UserManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Project;import com.pmease.gitop.model.User;@@ -40,12 +41,16 @@ public class GitPostReceiveCallback extends HttpServlet {private final BranchManager branchManager;+ private final UserManager userManager;+private final EventBus eventBus;@Inject- public GitPostReceiveCallback(ProjectManager projectManager, BranchManager branchManager, EventBus eventBus) {+ public GitPostReceiveCallback(ProjectManager projectManager, BranchManager branchManager,+ UserManager userManager, EventBus eventBus) {this.projectManager = projectManager;this.branchManager = branchManager;+ this.userManager = userManager;this.eventBus = eventBus;}@@ -106,6 +111,7 @@ public class GitPostReceiveCallback extends HttpServlet {Branch branch = new Branch();branch.setProject(project);branch.setName(branchName);+ branch.setCreator(userManager.getCurrent());project.getBranches().add(branch);branchManager.save(branch);if (project.getBranches().size() == 1)@@ -118,7 +124,7 @@ public class GitPostReceiveCallback extends HttpServlet {if (project.code().resolveDefaultBranch().equals(branchName) && !project.getBranches().isEmpty())project.code().updateDefaultBranch(project.getBranches().iterator().next().getName());} else {- logger.info("Executing post-receive hook against branch {}...", branchName);+ logger.debug("Executing post-receive hook against branch {}...", branchName);Branch branch = branchManager.findBy(project, branchName);Preconditions.checkNotNull(branch);diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitUpdateCallback.java b/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitUpdateCallback.javaindex 671f7b4281..28f21c0de0 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitUpdateCallback.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/hookcallback/GitUpdateCallback.java@@ -26,7 +26,6 @@ import com.pmease.gitop.core.manager.ProjectManager;import com.pmease.gitop.core.manager.UserManager;import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Project;-import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.GateKeeper;import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;@@ -67,6 +66,18 @@ public class GitUpdateCallback extends HttpServlet {output.writeLine();}+ private void checkRef(User user, Project project, String refName, Output output) {+ GateKeeper gateKeeper = project.getGateKeeper();+ CheckResult checkResult = gateKeeper.checkRef(user, project, refName);++ if (!(checkResult instanceof Accepted)) {+ List<String> messages = new ArrayList<>();+ for (String each: checkResult.getReasons())+ messages.add(each);+ error(output, messages.toArray(new String[messages.size()]));+ }+ }+@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String clientIp = request.getHeader("X-Forwarded-For");@@ -95,55 +106,46 @@ public class GitUpdateCallback extends HttpServlet {String oldCommitHash = fields.get(1);String newCommitHash = fields.get(2);+ logger.debug("Executing update hook against reference {}...", refName);++ User user = userManager.getCurrent();+ Preconditions.checkNotNull(user);+if (refName.startsWith(Project.REFS_GITOP)) {- if (!SecurityUtils.getSubject().isPermitted(ObjectPermission.ofProjectAdmin(project)))+ if (!user.asSubject().isPermitted(ObjectPermission.ofProjectAdmin(project)))error(output, "Only project administrators can update gitop refs.");} else {String branchName = Branch.getName(refName);- if (branchName != null) {- if (!oldCommitHash.equals(Commit.ZERO_HASH)) {+ if (branchName != null) { // push branch ref+ if (oldCommitHash.equals(Commit.ZERO_HASH)) { // create new branch+ checkRef(user, project, refName, output);+ } else {Branch branch = branchManager.findBy(project, branchName);Preconditions.checkNotNull(branch);- logger.info("Executing pre-receive hook against branch {}...", branchName);-- User user = userManager.getCurrent();- Preconditions.checkNotNull(user);-- GateKeeper gateKeeper = project.getGateKeeper();- CheckResult checkResult;- if (newCommitHash.equals(Commit.ZERO_HASH))- checkResult = gateKeeper.checkFile(user, branch, null);- else- checkResult = gateKeeper.checkCommit(user, branch, newCommitHash);-- if (!(checkResult instanceof Accepted)) {- List<String> messages = new ArrayList<>();- for (String each: checkResult.getReasons())- messages.add(each);- if (!newCommitHash.equals(Commit.ZERO_HASH) && !(checkResult instanceof Rejected)) {- messages.add("");- messages.add("----------------------------------------------------");- messages.add("You may submit a pull request instead.");+ if (newCommitHash.equals(Commit.ZERO_HASH)) { // deleting a branch ref+ if (!user.asSubject().isPermitted(ObjectPermission.ofProjectAdmin(project)) && !user.equals(branch.getCreator())) {+ error(output, "Branch can only be deleted by its creator or project administrators.");}- error(output, messages.toArray(new String[messages.size()]));} else {- for (PullRequest each: branch.getIngoingRequests()) {- if (each.isOpen()) {- error(output, "There are unclosed pull requests targeting this branch.",- "Please close them before continue.");- return;- }- }- for (PullRequest each: branch.getOutgoingRequests()) {- if (each.isOpen()) {- error(output, "There are unclosed pull requests originating from this branch.",- "Please close them before continue.");- break;+ GateKeeper gateKeeper = project.getGateKeeper();+ CheckResult checkResult = gateKeeper.checkCommit(user, branch, newCommitHash);++ if (!(checkResult instanceof Accepted)) {+ List<String> messages = new ArrayList<>();+ for (String each: checkResult.getReasons())+ messages.add(each);+ if (!newCommitHash.equals(Commit.ZERO_HASH) && !(checkResult instanceof Rejected)) {+ messages.add("");+ messages.add("----------------------------------------------------");+ messages.add("You may submit a pull request instead.");}+ error(output, messages.toArray(new String[messages.size()]));}}}+ } else { // push non-branch refs+ checkRef(user, project, refName, output);}}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPullManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPullManager.javadeleted file mode 100644index 141c0c8344..0000000000--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPullManager.java+++ /dev/null@@ -1,11 +0,0 @@-package com.pmease.gitop.core.manager;--import com.google.inject.ImplementedBy;-import com.pmease.commons.hibernate.dao.GenericDao;-import com.pmease.gitop.core.manager.impl.DefaultAutoPullManager;-import com.pmease.gitop.model.AutoPull;--@ImplementedBy(DefaultAutoPullManager.class)-public interface AutoPullManager extends GenericDao<AutoPull> {--}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPushManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPushManager.javadeleted file mode 100644index 695d0ad223..0000000000--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/AutoPushManager.java+++ /dev/null@@ -1,11 +0,0 @@-package com.pmease.gitop.core.manager;--import com.google.inject.ImplementedBy;-import com.pmease.commons.hibernate.dao.GenericDao;-import com.pmease.gitop.core.manager.impl.DefaultAutoPushManager;-import com.pmease.gitop.model.AutoPush;--@ImplementedBy(DefaultAutoPushManager.class)-public interface AutoPushManager extends GenericDao<AutoPush> {--}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/BranchManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/BranchManager.javaindex b1da6fba14..7bc7a74010 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/BranchManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/BranchManager.java@@ -1,5 +1,7 @@package com.pmease.gitop.core.manager;+import java.util.Collection;+import javax.annotation.Nullable;import com.google.inject.ImplementedBy;@@ -83,4 +85,6 @@ public interface BranchManager extends GenericDao<Branch> {* new name of the branch*/public void rename(Branch branch, String newName);++ public void trim(Collection<Long> branchIds);}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/TeamManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/TeamManager.javaindex 46df39e9b6..5c3609001f 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/TeamManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/TeamManager.java@@ -1,5 +1,7 @@package com.pmease.gitop.core.manager;+import java.util.Collection;+import com.google.inject.ImplementedBy;import com.pmease.commons.hibernate.dao.GenericDao;import com.pmease.gitop.core.manager.impl.DefaultTeamManager;@@ -28,5 +30,7 @@ public interface TeamManager extends GenericDao<Team> {Team getOwners(User user);+ void trim(Collection<Long> teamIds);+GeneralOperation getActualAuthorizedOperation(Team team);}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/UserManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/UserManager.javaindex 262a3f7dae..d0e352d7a7 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/UserManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/UserManager.java@@ -1,5 +1,7 @@package com.pmease.gitop.core.manager;+import java.util.Collection;+import javax.annotation.Nullable;import com.google.inject.ImplementedBy;@@ -46,4 +48,5 @@ public interface UserManager extends GenericDao<User> {*/@Nullable User getCurrent();+ void trim(Collection<Long> userIds);}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPullManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPullManager.javadeleted file mode 100644index 87bb69ba28..0000000000--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPullManager.java+++ /dev/null@@ -1,89 +0,0 @@-package com.pmease.gitop.core.manager.impl;--import java.util.concurrent.Callable;-import java.util.concurrent.Executor;--import javax.inject.Inject;-import javax.inject.Singleton;--import org.apache.shiro.subject.Subject;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;--import com.google.common.eventbus.EventBus;-import com.google.common.eventbus.Subscribe;-import com.pmease.commons.git.Git;-import com.pmease.commons.hibernate.Sessional;-import com.pmease.commons.hibernate.UnitOfWork;-import com.pmease.commons.hibernate.dao.AbstractGenericDao;-import com.pmease.commons.hibernate.dao.GeneralDao;-import com.pmease.commons.util.ExceptionUtils;-import com.pmease.gitop.core.event.BranchRefUpdateEvent;-import com.pmease.gitop.core.manager.AutoPullManager;-import com.pmease.gitop.model.AutoPull;-import com.pmease.gitop.model.Branch;-import com.pmease.gitop.model.permission.ObjectPermission;--@Singleton-public class DefaultAutoPullManager extends AbstractGenericDao<AutoPull>- implements AutoPullManager {-- private final Logger logger = LoggerFactory.getLogger(DefaultAutoPullManager.class);-- private final EventBus eventBus;-- private final UnitOfWork unitOfWork;-- private final Executor executor;-- @Inject- public DefaultAutoPullManager(GeneralDao generalDao, EventBus eventBus,- UnitOfWork unitOfWork, Executor executor) {- super(generalDao);- this.eventBus = eventBus;- this.unitOfWork = unitOfWork;- this.executor = executor;- }-- @Sessional- @Subscribe- public void pullUpon(BranchRefUpdateEvent event) {- for (final AutoPull autoPull: event.getBranch().getAutoPullTargets()) {- Subject subject = autoPull.getTarget().getProject().getUser().asSubject();- if (subject.isPermitted(ObjectPermission.ofProjectRead(autoPull.getSource().getProject()))) {- executor.execute(new Runnable() {-- @Override- public void run() {- try {- unitOfWork.call(new Callable<Void>() {-- @Override- public Void call() throws Exception {- // Reload to avoid Hibernate LazyInitializationException- AutoPull reloaded = load(autoPull.getId());- Branch source = reloaded.getSource();- Branch target = reloaded.getTarget();- Git git = target.getProject().code();- String commit = source.getProject().code().parseRevision(source.getHeadRef(), true);- git.updateRef(target.getHeadRef(), commit, null, "Branch sync");-- eventBus.post(new BranchRefUpdateEvent(target));-- return null;- }-- });- } catch(Exception e) {- logger.error("Error performing branch sync.", e);- throw ExceptionUtils.unchecked(e);- }- }-- });- } else {- logger.error("Permission denied syncing from " + autoPull.getSource() + " to " + autoPull.getTarget());- }- }- }-}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPushManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPushManager.javadeleted file mode 100644index 4fd80760e0..0000000000--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultAutoPushManager.java+++ /dev/null@@ -1,90 +0,0 @@-package com.pmease.gitop.core.manager.impl;--import java.util.HashSet;-import java.util.Set;-import java.util.concurrent.Callable;-import java.util.concurrent.Executor;--import javax.inject.Inject;-import javax.inject.Singleton;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;--import com.google.common.eventbus.Subscribe;-import com.pmease.commons.git.Commit;-import com.pmease.commons.hibernate.Sessional;-import com.pmease.commons.hibernate.UnitOfWork;-import com.pmease.commons.hibernate.dao.AbstractGenericDao;-import com.pmease.commons.hibernate.dao.GeneralDao;-import com.pmease.commons.util.ExceptionUtils;-import com.pmease.gitop.core.event.BranchRefUpdateEvent;-import com.pmease.gitop.core.manager.AutoPushManager;-import com.pmease.gitop.core.manager.PullRequestManager;-import com.pmease.gitop.model.AutoPush;-import com.pmease.gitop.model.Branch;-import com.pmease.gitop.model.PullRequest;--@Singleton-public class DefaultAutoPushManager extends AbstractGenericDao<AutoPush>- implements AutoPushManager {-- private static final Logger logger = LoggerFactory.getLogger(DefaultAutoPushManager.class);-- private final PullRequestManager pullRequestManager;-- private final UnitOfWork unitOfWork;-- private final Executor executor;-- @Inject- public DefaultAutoPushManager(GeneralDao generalDao, PullRequestManager pullRequestManager,- UnitOfWork unitOfWork, Executor executor) {- super(generalDao);- this.pullRequestManager = pullRequestManager;- this.unitOfWork = unitOfWork;- this.executor = executor;- }-- @Sessional- @Subscribe- public void pushUpon(BranchRefUpdateEvent event) {- Set<Branch> branchesWithOpenRequests = new HashSet<>();- for (PullRequest request: event.getBranch().getOutgoingRequests()) {- if (request.isOpen()) {- branchesWithOpenRequests.add(request.getTarget());- }- }- for (final AutoPush autoPush: event.getBranch().getAutoPushTargets()) {- if (!branchesWithOpenRequests.contains(autoPush.getTarget())) {- executor.execute(new Runnable() {-- @Override- public void run() {- try {- unitOfWork.call(new Callable<Void>() {-- @Override- public Void call() throws Exception {- AutoPush reloaded = load(autoPush.getId());- Branch source = reloaded.getSource();- Commit commit = source.getProject().code().showRevision(source.getHeadRef());- PullRequest request = pullRequestManager.create(- commit.getSubject(), reloaded.getTarget(), source, true);- if (request != null)- pullRequestManager.refresh(request);- return null;- }-- });- } catch (Exception e) {- logger.error("Error performing auto-push.", e);- throw ExceptionUtils.unchecked(e);- }- }-- });- }- }- }-}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultBranchManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultBranchManager.javaindex 794f5cee62..312b72bb00 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultBranchManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultBranchManager.java@@ -1,5 +1,8 @@package com.pmease.gitop.core.manager.impl;+import java.util.Collection;+import java.util.Iterator;+import javax.inject.Inject;import javax.inject.Singleton;import javax.transaction.Status;@@ -45,16 +48,25 @@ public class DefaultBranchManager extends AbstractGenericDao<Branch> implements@Overridepublic void delete(Branch branch) {deleteRefs(branch);++ for (PullRequest request: branch.getIngoingRequests()) {+ request.setTarget(null);+ if (request.isOpen())+ pullRequestManager.decline(request);+ else+ pullRequestManager.save(request);+ }++ for (PullRequest request: branch.getOutgoingRequests()) {+ request.setSource(null);+ pullRequestManager.save(request);+ }super.delete(branch);}@Sessional@Overridepublic void deleteRefs(Branch branch) {- for (PullRequest request: branch.getIngoingRequests())- pullRequestManager.deleteRefs(request);- for (PullRequest request: branch.getOutgoingRequests())- pullRequestManager.deleteRefs(request);branch.getProject().code().deleteBranch(branch.getName());}@@ -100,5 +112,13 @@ public class DefaultBranchManager extends AbstractGenericDao<Branch> implements});}++ @Override+ public void trim(Collection<Long> branchIds) {+ for (Iterator<Long> it = branchIds.iterator(); it.hasNext();) {+ if (get(it.next()) == null)+ it.remove();+ }+ }}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultPullRequestManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultPullRequestManager.javaindex cb039e32c1..1b0cd36105 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultPullRequestManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultPullRequestManager.java@@ -3,7 +3,6 @@ package com.pmease.gitop.core.manager.impl;import java.io.File;import java.util.List;import java.util.concurrent.Callable;-import java.util.concurrent.Executor;import javax.inject.Inject;import javax.inject.Singleton;@@ -11,8 +10,6 @@ import javax.inject.Singleton;import org.hibernate.criterion.Criterion;import org.hibernate.criterion.Order;import org.hibernate.criterion.Restrictions;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;import com.google.common.base.Preconditions;import com.google.common.eventbus.EventBus;@@ -21,10 +18,8 @@ import com.pmease.commons.git.Git;import com.pmease.commons.hibernate.EntityEvent;import com.pmease.commons.hibernate.Sessional;import com.pmease.commons.hibernate.Transactional;-import com.pmease.commons.hibernate.UnitOfWork;import com.pmease.commons.hibernate.dao.AbstractGenericDao;import com.pmease.commons.hibernate.dao.GeneralDao;-import com.pmease.commons.util.ExceptionUtils;import com.pmease.commons.util.FileUtils;import com.pmease.commons.util.LockUtils;import com.pmease.gitop.core.event.BranchRefUpdateEvent;@@ -39,36 +34,27 @@ import com.pmease.gitop.model.PullRequest.Status;import com.pmease.gitop.model.PullRequestUpdate;import com.pmease.gitop.model.Vote;import com.pmease.gitop.model.VoteInvitation;-import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Pending;+import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Rejected;@Singletonpublic class DefaultPullRequestManager extends AbstractGenericDao<PullRequest> implementsPullRequestManager {- private static final Logger logger = LoggerFactory.getLogger(DefaultPullRequestManager.class);-private final VoteInvitationManager voteInvitationManager;private final PullRequestUpdateManager pullRequestUpdateManager;- private final UnitOfWork unitOfWork;-private final EventBus eventBus;- private final Executor executor;-@Injectpublic DefaultPullRequestManager(GeneralDao generalDao, VoteInvitationManager voteInvitationManager,- PullRequestUpdateManager pullRequestUpdateManager, UnitOfWork unitOfWork, EventBus eventBus,- Executor executor) {+ PullRequestUpdateManager pullRequestUpdateManager, EventBus eventBus) {super(generalDao);this.voteInvitationManager = voteInvitationManager;this.pullRequestUpdateManager = pullRequestUpdateManager;- this.unitOfWork = unitOfWork;this.eventBus = eventBus;- this.executor = executor;eventBus.register(this);}@@ -268,7 +254,7 @@ public class DefaultPullRequestManager extends AbstractGenericDao<PullRequest> i});}-+@Sessional@Subscribepublic void refreshUpon(EntityEvent entityEvent) {@@ -292,31 +278,9 @@ public class DefaultPullRequestManager extends AbstractGenericDao<PullRequest> i@Sessional@Subscribepublic void refreshUpon(BranchRefUpdateEvent event) {- for (final PullRequest request: event.getBranch().getIngoingRequests()) {- if (request.isOpen()) {- executor.execute(new Runnable() {-- @Override- public void run() {- try {- unitOfWork.call(new Callable<Void>() {-- @Override- public Void call() throws Exception {- // Reload request to avoid Hibernate LazyInitializationException- refresh(load(request.getId()));- return null;- }-- });- } catch (Exception e) {- logger.error("Error refreshing pull request.", e);- throw ExceptionUtils.unchecked(e);- }- }-- });- }+ for (PullRequest request: event.getBranch().getIngoingRequests()) {+ if (request.isOpen())+ refresh(load(request.getId()));}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultTeamManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultTeamManager.javaindex d80f183a23..a53e0fa044 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultTeamManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultTeamManager.java@@ -1,5 +1,8 @@package com.pmease.gitop.core.manager.impl;+import java.util.Collection;+import java.util.Iterator;+import javax.inject.Inject;import javax.inject.Singleton;@@ -22,12 +25,6 @@ import com.pmease.gitop.model.permission.operation.GeneralOperation;@Singletonpublic class DefaultTeamManager extends AbstractGenericDao<Team> implements TeamManager {-// private volatile Long anonymousId;-//-// private volatile Long ownersId;-//-// private volatile Long loggedInId;-private static class BuiltInTeam {final Long anonymousId;final Long ownersId;@@ -42,7 +39,6 @@ public class DefaultTeamManager extends AbstractGenericDao<Team> implements Teamprivate final LoadingCache<Long, BuiltInTeam> builtInTeamsCache;-@Injectpublic DefaultTeamManager(GeneralDao generalDao, final UserManager userManager) {super(generalDao);@@ -72,43 +68,16 @@ public class DefaultTeamManager extends AbstractGenericDao<Team> implements Team@Overridepublic Team getAnonymous(User user) {return load(builtInTeamsCache.getUnchecked(user.getId()).anonymousId);-// Team anonymous;-// if (anonymousId == null) {-// anonymous = findBy(user, Team.ANONYMOUS);-// Preconditions.checkNotNull(anonymous);-// anonymousId = anonymous.getId();-// } else {-// anonymous = load(anonymousId);-// }-// return anonymous;}@Overridepublic Team getLoggedIn(User user) {return load(builtInTeamsCache.getUnchecked(user.getId()).loggedInId);-// Team loggedIn;-// if (loggedInId == null) {-// loggedIn = findBy(user, Team.LOGGEDIN);-// Preconditions.checkNotNull(loggedIn);-// loggedInId = loggedIn.getId();-// } else {-// loggedIn = load(loggedInId);-// }-// return loggedIn;}@Overridepublic Team getOwners(User user) {return load(builtInTeamsCache.getUnchecked(user.getId()).ownersId);-// Team owners;-// if (ownersId == null) {-// owners = findBy(user, Team.OWNERS);-// Preconditions.checkNotNull(owners);-// ownersId = owners.getId();-// } else {-// owners = load(ownersId);-// }-// return owners;}@Override@@ -126,4 +95,12 @@ public class DefaultTeamManager extends AbstractGenericDao<Team> implements TeamgetLoggedIn(team.getOwner()).getAuthorizedOperation());}}++ @Override+ public void trim(Collection<Long> teamIds) {+ for (Iterator<Long> it = teamIds.iterator(); it.hasNext();) {+ if (get(it.next()) == null)+ it.remove();+ }+ }}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultUserManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultUserManager.javaindex c0a8d9278b..700f664222 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultUserManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultUserManager.java@@ -1,5 +1,8 @@package com.pmease.gitop.core.manager.impl;+import java.util.Collection;+import java.util.Iterator;+import javax.inject.Inject;import javax.inject.Singleton;@@ -12,10 +15,14 @@ import com.pmease.commons.hibernate.Sessional;import com.pmease.commons.hibernate.Transactional;import com.pmease.commons.hibernate.dao.AbstractGenericDao;import com.pmease.commons.hibernate.dao.GeneralDao;+import com.pmease.gitop.core.manager.BranchManager;import com.pmease.gitop.core.manager.MembershipManager;+import com.pmease.gitop.core.manager.PullRequestManager;import com.pmease.gitop.core.manager.TeamManager;import com.pmease.gitop.core.manager.UserManager;+import com.pmease.gitop.model.Branch;import com.pmease.gitop.model.Membership;+import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.Team;import com.pmease.gitop.model.User;import com.pmease.gitop.model.permission.operation.GeneralOperation;@@ -26,15 +33,23 @@ public class DefaultUserManager extends AbstractGenericDao<User> implements Userprivate volatile Long rootId;private final TeamManager teamManager;+private final MembershipManager membershipManager;+ private final PullRequestManager pullRequestManager;++ private final BranchManager branchManager;+@Injectpublic DefaultUserManager(GeneralDao generalDao, TeamManager teamManager,- MembershipManager membershipManager) {+ MembershipManager membershipManager, PullRequestManager pullRequestManager,+ BranchManager branchManager) {super(generalDao);this.teamManager = teamManager;this.membershipManager = membershipManager;+ this.pullRequestManager = pullRequestManager;+ this.branchManager = branchManager;}@Transactional@@ -84,7 +99,23 @@ public class DefaultUserManager extends AbstractGenericDao<User> implements Userreturn root;}- @Sessional+ @Transactional+ @Override+ public void delete(User user) {+ for (PullRequest request: user.getRequests()) {+ request.setSubmitter(null);+ pullRequestManager.save(request);+ }++ for (Branch branch: user.getBranches()) {+ branch.setCreator(null);+ branchManager.save(branch);+ }++ super.delete(user);+ }++ @Sessional@Overridepublic User findByName(String userName) {return find(new Criterion[] {Restrictions.eq("name", userName)});@@ -106,4 +137,12 @@ public class DefaultUserManager extends AbstractGenericDao<User> implements User}}+ @Override+ public void trim(Collection<Long> userIds) {+ for (Iterator<Long> it = userIds.iterator(); it.hasNext();) {+ if (get(it.next()) == null)+ it.remove();+ }+ }+}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultVoteInvitationManager.java b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultVoteInvitationManager.javaindex a9a17fe146..349db14d7f 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultVoteInvitationManager.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/manager/impl/DefaultVoteInvitationManager.java@@ -42,7 +42,8 @@ public class DefaultVoteInvitationManager extends AbstractGenericDao<VoteInvitatCollection<User> copyOfCandidates = new HashSet<User>(candidates);// submitter is not allowed to vote for this request- copyOfCandidates.remove(request.getSubmitter());+ if (request.getSubmitter() != null)+ copyOfCandidates.remove(request.getSubmitter());/** users already voted since base update should be excluded fromdiff --git a/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/DirectionProtectionTest.java b/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/DirectionProtectionTest.javaindex f7a2c6029c..1feaa30cc9 100644--- a/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/DirectionProtectionTest.java+++ b/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/DirectionProtectionTest.java@@ -13,7 +13,8 @@ import com.pmease.commons.git.AbstractGitTest;import com.pmease.commons.git.Git;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.util.FileUtils;-import com.pmease.gitop.core.gatekeeper.DirectoryProtection.Entry;+import com.pmease.gitop.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByIds;+import com.pmease.gitop.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;import com.pmease.gitop.core.manager.BranchManager;import com.pmease.gitop.core.manager.TeamManager;import com.pmease.gitop.model.Branch;@@ -60,11 +61,16 @@ public class DirectionProtectionTest extends AbstractGitTest {@Testpublic void testCheckFile() {- DirectoryProtection directoryProtection = new DirectoryProtection();- directoryProtection.setBranchIds(Lists.newArrayList(1L));- Entry entry = directoryProtection.getEntries().get(0);- entry.setDirectory("src");- entry.setTeamId(1L);+ DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();+ SpecifyTargetBranchesByIds branchSelection = new SpecifyTargetBranchesByIds();+ branchSelection.setBranchIds(Lists.newArrayList(1L));+ pathProtection.setBranchSelection(branchSelection);++ SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();+ pathSelection.setDirectories(Lists.newArrayList("src"));+ pathProtection.setPathSelection(pathSelection);++ pathProtection.setTeamIds(Lists.newArrayList(1L));Team team = new Team();team.setId(1L);@@ -83,10 +89,10 @@ public class DirectionProtectionTest extends AbstractGitTest {branch1.setId(1L);Branch branch2 = new Branch();branch2.setId(2L);- assertTrue(directoryProtection.checkFile(user1, branch1, "src/test.java").isAccepted());- assertTrue(directoryProtection.checkFile(user1, branch1, "doc/test.pdf").isAccepted());- assertTrue(directoryProtection.checkFile(user2, branch1, "src/test.java").isPending());- assertTrue(directoryProtection.checkFile(user2, branch2, "src/test.java").isAccepted());+ assertTrue(pathProtection.checkFile(user1, branch1, "src/test.java").isAccepted());+ assertTrue(pathProtection.checkFile(user1, branch1, "doc/test.pdf").isAccepted());+ assertTrue(pathProtection.checkFile(user2, branch1, "src/test.java").isPending());+ assertTrue(pathProtection.checkFile(user2, branch2, "src/test.java").isAccepted());}@SuppressWarnings("serial")@@ -95,12 +101,17 @@ public class DirectionProtectionTest extends AbstractGitTest {File tempDir = FileUtils.createTempDir();try {- DirectoryProtection directoryProtection = new DirectoryProtection();- directoryProtection.setBranchIds(Lists.newArrayList(1L));- Entry entry = directoryProtection.getEntries().get(0);- entry.setDirectory("src");- entry.setTeamId(1L);+ DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();+ SpecifyTargetBranchesByIds branchSelection = new SpecifyTargetBranchesByIds();+ branchSelection.setBranchIds(Lists.newArrayList(1L));+ pathProtection.setBranchSelection(branchSelection);+ SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();+ pathSelection.setDirectories(Lists.newArrayList("src"));+ pathProtection.setPathSelection(pathSelection);++ pathProtection.setTeamIds(Lists.newArrayList(1L));+final Git git = new Git(tempDir);git.init(false);@@ -132,8 +143,8 @@ public class DirectionProtectionTest extends AbstractGitTest {git.add("src/file2");git.commit("add src/file2", false, false);- assertTrue(directoryProtection.checkCommit(user1, master, git.parseRevision("branch1", true)).isAccepted());- assertTrue(directoryProtection.checkCommit(user2, master, git.parseRevision("branch1", true)).isPending());+ assertTrue(pathProtection.checkCommit(user1, master, git.parseRevision("branch1", true)).isAccepted());+ assertTrue(pathProtection.checkCommit(user2, master, git.parseRevision("branch1", true)).isPending());git.checkout("master", "branch2");@@ -141,8 +152,8 @@ public class DirectionProtectionTest extends AbstractGitTest {git.add("docs/file2");git.commit("add docs/file2", false, false);- assertTrue(directoryProtection.checkCommit(user1, master, git.parseRevision("branch2", true)).isAccepted());- assertTrue(directoryProtection.checkCommit(user2, master, git.parseRevision("branch2", true)).isAccepted());+ assertTrue(pathProtection.checkCommit(user1, master, git.parseRevision("branch2", true)).isAccepted());+ assertTrue(pathProtection.checkCommit(user2, master, git.parseRevision("branch2", true)).isAccepted());} finally {FileUtils.deleteDir(tempDir);;}diff --git a/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java b/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.javaindex c78159d561..f3b206003c 100644--- a/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java+++ b/gitop.core/src/test/java/com/pmease/gitop/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeamTest.java@@ -137,10 +137,10 @@ public class IfApprovedByMajoritiesOfSpecifiedTeamTest extends AbstractGitTest {}});- request.getSource().getProject().setId(2L);- request.getSource().getProject().setOwner(new User());- request.getSource().getProject().getOwner().setId(2L);- request.getSource().getProject().getOwner().setName("user2");++ request.setSubmitter(new User());+ request.getSubmitter().setId(2L);+ request.getSubmitter().setName("user2");PullRequestUpdate update = new PullRequestUpdate();update.setHeadCommit(git.parseRevision("dev", true));diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/AutoPull.java b/gitop.model/src/main/java/com/pmease/gitop/model/AutoPull.javadeleted file mode 100644index 442376ea5d..0000000000--- a/gitop.model/src/main/java/com/pmease/gitop/model/AutoPull.java+++ /dev/null@@ -1,58 +0,0 @@-package com.pmease.gitop.model;--import javax.persistence.Entity;-import javax.persistence.JoinColumn;-import javax.persistence.ManyToOne;-import javax.persistence.Table;-import javax.persistence.UniqueConstraint;--import com.google.common.base.Objects;-import com.pmease.commons.hibernate.AbstractEntity;--/**- * Auto-pull is set up by owner of target branch project to sync target branch- * head with source branch whenever there is new commit in source branch.- * Unlike git pull command, it will override target branch head even if source- * branch is not fast-forward of target branch.- *- */-@Entity-@Table(uniqueConstraints={- @UniqueConstraint(columnNames={"source", "target"})-})-@SuppressWarnings("serial")-public class AutoPull extends AbstractEntity {-- @ManyToOne- @JoinColumn(nullable=false)- private Branch source;-- @ManyToOne- @JoinColumn(nullable=false)- private Branch target;-- public Branch getSource() {- return source;- }-- public void setSource(Branch source) {- this.source = source;- }-- public Branch getTarget() {- return target;- }-- public void setTarget(Branch target) {- this.target = target;- }-- @Override- public String toString() {- return Objects.toStringHelper(this)- .add("source", getSource())- .add("target", getTarget())- .toString();- }--}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/AutoPush.java b/gitop.model/src/main/java/com/pmease/gitop/model/AutoPush.javadeleted file mode 100644index 9c2edfcd02..0000000000--- a/gitop.model/src/main/java/com/pmease/gitop/model/AutoPush.java+++ /dev/null@@ -1,56 +0,0 @@-package com.pmease.gitop.model;--import javax.persistence.Entity;-import javax.persistence.JoinColumn;-import javax.persistence.ManyToOne;-import javax.persistence.Table;-import javax.persistence.UniqueConstraint;--import com.google.common.base.Objects;-import com.pmease.commons.hibernate.AbstractEntity;--/**- * Auto-push is set up by owner of source branch project to push source branch- * changes to target branch in form of pull requests.- *- */-@Entity-@Table(uniqueConstraints={- @UniqueConstraint(columnNames={"source", "target"})-})-@SuppressWarnings("serial")-public class AutoPush extends AbstractEntity {-- @ManyToOne- @JoinColumn(nullable=false)- private Branch source;-- @ManyToOne- @JoinColumn(nullable=false)- private Branch target;-- public Branch getSource() {- return source;- }-- public void setSource(Branch source) {- this.source = source;- }-- public Branch getTarget() {- return target;- }-- public void setTarget(Branch target) {- this.target = target;- }-- @Override- public String toString() {- return Objects.toStringHelper(this)- .add("source", getSource())- .add("target", getTarget())- .toString();- }--}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/Branch.java b/gitop.model/src/main/java/com/pmease/gitop/model/Branch.javaindex 750bd8b33c..e38f67c16f 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/Branch.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/Branch.java@@ -3,7 +3,7 @@ package com.pmease.gitop.model;import java.util.ArrayList;import java.util.Collection;-import javax.persistence.CascadeType;+import javax.annotation.Nullable;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.JoinColumn;@@ -30,22 +30,13 @@ public class Branch extends AbstractEntity {@Column(nullable=false)private String name;- @OneToMany(mappedBy="target", cascade=CascadeType.REMOVE)- private Collection<AutoPull> autoPullSources = new ArrayList<AutoPull>();-- @OneToMany(mappedBy="source", cascade=CascadeType.REMOVE)- private Collection<AutoPull> autoPullTargets = new ArrayList<AutoPull>();-- @OneToMany(mappedBy="target", cascade=CascadeType.REMOVE)- private Collection<AutoPush> autoPushSources = new ArrayList<AutoPush>();-- @OneToMany(mappedBy="source", cascade=CascadeType.REMOVE)- private Collection<AutoPush> autoPushTargets = new ArrayList<AutoPush>();-- @OneToMany(mappedBy="target", cascade=CascadeType.REMOVE)+ @ManyToOne+ private User creator;++ @OneToMany(mappedBy="target")private Collection<PullRequest> ingoingRequests = new ArrayList<PullRequest>();- @OneToMany(mappedBy="source", cascade=CascadeType.REMOVE)+ @OneToMany(mappedBy="source")private Collection<PullRequest> outgoingRequests = new ArrayList<PullRequest>();private transient String headCommit;@@ -66,36 +57,19 @@ public class Branch extends AbstractEntity {this.name = name;}- public Collection<AutoPull> getAutoPullSources() {- return autoPullSources;- }-- public void setAutoPullSources(Collection<AutoPull> autoPullSources) {- this.autoPullSources = autoPullSources;- }-- public Collection<AutoPull> getAutoPullTargets() {- return autoPullTargets;- }-- public void setAutoPullTargets(Collection<AutoPull> autoPullTargets) {- this.autoPullTargets = autoPullTargets;- }-- public Collection<AutoPush> getAutoPushSources() {- return autoPushSources;- }-- public void setAutoPushSources(Collection<AutoPush> autoPushSources) {- this.autoPushSources = autoPushSources;- }-- public Collection<AutoPush> getAutoPushTargets() {- return autoPushTargets;+ /**+ * Get creator of the branch.+ *+ * @return+ * <tt>null</tt> if creator is unknown+ */+ @Nullable+ public User getCreator() {+ return creator;}- public void setAutoPushTargets(Collection<AutoPush> autoPushTargets) {- this.autoPushTargets = autoPushTargets;+ public void setCreator(@Nullable User creator) {+ this.creator = creator;}public Collection<PullRequest> getIngoingRequests() {diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/PullRequest.java b/gitop.model/src/main/java/com/pmease/gitop/model/PullRequest.javaindex 5e1977c3d7..c4a56d2aa6 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/PullRequest.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/PullRequest.java@@ -34,11 +34,12 @@ public class PullRequest extends AbstractEntity {private boolean autoMerge;@ManyToOne- @JoinColumn(nullable = false)+ private User submitter;++ @ManyToOneprivate Branch target;@ManyToOne- @JoinColumn(nullable = false)private Branch source;@Lob@@ -83,24 +84,55 @@ public class PullRequest extends AbstractEntity {public void setAutoMerge(boolean autoMerge) {this.autoMerge = autoMerge;}-++ /**+ * Get the user submitting the pull request.+ *+ * @return+ * the user submitting the pull request, or <tt>null</tt> if the user+ * submitting the request is removed.+ */+ @Nullablepublic User getSubmitter() {- return getSource().getProject().getOwner();+ return submitter;}+ public void setSubmitter(@Nullable User submitter) {+ this.submitter = submitter;+ }++ /**+ * Get target branch of this request.+ *+ * @return+ * target branch of this request, or <tt>null</tt> if target branch+ * is deleted. In case of target branch being deleted, the pull request+ * will also be closed+ */+ @Nullablepublic Branch getTarget() {return target;}- public void setTarget(Branch target) {+ public void setTarget(@Nullable Branch target) {this.target = target;}+ /**+ * Get source branch of this request.+ *+ * @return+ * source branch of this request, or <tt>null</tt> if source branch+ * is deleted. In case of source branch being deleted, the pull request+ * may still in opened state for review, but can not be updated with+ * new commits+ */+ @Nullablepublic Branch getSource() {return source;}- public void setSource(Branch source) {+ public void setSource(@Nullable Branch source) {this.source = source;}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/User.java b/gitop.model/src/main/java/com/pmease/gitop/model/User.javaindex 866c4d79b2..716cdf5d9d 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/User.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/User.java@@ -41,6 +41,12 @@ public class User extends AbstractUser implements ProtectedObject {@OneToMany(mappedBy="owner", cascade=CascadeType.REMOVE)private Collection<Team> teams = new ArrayList<Team>();+ @OneToMany(mappedBy="creator")+ private Collection<Branch> branches = new ArrayList<Branch>();++ @OneToMany(mappedBy="submitter")+ private Collection<PullRequest> requests = new ArrayList<PullRequest>();+@OneToMany(mappedBy="voter", cascade=CascadeType.REMOVE)private Collection<Vote> votes = new ArrayList<Vote>();@@ -122,6 +128,34 @@ public class User extends AbstractUser implements ProtectedObject {this.teams = teams;}+ /**+ * Get created branches.+ *+ * @return+ * collection of created branches+ */+ public Collection<Branch> getBranches() {+ return branches;+ }++ public void setBranches(Collection<Branch> branches) {+ this.branches = branches;+ }++ /**+ * Get submitted pull requests.+ *+ * @return+ * collection of submitted pull requests+ */+ public Collection<PullRequest> getRequests() {+ return requests;+ }++ public void setRequests(Collection<PullRequest> requests) {+ this.requests = requests;+ }+public Collection<Vote> getVotes() {return votes;}@@ -152,7 +186,7 @@ public class User extends AbstractUser implements ProtectedObject {}public Vote.Result checkVoteSince(PullRequestUpdate update) {- if (update.getRequest().getSubmitter().equals(this))+ if (this.equals(update.getRequest().getSubmitter()))return Vote.Result.ACCEPT;for (Vote vote: update.listVotesOnwards()) {diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.javaindex 1eb8275099..66bd2ebfef 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AbstractGateKeeper.java@@ -12,9 +12,10 @@ import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;-import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;+import com.pmease.gitop.model.gatekeeper.checkresult.Ignored;import com.pmease.gitop.model.gatekeeper.checkresult.Pending;+import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Rejected;import com.pmease.gitop.model.gatekeeper.voteeligibility.VoteEligibility;@@ -37,15 +38,15 @@ public abstract class AbstractGateKeeper implements GateKeeper {if (enabled)return doCheckRequest(request);else- return accepted("Gate keeper is disabled.");+ return ignored();}@Override- public CheckResult checkFile(User user, Branch branch, @Nullable String file) {+ public CheckResult checkFile(User user, Branch branch, String file) {if (isEnabled())return doCheckFile(user, branch, file);else- return accepted("Gate keeper is disabled");+ return ignored();}@Override@@ -53,11 +54,19 @@ public abstract class AbstractGateKeeper implements GateKeeper {if (isEnabled())return doCheckCommit(user, branch, commit);else- return accepted("Gate keeper is disabled");+ return ignored();}+ @Override+ public CheckResult checkRef(User user, Project project, String refName) {+ if (isEnabled())+ return doCheckRef(user, project, refName);+ else+ return ignored();+ }+/**- * Check the gate keeper against specified request without considering enable flag. This is+ * Check gate keeper against specified pull request without considering enable flag. This is* typically used to determine whether or not to accept a pull request.** @param request@@ -68,27 +77,24 @@ public abstract class AbstractGateKeeper implements GateKeeper {protected abstract CheckResult doCheckRequest(PullRequest request);/**- * Check the gate keeper against specified user, branch and file without considering enable flag.- * This is typically used to determine whether or not to accept a file modification or branch- * deletion (when file parameter is specified as <tt>null</tt>).+ * Check if specified user can modify specified file in specified branch, without considering enable flag.** @param user* user to be checked* @param branch* branch to be checked* @param file- * file to be checked, <tt>null</tt> means to check if the user can administer/delete the branch+ * file to be checked* @return* result of the check*/- protected abstract CheckResult doCheckFile(User user, Branch branch, @Nullable String file);-+ protected abstract CheckResult doCheckFile(User user, Branch branch, String file);+/**- * Check the gate keeper against specified user, branch and commit without considering enable flag.- * This is typically used to determine whether or not to accept a push operation.- *+ * Check if specified user can push specified commit to specified branch, without considering enable flag.+ ** @param user- * user to be checked+ * user to be checked* @param branch* branch to be checked* @param commit@@ -98,6 +104,21 @@ public abstract class AbstractGateKeeper implements GateKeeper {*/protected abstract CheckResult doCheckCommit(User user, Branch branch, String commit);+ /**+ * Check if specified user can create/delete specified reference in specified project,+ * without considering enable flag.+ *+ * @param user+ * user to be checked+ * @param project+ * project to be checked+ * @param refName+ * reference name to be checked+ * @return+ * result of the check+ */+ protected abstract CheckResult doCheckRef(User user, Project project, String refName);+@Overridepublic final Object trim(@Nullable Object context) {Preconditions.checkArgument(context instanceof Project);@@ -124,10 +145,14 @@ public abstract class AbstractGateKeeper implements GateKeeper {return new PendingAndBlock(reason, voteEligibility);}+ protected CheckResult ignored() {+ return new Ignored();+ }+protected CheckResult accepted(List<String> reasons) {return new Accepted(reasons);}-+protected CheckResult rejected(List<String> reasons) {return new Rejected(reasons);}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndGateKeeper.javaindex ee26d249ac..ba39afd0fe 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/AndGateKeeper.java@@ -7,8 +7,9 @@ import java.util.List;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.editable.annotation.TableLayout;import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;-import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;+import com.pmease.gitop.model.gatekeeper.checkresult.Pending;+import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Rejected;import com.pmease.gitop.model.gatekeeper.voteeligibility.VoteEligibility;@@ -35,7 +36,7 @@ public class AndGateKeeper extends AndOrGateKeeper {result.getReasons().addAll(pendingReasons);result.getVoteEligibilities().addAll(voteEligibilities);return result;- } else {+ } else if (result instanceof Pending) {pendingReasons.addAll(result.getReasons());voteEligibilities.addAll(result.getVoteEligibilities());}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/CompositeGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/CompositeGateKeeper.javaindex bd3a3cfcd9..580efe5356 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/CompositeGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/CompositeGateKeeper.java@@ -1,9 +1,8 @@package com.pmease.gitop.model.gatekeeper;-import javax.annotation.Nullable;-import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@@ -31,7 +30,7 @@ public abstract class CompositeGateKeeper extends AbstractGateKeeper {}@Override- protected CheckResult doCheckFile(final User user, final Branch branch, final @Nullable String file) {+ protected CheckResult doCheckFile(final User user, final Branch branch, final String file) {return aggregate(new Checker() {@Override@@ -54,4 +53,16 @@ public abstract class CompositeGateKeeper extends AbstractGateKeeper {});}+ @Override+ protected CheckResult doCheckRef(final User user, final Project project, final String refName) {+ return aggregate(new Checker() {++ @Override+ public CheckResult check(GateKeeper gateKeeper) {+ return gateKeeper.checkRef(user, project, refName);+ }++ });+ }+}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.javaindex 7ebaec2c4e..0cee60dd02 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/DefaultGateKeeper.java@@ -18,17 +18,22 @@ public class DefaultGateKeeper extends AbstractGateKeeper {@Overridepublic CheckResult doCheckRequest(PullRequest request) {- return accepted("Not defined.");+ return ignored();}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return accepted("Not defined.");+ return ignored();}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return accepted("Not defined.");+ return ignored();+ }++ @Override+ protected CheckResult doCheckRef(User user, Project project, String refName) {+ return ignored();}}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/GateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/GateKeeper.javaindex c0f3bab92e..2ce7d66235 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/GateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/GateKeeper.java@@ -2,11 +2,10 @@ package com.pmease.gitop.model.gatekeeper;import java.io.Serializable;-import javax.annotation.Nullable;-import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.trimmable.Trimmable;import com.pmease.gitop.model.Branch;+import com.pmease.gitop.model.Project;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.User;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@@ -26,25 +25,21 @@ public interface GateKeeper extends Trimmable, Serializable {CheckResult checkRequest(PullRequest request);/**- * Check the gate keeper against specified user, branch and file. This is typically used- * to determine whether or not to accept a file modification or branch deletion (when- * file parameter is specified as <tt>null</tt>).+ * Check if specified user can modify specified file in specified branch.** @param user* user to be checked* @param branch* branch to be checked* @param file- * file to be checked, <tt>null</tt> means to check if the user can- * administer/delete the branch+ * file to be checked* @return* result of the check.*/- CheckResult checkFile(User user, Branch branch, @Nullable String file);+ CheckResult checkFile(User user, Branch branch, String file);/**- * Check the gate keeper against specified user, branch and commit. This is typically used- * to determine whether or not to accept a push operation.+ * Check specified user can push specified commit to specified branch.** @param user* user to be checked@@ -56,6 +51,20 @@ public interface GateKeeper extends Trimmable, Serializable {* result of the check*/CheckResult checkCommit(User user, Branch branch, String commit);-++ /**+ * Check if specified user can push specified reference to specified project.+ *+ * @param user+ * user to be checked+ * @param project+ * project to be checked+ * @param refName+ * reference name to be checked+ * @return+ * result of the check+ */+ CheckResult checkRef(User user, Project project, String refName);+boolean isEnabled();}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/IfThenGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/IfThenGateKeeper.javaindex 7ad4658fc5..9fac9ea374 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/IfThenGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/IfThenGateKeeper.java@@ -6,8 +6,9 @@ import javax.validation.constraints.NotNull;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.editable.annotation.TableLayout;import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;-import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;+import com.pmease.gitop.model.gatekeeper.checkresult.Pending;+import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Rejected;@SuppressWarnings("serial")@@ -50,12 +51,14 @@ public class IfThenGateKeeper extends CompositeGateKeeper {return accepted(ifResult.getReasons());} else if (ifResult instanceof PendingAndBlock) {return ifResult;- } else {+ } else if (ifResult instanceof Pending) {CheckResult thenResult = checker.check(getThenGate());if (thenResult instanceof Accepted)return thenResult;elsereturn ifResult;+ } else {+ return ifResult;}}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/OrGateKeeper.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/OrGateKeeper.javaindex b3179c6589..0c08f50cd5 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/OrGateKeeper.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/OrGateKeeper.java@@ -7,8 +7,9 @@ import java.util.List;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.editable.annotation.TableLayout;import com.pmease.gitop.model.gatekeeper.checkresult.Accepted;-import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;+import com.pmease.gitop.model.gatekeeper.checkresult.Pending;+import com.pmease.gitop.model.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitop.model.gatekeeper.checkresult.Rejected;import com.pmease.gitop.model.gatekeeper.voteeligibility.VoteEligibility;@@ -34,7 +35,7 @@ public class OrGateKeeper extends AndOrGateKeeper {result.getReasons().addAll(pendingReasons);result.getVoteEligibilities().addAll(voteEligibilities);return result;- } else {+ } else if (result instanceof Pending) {pendingReasons.addAll(result.getReasons());voteEligibilities.addAll(result.getVoteEligibilities());}diff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/CheckResult.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/CheckResult.javaindex 7a98bc2136..4a9fde2f7e 100644--- a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/CheckResult.java+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/CheckResult.java@@ -96,4 +96,15 @@ public abstract class CheckResult implements Serializable {public boolean isPendingAndBlock() {return this instanceof PendingAndBlock;}++ /**+ * Whether or not this check result should be ignored.+ *+ * @return+ * <tt>true</tt> if this check result should be ignored+ */+ public boolean isIgnored() {+ return this instanceof Ignored;+ }+}\ No newline at end of filediff --git a/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/Ignored.java b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/Ignored.javanew file mode 100644index 0000000000..6470ce6775--- /dev/null+++ b/gitop.model/src/main/java/com/pmease/gitop/model/gatekeeper/checkresult/Ignored.java@@ -0,0 +1,23 @@+package com.pmease.gitop.model.gatekeeper.checkresult;+++/**+ * Represents an ignored result, for instance if some check is not applicable, or if+ * some user selected to ignore the vote.+ *+ * @author robin+ *+ */+@SuppressWarnings("serial")+public class Ignored extends CheckResult {++ public Ignored() {+ super("Ignored");+ }++ @Override+ public String toString() {+ return "Ignore";+ }++}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/directory/DirectoryChoiceEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/directory/DirectoryChoiceEditor.javaindex f25b936729..ebda7b5df8 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/editable/directory/DirectoryChoiceEditor.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/directory/DirectoryChoiceEditor.java@@ -1,5 +1,8 @@package com.pmease.gitop.web.editable.directory;+import java.util.ArrayList;+import java.util.List;+import org.apache.commons.lang3.StringEscapeUtils;import org.apache.wicket.Component;import org.apache.wicket.MarkupContainer;@@ -12,8 +15,10 @@ import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;+import com.google.common.collect.Lists;import com.pmease.commons.editable.PropertyEditContext;import com.pmease.commons.git.TreeNode;+import com.pmease.commons.util.StringUtils;import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;import com.pmease.gitop.core.Gitop;@@ -57,14 +62,28 @@ public class DirectoryChoiceEditor extends Panel {public void detach() {}+ @SuppressWarnings("unchecked")@Overridepublic String getObject() {- return (String) editContext.getPropertyValue();+ Object propertyValue = editContext.getPropertyValue();+ if (propertyValue == null)+ return null;+ else if (propertyValue instanceof String)+ return (String) propertyValue;+ else+ return StringUtils.join((List<String>)propertyValue, ", ");}@Overridepublic void setObject(String object) {- editContext.setPropertyValue(object);+ if (String.class.isAssignableFrom(editContext.getPropertyGetter().getReturnType())) {+ editContext.setPropertyValue(object);+ } else {+ if (object != null)+ editContext.setPropertyValue(Lists.newArrayList(StringUtils.splitAndTrim(object)));+ else+ editContext.setPropertyValue(new ArrayList<>());+ }}}));diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamEditSupport.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamEditSupport.javaindex b4332b84fe..dc908e98cb 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamEditSupport.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamEditSupport.java@@ -2,6 +2,7 @@ package com.pmease.gitop.web.editable.team;import java.io.Serializable;import java.lang.reflect.Method;+import java.util.List;import com.pmease.commons.editable.BeanEditContext;import com.pmease.commons.editable.EditSupport;@@ -21,7 +22,10 @@ public class TeamEditSupport implements EditSupport {public PropertyEditContext getPropertyEditContext(Serializable bean, String propertyName) {Method propertyGetter = BeanUtils.getGetter(JavassistUtils.unproxy(bean.getClass()), propertyName);if (propertyGetter.getAnnotation(TeamChoice.class) != null) {- return new TeamSingleChoiceEditContext(bean, propertyName);+ if (List.class.isAssignableFrom(propertyGetter.getReturnType()))+ return new TeamMultiChoiceEditContext(bean, propertyName);+ else+ return new TeamSingleChoiceEditContext(bean, propertyName);} else {return null;}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditContext.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditContext.javanew file mode 100644index 0000000000..aeb5ef88f6--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditContext.java@@ -0,0 +1,44 @@+package com.pmease.gitop.web.editable.team;++import java.io.Serializable;+import java.util.ArrayList;+import java.util.Collection;+import java.util.List;++import org.apache.wicket.markup.html.basic.Label;+import org.eclipse.jgit.util.StringUtils;++import com.pmease.commons.editable.PropertyEditContext;+import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.core.manager.TeamManager;++@SuppressWarnings("serial")+public class TeamMultiChoiceEditContext extends PropertyEditContext {++ public TeamMultiChoiceEditContext(Serializable bean, String propertyName) {+ super(bean, propertyName);+ }++ @Override+ public Object renderForEdit(Object renderParam) {+ return new TeamMultiChoiceEditor((String) renderParam, this);+ }++ @SuppressWarnings("unchecked")+ @Override+ public Object renderForView(Object renderParam) {+ Collection<Long> teamIds = (Collection<Long>) getPropertyValue();+ if (teamIds != null && !teamIds.isEmpty()) {+ TeamManager teamManager = Gitop.getInstance(TeamManager.class);+ List<String> teamNames = new ArrayList<>();+ for (Long teamId: teamIds) {+ teamNames.add(teamManager.load(teamId).getName());+ }+ return new Label((String) renderParam, StringUtils.join(teamNames, ", " ));+ } else {+ return new Label((String) renderParam, "<i>Not Defined</i>")+ .setEscapeModelStrings(false);+ }+ }++}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.html b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.htmlnew file mode 100644index 0000000000..5596a9ca8b--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.html@@ -0,0 +1,3 @@+<wicket:panel>+ <input wicket:id="chooser" type="hidden"></input>+</wicket:panel>\ No newline at end of filediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.javanew file mode 100644index 0000000000..8a70512282--- /dev/null+++ b/gitop.web/src/main/java/com/pmease/gitop/web/editable/team/TeamMultiChoiceEditor.java@@ -0,0 +1,88 @@+package com.pmease.gitop.web.editable.team;++import java.io.Serializable;+import java.util.ArrayList;+import java.util.Collection;+import java.util.List;++import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.hibernate.criterion.DetachedCriteria;+import org.hibernate.criterion.Restrictions;++import com.pmease.gitop.core.Gitop;+import com.pmease.gitop.core.manager.TeamManager;+import com.pmease.gitop.model.Team;+import com.pmease.gitop.web.component.choice.TeamChoiceProvider;+import com.pmease.gitop.web.component.choice.TeamMultiChoice;+import com.pmease.gitop.web.page.project.AbstractProjectPage;++@SuppressWarnings("serial")+public class TeamMultiChoiceEditor extends Panel {++ private final TeamMultiChoiceEditContext editContext;++ public TeamMultiChoiceEditor(String id, TeamMultiChoiceEditContext editContext) {+ super(id);+ this.editContext = editContext;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ IModel<Collection<Team>> model = new IModel<Collection<Team>>() {++ @Override+ public void detach() {+ }++ @SuppressWarnings("unchecked")+ @Override+ public Collection<Team> getObject() {+ List<Long> teamIds = (List<Long>) editContext.getPropertyValue();+ if (teamIds != null) {+ TeamManager teamManager = Gitop.getInstance(TeamManager.class);+ Collection<Team> teams = new ArrayList<>();+ for (Long teamId: teamIds)+ teams.add(teamManager.load(teamId));+ return teams;+ } else {+ return null;+ }+ }++ @Override+ public void setObject(Collection<Team> teams) {+ if (teams != null) {+ List<Long> teamIds = new ArrayList<>();+ for (Team team: teams)+ teamIds.add(team.getId());+ editContext.setPropertyValue((Serializable) teamIds);+ } else {+ editContext.setPropertyValue(null);+ }+ }++ };++ TeamChoiceProvider teamProvider = new TeamChoiceProvider(new LoadableDetachableModel<DetachedCriteria>() {++ @Override+ protected DetachedCriteria load() {+ DetachedCriteria criteria = DetachedCriteria.forClass(Team.class);+ AbstractProjectPage page = (AbstractProjectPage) getPage();+ criteria.add(Restrictions.eq("project", page.getProject()));+ return criteria;+ }++ });++ TeamMultiChoice chooser = new TeamMultiChoice("chooser", model, teamProvider);+ chooser.setConvertEmptyInputStringToNull(true);++ add(chooser);+ }++}