Search in sources :

Example 1 with GroupConfig

use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.

the class Schema_184 method upgrade.

@Override
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
    try (Repository allUsersRepo = args.repoManager.openRepository(args.allUsers)) {
        AccountGroup.NameKey newName = AccountGroup.nameKey(ServiceUserClassifier.SERVICE_USERS);
        Optional<GroupReference> nonInteractiveUsers = GroupNameNotes.loadAllGroups(allUsersRepo).stream().filter(g -> g.getName().equals("Non-Interactive Users")).findAny();
        if (!nonInteractiveUsers.isPresent()) {
            return;
        }
        GroupNameNotes newNameNotes = GroupNameNotes.forRename(args.allUsers, allUsersRepo, nonInteractiveUsers.get().getUUID(), AccountGroup.nameKey(nonInteractiveUsers.get().getName()), newName);
        GroupConfig groupConfig = GroupConfig.loadForGroup(args.allUsers, allUsersRepo, nonInteractiveUsers.get().getUUID());
        groupConfig.setGroupDelta(GroupDelta.builder().setName(newName).build(), AuditLogFormatter.createPartiallyWorkingFallBack());
        commit(args.allUsers, args.serverUser, allUsersRepo, groupConfig, newNameNotes);
        index(args.groupIndexCollection, groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Created group wasn't automatically loaded")));
    }
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) AllUsersName(com.google.gerrit.server.config.AllUsersName) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter) GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) InternalGroup(com.google.gerrit.entities.InternalGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupIndexCollection(com.google.gerrit.server.index.group.GroupIndexCollection) IOException(java.io.IOException) GroupReference(com.google.gerrit.entities.GroupReference) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Nullable(com.google.gerrit.common.Nullable) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) Optional(java.util.Optional) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) RefUpdateUtil(com.google.gerrit.git.RefUpdateUtil) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Repository(org.eclipse.jgit.lib.Repository) GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupReference(com.google.gerrit.entities.GroupReference)

Example 2 with GroupConfig

use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.

the class SchemaCreatorImpl method createGroupInNoteDb.

private InternalGroup createGroupInNoteDb(Repository allUsersRepo, InternalGroupCreation groupCreation, GroupDelta groupDelta) throws ConfigInvalidException, IOException, DuplicateKeyException {
    // This method is only executed on a new server which doesn't have any accounts or groups.
    AuditLogFormatter auditLogFormatter = AuditLogFormatter.createBackedBy(ImmutableSet.of(), ImmutableSet.of(), serverId);
    GroupConfig groupConfig = GroupConfig.createForNewGroup(allUsersName, allUsersRepo, groupCreation);
    groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
    AccountGroup.NameKey groupName = groupDelta.getName().orElseGet(groupCreation::getNameKey);
    GroupNameNotes groupNameNotes = GroupNameNotes.forNewGroup(allUsersName, allUsersRepo, groupCreation.getGroupUUID(), groupName);
    commit(allUsersRepo, groupConfig, groupNameNotes);
    return groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Created group wasn't automatically loaded"));
}
Also used : GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) AccountGroup(com.google.gerrit.entities.AccountGroup) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter)

Example 3 with GroupConfig

use of com.google.gerrit.server.group.db.GroupConfig 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());
}
Also used : GroupConfig(com.google.gerrit.server.group.db.GroupConfig) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) AuditLogFormatter(com.google.gerrit.server.group.db.AuditLogFormatter) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 4 with GroupConfig

use of com.google.gerrit.server.group.db.GroupConfig in project gerrit by GerritCodeReview.

the class GroupsOnInit method getExistingGroup.

/**
 * Returns the {@code AccountGroup} for the specified {@code GroupReference}.
 *
 * @param groupReference the {@code GroupReference} of the group
 * @return the {@code InternalGroup} represented by the {@code GroupReference}
 * @throws IOException if an error occurs while reading from NoteDb
 * @throws ConfigInvalidException if the data in NoteDb is in an incorrect format
 * @throws NoSuchGroupException if a group with such a name doesn't exist
 */
public InternalGroup getExistingGroup(GroupReference groupReference) throws NoSuchGroupException, IOException, ConfigInvalidException {
    File allUsersRepoPath = getPathToAllUsersRepository();
    if (allUsersRepoPath != null) {
        try (Repository allUsersRepo = new FileRepository(allUsersRepoPath)) {
            AccountGroup.UUID groupUuid = groupReference.getUUID();
            GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, allUsersRepo, groupUuid);
            return groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupReference.getUUID()));
        }
    }
    throw new NoSuchGroupException(groupReference.getUUID());
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) File(java.io.File) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Aggregations

GroupConfig (com.google.gerrit.server.group.db.GroupConfig)4 AccountGroup (com.google.gerrit.entities.AccountGroup)3 AuditLogFormatter (com.google.gerrit.server.group.db.AuditLogFormatter)3 InternalGroup (com.google.gerrit.entities.InternalGroup)2 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)2 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)2 GroupNameNotes (com.google.gerrit.server.group.db.GroupNameNotes)2 Repository (org.eclipse.jgit.lib.Repository)2 Nullable (com.google.gerrit.common.Nullable)1 GroupReference (com.google.gerrit.entities.GroupReference)1 RefUpdateUtil (com.google.gerrit.git.RefUpdateUtil)1 ServiceUserClassifier (com.google.gerrit.server.account.ServiceUserClassifier)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)1 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)1 GroupIndex (com.google.gerrit.server.index.group.GroupIndex)1 GroupIndexCollection (com.google.gerrit.server.index.group.GroupIndexCollection)1 File (java.io.File)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1