if (issues != null && !issues.isEmpty()) {
return issues.get(0);
}
- throw new IllegalStateException("No issue");
+ throw new IllegalStateException("No issue found");
}
@Override
this.actions = actions;
}
+ public List<Action> listAvailableActions(String issueKey) {
+ IssueQueryResult queryResult = loadIssue(issueKey);
+ final DefaultIssue issue = (DefaultIssue) queryResult.first();
+ return listAvailableActions(issue);
+ }
+
public List<Action> listAvailableActions(final Issue issue) {
return newArrayList(Iterables.filter(actions.list(), new Predicate<Action>() {
@Override
}));
}
- public List<Action> listAvailableActions(String issueKey) {
- IssueQueryResult queryResult = loadIssue(issueKey);
- final DefaultIssue issue = (DefaultIssue) queryResult.first();
- return listAvailableActions(issue);
- }
-
public Issue execute(String issueKey, String actionKey, UserSession userSession) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(actionKey), "Missing action");
IssueQueryResult queryResult = loadIssue(issueKey);
DefaultIssue issue = (DefaultIssue) queryResult.first();
- if (issue == null) {
- throw new IllegalArgumentException("Issue is not found : " + issueKey);
- }
-
Action action = getAction(actionKey);
if (action == null) {
throw new IllegalArgumentException("Action is not found : " + actionKey);
}
public List<Transition> listTransitions(String issueKey) {
- return issueService.listTransitions(issueKey, UserSession.get());
+ return issueService.listTransitions(issueKey);
}
public List<Transition> listTransitions(Issue issue) {
- return issueService.listTransitions(issue, UserSession.get());
+ return issueService.listTransitions(issue);
}
public List<String> listStatus() {
* <p/>
* Never return null, but return an empty list if the issue does not exist.
*/
- public List<Transition> listTransitions(String issueKey, UserSession userSession) {
- return listTransitions(loadIssue(issueKey).first(), userSession);
+ public List<Transition> listTransitions(String issueKey) {
+ Issue issue = loadIssue(issueKey).first();
+ return listTransitions(issue);
}
/**
* Never return null, but an empty list if the issue does not exist.
+ * No security check is done since it should already have been done to get the issue
*/
- public List<Transition> listTransitions(@Nullable Issue issue, UserSession userSession) {
+ public List<Transition> listTransitions(@Nullable Issue issue) {
if (issue == null) {
return Collections.emptyList();
}
- checkAuthorization(userSession, issue, UserRole.USER);
return workflow.outTransitions(issue);
}
public Issue doTransition(String issueKey, String transition, UserSession userSession) {
IssueQueryResult queryResult = loadIssue(issueKey);
DefaultIssue issue = (DefaultIssue) queryResult.first();
- checkAuthorization(userSession, issue, UserRole.USER);
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login());
if (workflow.doTransition(issue, transition, context)) {
issueStorage.save(issue);
public Issue assign(String issueKey, @Nullable String assignee, UserSession userSession) {
IssueQueryResult queryResult = loadIssue(issueKey);
DefaultIssue issue = (DefaultIssue) queryResult.first();
- checkAuthorization(userSession, issue, UserRole.USER);
if (assignee != null && userFinder.findByLogin(assignee) == null) {
throw new IllegalArgumentException("Unknown user: " + assignee);
}
}
IssueQueryResult queryResult = loadIssue(issueKey);
DefaultIssue issue = (DefaultIssue) queryResult.first();
- checkAuthorization(userSession, issue, UserRole.USER);
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login());
if (issueUpdater.plan(issue, actionPlanKey, context)) {
public Issue setSeverity(String issueKey, String severity, UserSession userSession) {
IssueQueryResult queryResult = loadIssue(issueKey);
DefaultIssue issue = (DefaultIssue) queryResult.first();
- checkAuthorization(userSession, issue, UserRole.USER);
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login());
if (issueUpdater.setManualSeverity(issue, severity, context)) {
actionService.execute("ABCD", "link-to-jira", mock(UserSession.class));
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No issue");
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No issue found");
}
verifyZeroInteractions(function);
}
actionService.listAvailableActions("ABCD");
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No issue");
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("No issue found");
}
}
@Test
public void should_list_transitions() {
- grantAccess();
List<Transition> transitions = newArrayList(transition);
when(workflow.outTransitions(issue)).thenReturn(transitions);
- List<Transition> result = issueService.listTransitions("ABCD", userSession);
+ List<Transition> result = issueService.listTransitions("ABCD");
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(transition);
- verify(authorizationDao).isAuthorizedComponentId(anyLong(), anyInt(), eq(UserRole.USER));
}
@Test
public void should_return_no_transition() {
- grantAccess();
when(issueQueryResult.first()).thenReturn(null);
when(issueQueryResult.issues()).thenReturn(newArrayList((Issue) new DefaultIssue()));
- assertThat(issueService.listTransitions("ABCD", userSession)).isEmpty();
+ assertThat(issueService.listTransitions("ABCD")).isEmpty();
verifyZeroInteractions(workflow);
}
@Test
public void should_do_transition() {
- grantAccess();
when(workflow.doTransition(eq(issue), eq(transition.key()), any(IssueChangeContext.class))).thenReturn(true);
Issue result = issueService.doTransition("ABCD", transition.key(), userSession);
assertThat(issueChangeContext.date()).isNotNull();
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
- verify(authorizationDao).isAuthorizedComponentId(anyLong(), anyInt(), eq(UserRole.USER));
}
@Test
@Test
public void should_assign() {
- grantAccess();
String assignee = "perceval";
when(userFinder.findByLogin(assignee)).thenReturn(new DefaultUser());
assertThat(issueChangeContext.date()).isNotNull();
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
- verify(authorizationDao).isAuthorizedComponentId(anyLong(), anyInt(), eq(UserRole.USER));
}
@Test
public void should_not_assign() {
- grantAccess();
String assignee = "perceval";
when(userFinder.findByLogin(assignee)).thenReturn(new DefaultUser());
@Test
public void should_fail_assign_if_assignee_not_found() {
- grantAccess();
String assignee = "perceval";
when(userFinder.findByLogin(assignee)).thenReturn(null);
@Test
public void should_plan() {
- grantAccess();
String actionPlanKey = "EFGH";
when(actionPlanService.findByKey(actionPlanKey, userSession)).thenReturn(new DefaultActionPlan());
assertThat(issueChangeContext.date()).isNotNull();
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
- verify(authorizationDao).isAuthorizedComponentId(anyLong(), anyInt(), eq(UserRole.USER));
}
@Test
public void should_not_plan() {
- grantAccess();
String actionPlanKey = "EFGH";
when(actionPlanService.findByKey(actionPlanKey, userSession)).thenReturn(new DefaultActionPlan());
@Test
public void should_fail_plan_if_action_plan_not_found() {
- grantAccess();
String actionPlanKey = "EFGH";
when(actionPlanService.findByKey(actionPlanKey, userSession)).thenReturn(null);
@Test
public void should_set_severity() {
- grantAccess();
String severity = "MINOR";
when(issueUpdater.setManualSeverity(eq(issue), eq(severity), any(IssueChangeContext.class))).thenReturn(true);
assertThat(issueChangeContext.date()).isNotNull();
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
- verify(authorizationDao).isAuthorizedComponentId(anyLong(), anyInt(), eq(UserRole.USER));
}
@Test
public void should_not_set_severity() {
- grantAccess();
String severity = "MINOR";
when(issueUpdater.setManualSeverity(eq(issue), eq(severity), any(IssueChangeContext.class))).thenReturn(false);