use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.
the class PutDescription method apply.
@Override
public Response<String> apply(GroupResource resource, DescriptionInput input) throws AuthException, NotInternalGroupException, ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
// Delete would set description to null.
input = new DescriptionInput();
}
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
String currentDescription = Strings.nullToEmpty(internalGroup.getDescription());
String newDescription = Strings.nullToEmpty(input.description);
if (!Objects.equals(currentDescription, newDescription)) {
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setDescription(newDescription).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}
return Strings.isNullOrEmpty(input.description) ? Response.none() : Response.ok(input.description);
}
use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.
the class AccountCreator method addGroupMember.
private void addGroupMember(AccountGroup.UUID groupUuid, Account.Id accountId) throws IOException, NoSuchGroupException, ConfigInvalidException {
GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.union(memberIds, ImmutableSet.of(accountId))).build();
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
}
use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.
the class GroupsOnInit method addGroupMemberInNoteDb.
private void addGroupMemberInNoteDb(Repository repository, AccountGroup.UUID groupUuid, Account account) throws IOException, ConfigInvalidException, NoSuchGroupException {
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, repository, groupUuid);
InternalGroup group = groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupUuid));
GroupDelta groupDelta = getMemberAdditionDelta(account);
AuditLogFormatter auditLogFormatter = getAuditLogFormatter(account);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
commit(repository, groupConfig, group.getCreatedOn());
}
use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.
the class CreateAccount method addGroupMember.
private void addGroupMember(AccountGroup.UUID groupUuid, Account.Id accountId) throws IOException, NoSuchGroupException, ConfigInvalidException {
GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.union(memberIds, ImmutableSet.of(accountId))).build();
groupsUpdate.get().updateGroup(groupUuid, groupDelta);
}
use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.
the class AbstractQueryGroupsTest method reindex.
// reindex permissions are tested by {@link GroupsIT#reindexPermissions}
@Test
public void reindex() throws Exception {
GroupInfo group1 = createGroupWithDescription(name("group"), "barX");
// update group in the database so that group index is stale
String newDescription = "barY";
AccountGroup.UUID groupUuid = AccountGroup.uuid(group1.id);
GroupDelta groupDelta = GroupDelta.builder().setDescription(newDescription).build();
groupsUpdateProvider.get().updateGroupInNoteDb(groupUuid, groupDelta);
assertQuery("description:" + group1.description, group1);
assertQuery("description:" + newDescription);
gApi.groups().id(group1.id).index();
assertQuery("description:" + group1.description);
assertQuery("description:" + newDescription, group1);
}
Aggregations