Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 252fc93

Browse files
committed
Filtering buttons in buttons resource, and filtering out allowed buttons
1 parent 4ee1f0d commit 252fc93

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Changelog of Pull Request Notifier for Bitbucket.
88

99
* So that the user may be admin in the repo, but not in the project.
1010

11-
[0e8243eb4d445dd](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/0e8243eb4d445dd) Tomas Bjerre *2016-07-30 06:58:02*
11+
[4ee1f0d0a754a04](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/4ee1f0d0a754a04) Tomas Bjerre *2016-07-30 07:15:22*
1212

1313
### GitHub [#135](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/135) Not permitted to access buttons settings as project/repo admin
1414
Getting project and repo with sys admin permissions

src/main/java/se/bjurr/prnfb/presentation/ButtonServlet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public Response get() {
8787
List<PrnfbButton> buttons = this.settingsService.getButtons();
8888
Iterable<PrnfbButton> allowedButtons = this.userCheckService.filterAllowed(buttons);
8989
List<ButtonDTO> dtos = toButtonDtoList(allowedButtons);
90+
Collections.sort(dtos);
9091
return ok(dtos, APPLICATION_JSON).build();
9192
}
9293

@@ -112,7 +113,9 @@ public Response get(@PathParam("projectKey") String projectKey) {
112113
return status(UNAUTHORIZED).build();
113114
}
114115
List<PrnfbButton> buttons = this.settingsService.getButtons(projectKey);
115-
List<ButtonDTO> dtos = toButtonDtoList(buttons);
116+
Iterable<PrnfbButton> allowedButtons = this.userCheckService.filterAllowed(buttons);
117+
List<ButtonDTO> dtos = toButtonDtoList(allowedButtons);
118+
Collections.sort(dtos);
116119
return ok(dtos, APPLICATION_JSON).build();
117120
}
118121

@@ -124,7 +127,8 @@ public Response get(@PathParam("projectKey") String projectKey, @PathParam("repo
124127
return status(UNAUTHORIZED).build();
125128
}
126129
List<PrnfbButton> buttons = this.settingsService.getButtons(projectKey, repositorySlug);
127-
List<ButtonDTO> dtos = toButtonDtoList(buttons);
130+
Iterable<PrnfbButton> allowedButtons = this.userCheckService.filterAllowed(buttons);
131+
List<ButtonDTO> dtos = toButtonDtoList(allowedButtons);
128132
Collections.sort(dtos);
129133
return ok(dtos, APPLICATION_JSON).build();
130134
}

src/test/java/se/bjurr/prnfb/presentation/ButtonServletTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void testThatButtonCanBeListedForAPr() throws Exception {
114114
public void testThatButtonCanBeListedPerProject() throws Exception {
115115
when(this.settingsService.getButtons(this.buttonDto1.getProjectKey().orNull()))//
116116
.thenReturn(newArrayList(this.button1));
117+
allowAll();
117118

118119
Response actual = this.sut.get(this.buttonDto1.getProjectKey().orNull());
119120
@SuppressWarnings("unchecked")
@@ -129,6 +130,7 @@ public void testThatButtonCanBeListedPerProjectAndRepo() throws Exception {
129130
this.settingsService.getButtons(this.buttonDto1.getProjectKey().orNull(), this.buttonDto1.getRepositorySlug()
130131
.orNull()))//
131132
.thenReturn(newArrayList(this.button1));
133+
allowAll();
132134

133135
Response actual = this.sut
134136
.get(this.buttonDto1.getProjectKey().orNull(), this.buttonDto1.getRepositorySlug().orNull());

0 commit comments

Comments
 (0)