CommentData(DbSession dbSession, String commentKey) { this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, commentKey) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments"); }
ChangeLogResults(DbSession dbSession, String issueKey) { IssueDto issue = issueFinder.getByKey(dbSession, issueKey); if (isMember(dbSession, issue)) { this.changes = dbClient.issueChangeDao().selectChangelogByIssue(dbSession, issue.getKey()); List<String> userUuids = changes.stream().filter(change -> change.userUuid() != null).map(FieldDiffs::userUuid).collect(MoreCollectors.toList()); this.users = dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(MoreCollectors.uniqueIndex(UserDto::getUuid)); this.files = dbClient.componentDao().selectByUuids(dbSession, getFileUuids(changes)).stream().collect(MoreCollectors.uniqueIndex(ComponentDto::uuid, Function.identity())); } else { changes = ImmutableList.of(); users = ImmutableMap.of(); files = ImmutableMap.of(); } }
CommentData(DbSession dbSession, EditCommentRequest request) { this.request = request; this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, request.getComment()) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", request.getComment()))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments"); }
private SearchResponseData setTags(String issueKey, List<String> tags) { userSession.checkLoggedIn(); try (DbSession session = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid()); if (issueFieldsSetter.setTags(issue, tags, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, false); } return new SearchResponseData(issueDto); } }
private SearchResponseData setType(DbSession session, String issueKey, String severity) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid()); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid()); if (issueFieldsSetter.setManualSeverity(issue, severity, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true); } return new SearchResponseData(issueDto); } }
private SearchResponseData assign(String issueKey, @Nullable String login) { try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); checkArgument(issue.type() != RuleType.SECURITY_HOTSPOT,"It is not allowed to assign a security hotspot"); UserDto user = getUser(dbSession, login); if (user != null) { checkMembership(dbSession, issueDto, user); } IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid()); if (issueFieldsSetter.assign(issue, user, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, issue, context, null, false); } return new SearchResponseData(issueDto); } }
private SearchResponseData setType(DbSession session, String issueKey, RuleType ruleType) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); if (issue.isFromHotspot()) { throw new IllegalArgumentException("Changing type of a security hotspot is not permitted"); } userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid()); IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid()); if (issueFieldsSetter.setType(issue, ruleType, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true); } return new SearchResponseData(issueDto); }
@Override public void handle(Request request, Response response) { userSession.checkLoggedIn(); String issue = request.mandatoryParam(PARAM_ISSUE); try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issue); SearchResponseData preloadedSearchResponseData = doTransition(dbSession, issueDto, request.mandatoryParam(PARAM_TRANSITION)); responseWriter.write(issue, preloadedSearchResponseData, request, response); } }
@Test public void get_by_issue_key() { IssueDto issueDto = insertIssue(); String permission = USER; addProjectPermission(issueDto, permission); IssueDto result = underTest.getByKey(db.getSession(), issueDto.getKey()); assertThat(result).isNotNull(); assertThat(result.getKey()).isEqualTo(issueDto.getKey()); }
@Override public void handle(Request request, Response response) { userSession.checkLoggedIn(); AddCommentRequest wsRequest = toWsRequest(request); try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, wsRequest.getIssue()); IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid()); DefaultIssue defaultIssue = issueDto.toDefaultIssue(); issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context); SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, wsRequest.getText(), false); responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response); } }
@Test public void fail_when_not_enough_permission() { IssueDto issueDto = insertIssue(); addProjectPermission(issueDto, CODEVIEWER); expectedException.expect(ForbiddenException.class); underTest.getByKey(db.getSession(), issueDto.getKey()); }
@Test public void fail_when_issue_key_does_not_exist() { IssueDto issueDto = insertIssue(); addProjectPermission(issueDto, USER); expectedException.expect(NotFoundException.class); expectedException.expectMessage("Issue with key 'UNKNOWN' does not exist"); underTest.getByKey(db.getSession(), "UNKNOWN"); }
CommentData(DbSession dbSession, String commentKey) { this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, commentKey) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments"); }
ChangeLogResults(DbSession dbSession, String issueKey) { IssueDto dbIssue = issueFinder.getByKey(dbSession, issueKey); this.changes = dbClient.issueChangeDao().selectChangelogByIssue(dbSession, dbIssue.getKey()); List<String> userUuids = changes.stream().filter(change -> change.userUuid() != null).map(FieldDiffs::userUuid).collect(MoreCollectors.toList()); this.users = dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(MoreCollectors.uniqueIndex(UserDto::getUuid)); this.files = dbClient.componentDao().selectByUuids(dbSession, getFileUuids(changes)).stream().collect(MoreCollectors.uniqueIndex(ComponentDto::uuid, Function.identity())); }
CommentData(DbSession dbSession, EditCommentRequest request) { this.request = request; this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, request.getComment()) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", request.getComment()))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments"); }
private SearchResponseData setType(DbSession session, String issueKey, String severity) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid()); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid()); if (issueFieldsSetter.setManualSeverity(issue, severity, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true); } return new SearchResponseData(issueDto); } }
private SearchResponseData setTags(String issueKey, List<String> tags) { userSession.checkLoggedIn(); try (DbSession session = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid()); if (issueFieldsSetter.setTags(issue, tags, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, false); } return new SearchResponseData(issueDto); } }
private SearchResponseData setType(DbSession session, String issueKey, RuleType ruleType) { IssueDto issueDto = issueFinder.getByKey(session, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid()); IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid()); if (issueFieldsSetter.setType(issue, ruleType, context)) { return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true); } return new SearchResponseData(issueDto); }
@Override public void handle(Request request, Response response) { userSession.checkLoggedIn(); String issue = request.mandatoryParam(PARAM_ISSUE); try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issue); checkRequest(!issueDto.isExternal(), "Transition is not allowed on issues imported from external rule engines"); SearchResponseData preloadedSearchResponseData = doTransition(dbSession, issueDto, request.mandatoryParam(PARAM_TRANSITION)); responseWriter.write(issue, preloadedSearchResponseData, request, response); } }
@Override public void handle(Request request, Response response) { userSession.checkLoggedIn(); AddCommentRequest wsRequest = toWsRequest(request); try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, wsRequest.getIssue()); IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid()); DefaultIssue defaultIssue = issueDto.toDefaultIssue(); issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context); SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, wsRequest.getText(), false); responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response); } }