RefNames: Add a method to check whether a ref is used to store group data
All refs that are used to store group data in NoteDb are protected (group branches and refs/meta/group-names). Instead of checking for group refs in different places have a method for this so that the check needs to be implemented only once. Change-Id: I7bcc1421f698bdefb5ef05a9a666fac88e58e9d2 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -778,7 +778,7 @@ public class CommitValidators {
|
||||
}
|
||||
}
|
||||
|
||||
/** Rejects updates to group branches (refs/groups/* and refs/meta/group-names). */
|
||||
/** Rejects updates to group branches. */
|
||||
public static class GroupCommitValidator implements CommitValidationListener {
|
||||
private final AllUsersName allUsers;
|
||||
|
||||
@@ -789,8 +789,7 @@ public class CommitValidators {
|
||||
@Override
|
||||
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
|
||||
throws CommitValidationException {
|
||||
// Groups are stored inside 'refs/groups/' refs inside the 'All-Users' repository.
|
||||
// Group names are stored inside 'refs/meta/group-names' refs inside the 'All-Users' repository.
|
||||
// Groups are stored inside the 'All-Users' repository.
|
||||
if (!allUsers.equals(receiveEvent.project.getNameKey())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -801,8 +800,7 @@ public class CommitValidators {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (receiveEvent.command.getRefName().startsWith(RefNames.REFS_GROUPS)
|
||||
|| receiveEvent.command.getRefName().equals(RefNames.REFS_GROUPNAMES)) {
|
||||
if (RefNames.isGroupRef(receiveEvent.command.getRefName())) {
|
||||
throw new CommitValidationException("group update not allowed");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -318,11 +318,9 @@ public class MergeValidators {
|
||||
PatchSet.Id patchSetId,
|
||||
IdentifiedUser caller)
|
||||
throws MergeValidationException {
|
||||
// Groups are stored inside 'refs/groups/' refs inside the 'All-Users' repository.
|
||||
// Group names are stored inside 'refs/meta/group-names' inside the 'All-Users' repository.
|
||||
// Groups are stored inside the 'All-Users' repository.
|
||||
if (!allUsersName.equals(destProject.getNameKey())
|
||||
|| (!destBranch.get().startsWith(RefNames.REFS_GROUPS)
|
||||
&& !destBranch.get().equals(RefNames.REFS_GROUPNAMES))) {
|
||||
|| !RefNames.isGroupRef(destBranch.get())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,8 +149,7 @@ public class RefOperationValidators {
|
||||
}
|
||||
}
|
||||
|
||||
if (refEvent.command.getRefName().startsWith(RefNames.REFS_GROUPS)
|
||||
|| refEvent.command.getRefName().equals(RefNames.REFS_GROUPNAMES)) {
|
||||
if (RefNames.isGroupRef(refEvent.command.getRefName())) {
|
||||
if (refEvent.command.getType().equals(ReceiveCommand.Type.CREATE)) {
|
||||
throw new ValidationException("Not allowed to create group branch.");
|
||||
} else if (refEvent.command.getType().equals(ReceiveCommand.Type.DELETE)) {
|
||||
|
||||
Reference in New Issue
Block a user