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:
Edwin Kempin
2017-11-20 11:13:30 +01:00
parent d7848539ca
commit 2369ea7b6e
5 changed files with 37 additions and 11 deletions

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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)) {