@Override public Function.Context setAssignee(@Nullable UserDto user) { updater.assign(issue, user, changeContext); return this; }
@Override public boolean execute(Map<String, Object> properties, Context context) { checkArgument(properties.containsKey(VERIFIED_ASSIGNEE), "Assignee is missing from the execution parameters"); UserDto assignee = (UserDto) properties.get(VERIFIED_ASSIGNEE); return isAssigneeMemberOfIssueOrganization(assignee, properties, context) && issueFieldsSetter.assign(context.issue(), assignee, context.issueChangeContext()); }
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); } }
@Test public void unassign() { issue.setAssigneeUuid("user_uuid"); boolean updated = underTest.assign(issue, null, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isNull(); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isNull(); }
@Test public void assign() { UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik"); boolean updated = underTest.assign(issue, user, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isEqualTo(user.getUuid()); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isEqualTo(user.getName()); }
@Test public void change_assignee() { UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik"); issue.setAssigneeUuid("user_uuid"); boolean updated = underTest.assign(issue, user, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isEqualTo(user.getUuid()); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isEqualTo(user.getName()); }
@Test public void not_change_assignee() { UserDto user = newUserDto().setLogin("morgan").setName("Morgan"); issue.setAssigneeUuid(user.getUuid()); boolean updated = underTest.assign(issue, user, context); assertThat(updated).isFalse(); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void verify_notification_when_assignee_has_changed() { UserDto oldAssignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)) .setAssigneeUuid(oldAssignee.getUuid()) .toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); UserDto newAssignee = db.users().insertUser(); issueFieldsSetter.assign(issue, newAssignee, context); underTest.saveIssue(db.getSession(), issue, context, null); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("new.assignee")).isEqualTo(newAssignee.getName()); assertThat(issueChangeNotification.getFieldValue("old.assignee")).isNull(); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(newAssignee.getLogin()); }
@Override public Function.Context setAssignee(@Nullable UserDto user) { updater.assign(issue, user, changeContext); return this; }
@Override public boolean execute(Map<String, Object> properties, Context context) { checkArgument(properties.containsKey(VERIFIED_ASSIGNEE), "Assignee is missing from the execution parameters"); UserDto assignee = (UserDto) properties.get(VERIFIED_ASSIGNEE); return isAssigneeMemberOfIssueOrganization(assignee, properties, context) && issueFieldsSetter.assign(context.issue(), assignee, context.issueChangeContext()); }
private SearchResponseData assign(String issueKey, @Nullable String login) { try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); 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); } }