use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ActionJson method toActionMap.
private Map<String, ActionInfo> toActionMap(ChangeData changeData, List<ActionVisitor> visitors, ChangeInfo changeInfo) {
CurrentUser user = userProvider.get();
Map<String, ActionInfo> out = new LinkedHashMap<>();
if (!user.isIdentifiedUser()) {
return out;
}
Iterable<UiAction.Description> descs = uiActions.from(changeViews, changeResourceFactory.create(changeData, user));
// resulting action map.
if (!changeData.change().isAbandoned()) {
UiAction.Description descr = new UiAction.Description();
PrivateInternals_UiActionDescription.setId(descr, "followup");
PrivateInternals_UiActionDescription.setMethod(descr, "POST");
descr.setTitle("Create follow-up change");
descr.setLabel("Follow-Up");
descs = Iterables.concat(descs, Collections.singleton(descr));
}
ACTION: for (UiAction.Description d : descs) {
ActionInfo actionInfo = new ActionInfo(d);
for (ActionVisitor visitor : visitors) {
if (!visitor.visit(d.getId(), actionInfo, changeInfo)) {
continue ACTION;
}
}
out.put(d.getId(), actionInfo);
}
return out;
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class EventBroker method fireEvent.
protected void fireEvent(Change change, ChangeEvent event) throws PermissionBackendException {
setInstanceIdWhenEmpty(event);
for (PluginSetEntryContext<UserScopedEventListener> c : listeners) {
CurrentUser user = c.call(UserScopedEventListener::getUser);
if (isVisibleTo(change, user)) {
c.run(l -> l.onEvent(event));
}
}
fireEventForUnrestrictedListeners(event);
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class SubmitWithStickyApprovalDiff method apply.
public String apply(ChangeNotes notes, CurrentUser currentUser) throws AuthException, IOException, PermissionBackendException, InvalidChangeOperationException {
PatchSet currentPatchset = notes.getCurrentPatchSet();
PatchSet.Id latestApprovedPatchsetId = getLatestApprovedPatchsetId(notes);
if (latestApprovedPatchsetId.get() == currentPatchset.id().get()) {
// If the latest approved patchset is the current patchset, no need to return anything.
return "";
}
StringBuilder diff = new StringBuilder(String.format("\n\n%d is the latest approved patch-set.\n", latestApprovedPatchsetId.get()));
Map<String, FileDiffOutput> modifiedFiles = listModifiedFiles(notes.getProjectName(), currentPatchset, notes.getPatchSets().get(latestApprovedPatchsetId));
// To make the message a bit more concise, we skip the magic files.
List<FileDiffOutput> modifiedFilesList = modifiedFiles.values().stream().filter(p -> !Patch.isMagic(p.newPath().orElse(""))).collect(Collectors.toList());
if (modifiedFilesList.isEmpty()) {
diff.append("No files were changed between the latest approved patch-set and the submitted one.\n");
return diff.toString();
}
diff.append("The change was submitted with unreviewed changes in the following files:\n\n");
TemporaryBuffer.Heap buffer = new TemporaryBuffer.Heap(Math.min(HEAP_EST_SIZE, DEFAULT_POST_SUBMIT_SIZE_LIMIT), DEFAULT_POST_SUBMIT_SIZE_LIMIT);
try (Repository repository = repositoryManager.openRepository(notes.getProjectName());
DiffFormatter formatter = new DiffFormatter(buffer)) {
formatter.setRepository(repository);
formatter.setDetectRenames(true);
boolean isDiffTooLarge = false;
List<String> formatterResult = null;
try {
formatter.format(modifiedFilesList.get(0).oldCommitId(), modifiedFilesList.get(0).newCommitId());
// This returns the diff for all the files.
formatterResult = Arrays.stream(RawParseUtils.decode(buffer.toByteArray()).split("\n")).collect(Collectors.toList());
} catch (IOException e) {
if (JGitText.get().inMemoryBufferLimitExceeded.equals(e.getMessage())) {
isDiffTooLarge = true;
} else {
throw e;
}
}
if (formatterResult != null) {
int addedBytes = formatterResult.stream().mapToInt(String::length).sum();
if (!CommentCumulativeSizeValidator.isEnoughSpace(notes, addedBytes, maxCumulativeSize)) {
isDiffTooLarge = true;
}
}
for (FileDiffOutput fileDiff : modifiedFilesList) {
diff.append(getDiffForFile(notes, currentPatchset.id(), latestApprovedPatchsetId, fileDiff, currentUser, formatterResult, isDiffTooLarge));
}
}
return diff.toString();
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class PostReview method batchReviewerEvents.
private void batchReviewerEvents(CurrentUser user, ChangeData cd, PatchSet patchSet, List<ReviewerModification> reviewerModifications, Instant when) {
List<AccountState> newlyAddedReviewers = new ArrayList<>();
// There are no events for CCs and reviewers added/deleted by email.
for (ReviewerModification modification : reviewerModifications) {
Result reviewerAdditionResult = modification.op.getResult();
if (modification.state() == ReviewerState.REVIEWER) {
newlyAddedReviewers.addAll(reviewerAdditionResult.addedReviewers().stream().map(psa -> psa.accountId()).map(accountId -> accountCache.get(accountId)).flatMap(Streams::stream).collect(toList()));
} else if (modification.state() == ReviewerState.REMOVED) {
// There is no batch event for reviewer removals, hence fire the event for each
// modification that deleted a reviewer immediately.
modification.op.sendEvent();
}
}
// Fire a batch event for all newly added reviewers.
reviewerAdded.fire(cd, patchSet, newlyAddedReviewers, user.asIdentifiedUser().state(), when);
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class QueryChanges method skipVisibility.
@Option(name = "--skip-visibility", usage = "Skip visibility check, only for administrators")
public void skipVisibility(boolean on) throws AuthException, PermissionBackendException {
if (on) {
CurrentUser user = userProvider.get();
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
}
skipVisibility = on;
}
Aggregations