Skip to content

Commit b2f6344

Browse files
committed
fix: allow to reset cancelled sessions
1 parent 54ed42f commit b2f6344

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ category: Administration
1111

1212
### [Unreleased]
1313

14-
* ...
14+
* fix: allow to reset cancelled sessions
1515

1616
### [25.12.0] - 2025-12-12
1717

src/main/java/de/codescape/jira/plugins/scrumpoker/rest/SessionResource.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Response updateCard(@PathParam("issueKey") String issueKey, @PathParam("c
9393
return Response.status(Response.Status.FORBIDDEN).build();
9494
}
9595

96-
// return not-found for missing session
96+
// return not-found for missing active session
9797
if (!scrumPokerSessionService.hasActiveSession(issueKey)) {
9898
return Response.status(Response.Status.NOT_FOUND).build();
9999
}
@@ -127,7 +127,7 @@ public Response revealCards(@PathParam("issueKey") String issueKey) {
127127
return Response.status(Response.Status.FORBIDDEN).build();
128128
}
129129

130-
// return not-found for missing session
130+
// return not-found for missing active session
131131
if (!scrumPokerSessionService.hasActiveSession(issueKey)) {
132132
return Response.status(Response.Status.NOT_FOUND).build();
133133
}
@@ -168,7 +168,7 @@ public Response cancelSession(@PathParam("issueKey") String issueKey) {
168168
return Response.status(Response.Status.FORBIDDEN).build();
169169
}
170170

171-
// return not-found for missing session
171+
// return not-found for missing active session
172172
if (!scrumPokerSessionService.hasActiveSession(issueKey)) {
173173
return Response.status(Response.Status.NOT_FOUND).build();
174174
}
@@ -188,8 +188,8 @@ public Response cancelSession(@PathParam("issueKey") String issueKey) {
188188
* Reset the Scrum Poker session.
189189
* <ul>
190190
* <li>user is not allowed to see the issue -> FORBIDDEN</li>
191-
* <li>no active session exists -> NOT FOUND</li>
192-
* <li>session is not visible or has no votes -> FORBIDDEN</li>
191+
* <li>no session exists -> NOT FOUND</li>
192+
* <li>session is neither cancelled nor visible and has votes -> FORBIDDEN</li>
193193
* </ul>
194194
*/
195195
@POST
@@ -201,13 +201,13 @@ public Response resetSession(@PathParam("issueKey") String issueKey) {
201201
}
202202

203203
// return not-found for missing session
204-
if (!scrumPokerSessionService.hasActiveSession(issueKey)) {
204+
if (!scrumPokerSessionService.hasSession(issueKey)) {
205205
return Response.status(Response.Status.NOT_FOUND).build();
206206
}
207207

208208
// return forbidden if session reset is not allowed
209209
ScrumPokerSession scrumPokerSession = scrumPokerSessionService.byIssueKey(issueKey, currentUser());
210-
if (!(scrumPokerSession.isVisible() && scrumPokerSession.getVotes().length > 0)) {
210+
if (!(scrumPokerSession.isCancelled() || scrumPokerSession.isVisible() && scrumPokerSession.getVotes().length > 0)) {
211211
return Response.status(Response.Status.FORBIDDEN).build();
212212
}
213213

@@ -238,7 +238,7 @@ public Response confirmEstimation(@PathParam("issueKey") String issueKey,
238238
return Response.status(Response.Status.FORBIDDEN).build();
239239
}
240240

241-
// return not-found for missing session
241+
// return not-found for missing active session
242242
if (!scrumPokerSessionService.hasActiveSession(issueKey)) {
243243
return Response.status(Response.Status.NOT_FOUND).build();
244244
}

src/main/java/de/codescape/jira/plugins/scrumpoker/service/ScrumPokerSessionService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,16 @@ public interface ScrumPokerSessionService {
8585
* Returns whether an active Scrum Poker session for this issue exists.
8686
*
8787
* @param issueKey key of the issue
88-
* @return <code>true</code> if session exists, otherwise <code>false</code>
88+
* @return <code>true</code> if active session exists, otherwise <code>false</code>
8989
*/
9090
boolean hasActiveSession(String issueKey);
9191

92+
/**
93+
* Returns whether a Scrum Poker sessions for this issue exists.
94+
*
95+
* @param issueKey key of the issue
96+
* @return <code>true</code> if session exists, otherwise <code>false</code>
97+
*/
98+
boolean hasSession(String issueKey);
99+
92100
}

src/main/java/de/codescape/jira/plugins/scrumpoker/service/ScrumPokerSessionServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public boolean hasActiveSession(String issueKey) {
147147
&& !(scrumPokerSession.getUpdateDate().before(sessionTimeout()));
148148
}
149149

150+
@Override
151+
public boolean hasSession(String issueKey) {
152+
return findScrumPokerSession(issueKey) != null;
153+
}
154+
150155
private Date sessionTimeout() {
151156
long sessionTimeoutMillis = hoursToMillis(globalSettingsService.load().getSessionTimeout());
152157
return new Date(System.currentTimeMillis() - sessionTimeoutMillis);

src/test/java/de/codescape/jira/plugins/scrumpoker/rest/SessionResourceTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void revealingCardShouldRevealCardsForUnderlyingSession() {
152152
givenCurrentUserCanSeeIssue(ISSUE_KEY, true);
153153
givenCurrentSessionCreatedByUser(ISSUE_KEY, USER_KEY);
154154
givenCurrentSessionIsVisible(false);
155-
when(scrumPokerSession.getVotes()).thenReturn(new ScrumPokerVote[]{Mockito.mock(ScrumPokerVote.class)});
155+
givenCurrentSessionHasVote();
156156
when(globalSettingsService.load()).thenReturn(globalSettings);
157157
when(globalSettings.getAllowRevealDeck()).thenReturn(AllowRevealDeck.EVERYONE);
158158

@@ -169,14 +169,13 @@ public void resettingSessionShouldResetTheUnderlyingSession() {
169169
givenCurrentUserCanSeeIssue(ISSUE_KEY, true);
170170
givenCurrentSessionCreatedByUser(ISSUE_KEY, USER_KEY);
171171
givenCurrentSessionIsVisible(true);
172-
when(scrumPokerSession.getVotes()).thenReturn(new ScrumPokerVote[]{Mockito.mock(ScrumPokerVote.class)});
172+
givenCurrentSessionHasVote();
173173

174174
sessionResource.resetSession(ISSUE_KEY);
175175

176176
verify(scrumPokerSessionService, times(1)).reset(ISSUE_KEY, USER_KEY);
177177
}
178178

179-
180179
/* tests for cancelSession */
181180

182181
@Test
@@ -246,6 +245,7 @@ private void givenCurrentSessionCreatedByUser(String issueKey, String userKey) {
246245
when(sessionEntity.getIssueKey()).thenReturn(issueKey);
247246
when(scrumPokerSession.getCreatorUserKey()).thenReturn(userKey);
248247
when(scrumPokerSessionService.hasActiveSession(issueKey)).thenReturn(true);
248+
when(scrumPokerSessionService.hasSession(issueKey)).thenReturn(true);
249249
}
250250

251251
private void givenCurrentSessionIsVisible(boolean visible) {
@@ -261,4 +261,8 @@ private void givenCardsInCardSet(String... cardValues) {
261261
Arrays.stream(cardValues).map(val -> new Card(val, true)).toList());
262262
}
263263

264+
private void givenCurrentSessionHasVote() {
265+
when(scrumPokerSession.getVotes()).thenReturn(new ScrumPokerVote[]{Mockito.mock(ScrumPokerVote.class)});
266+
}
267+
264268
}

0 commit comments

Comments
 (0)