use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class ProjectWatch method add.
private boolean add(Watchers matching, Account.Id accountId, ProjectWatchKey key, Set<NotifyConfig.NotifyType> watchedTypes, NotifyConfig.NotifyType type) {
logger.atFine().log("Checking project watch %s of account %s", key, accountId);
IdentifiedUser user = args.identifiedUserFactory.create(accountId);
try {
if (filterMatch(user, key.filter())) {
// Otherwise, still return true to stop notifications for this user.
if (watchedTypes.contains(type)) {
matching.bcc.accounts.add(accountId);
}
logger.atFine().log("Added account %s as watcher", accountId);
return true;
}
logger.atFine().log("The filter did not match for account %s; skip notification", accountId);
} catch (QueryParseException e) {
// Ignore broken filter expressions.
logger.atInfo().log("Account %s has invalid filter in project watch %s: %s", accountId, key, e.getMessage());
}
return false;
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class CreateChange method execute.
/**
* Creates the changes in the given project. This is public for reuse in the project API.
*/
public Response<ChangeInfo> execute(BatchUpdate.Factory updateFactory, ChangeInput input, ProjectResource projectResource) throws IOException, RestApiException, UpdateException, PermissionBackendException, ConfigInvalidException {
if (!user.get().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
ProjectState projectState = projectResource.getProjectState();
projectState.checkStatePermitsWrite();
IdentifiedUser me = user.get().asIdentifiedUser();
checkAndSanitizeChangeInput(input, me);
Project.NameKey project = projectResource.getNameKey();
contributorAgreements.check(project, user.get());
checkRequiredPermissions(project, input.branch, input.author);
ChangeInfo newChange = createNewChange(input, me, projectState, updateFactory);
return Response.created(newChange);
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class PutName method apply.
public Response<String> apply(IdentifiedUser user, NameInput input) throws MethodNotAllowedException, ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
input = new NameInput();
}
Account.Id accountId = user.getAccountId();
if (realm.accountBelongsToRealm(externalIds.byAccount(accountId)) && !realm.allowsEdit(AccountFieldName.FULL_NAME)) {
throw new MethodNotAllowedException("realm does not allow editing name");
}
String newName = input.name;
AccountState accountState = accountsUpdateProvider.get().update("Set Full Name via API", accountId, u -> u.setFullName(newName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().fullName()) ? Response.none() : Response.ok(accountState.account().fullName());
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class PutDisplayName method apply.
@Override
public Response<String> apply(AccountResource rsrc, @Nullable DisplayNameInput input) throws AuthException, ResourceNotFoundException, IOException, PermissionBackendException, ConfigInvalidException {
IdentifiedUser user = rsrc.getUser();
if (!self.get().hasSameAccountId(user)) {
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
}
if (input == null) {
input = new DisplayNameInput();
}
String newDisplayName = input.displayName;
AccountState accountState = accountsUpdateProvider.get().update("Set Display Name via API", user.getAccountId(), u -> u.setDisplayName(newDisplayName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().displayName()) ? Response.none() : Response.ok(accountState.account().displayName());
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class StarredChanges method parse.
@Override
public AccountResource.StarredChange parse(AccountResource parent, IdString id) throws RestApiException, PermissionBackendException, IOException {
IdentifiedUser user = parent.getUser();
ChangeResource change = changes.parse(TopLevelResource.INSTANCE, id);
if (starredChangesUtil.getLabels(user.getAccountId(), change.getId()).contains(StarredChangesUtil.DEFAULT_LABEL)) {
return new AccountResource.StarredChange(user, change);
}
throw new ResourceNotFoundException(id);
}
Aggregations