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

Commit 4ee1f0d

Browse files
committed
Checking privilegies for both project and repo #134
* So that the user may be admin in the repo, but not in the project.
1 parent 474e1fd commit 4ee1f0d

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
Changelog of Pull Request Notifier for Bitbucket.
44

55
## Unreleased
6+
### GitHub [#134](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/134) Not able to see PR buttons
7+
Checking privilegies for both project and repo
8+
9+
* So that the user may be admin in the repo, but not in the project.
10+
11+
[0e8243eb4d445dd](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/0e8243eb4d445dd) Tomas Bjerre *2016-07-30 06:58:02*
12+
613
### GitHub [#135](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/135) Not permitted to access buttons settings as project/repo admin
714
Getting project and repo with sys admin permissions
815

9-
[4af3fd9f87fa409](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/4af3fd9f87fa409) Tomas Bjerre *2016-07-30 06:42:38*
16+
[474e1fd252eebf4](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/474e1fd252eebf4) Tomas Bjerre *2016-07-30 06:56:50*
1017

1118
## 2.32
1219
### No issue

src/main/java/se/bjurr/prnfb/service/UserCheckService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public boolean apply(PrnfbButton input) {
5555
}
5656
});
5757
return allowedButtons;
58-
}
58+
}
5959

6060
public boolean isAdmin(UserKey userKey, String projectKey, String repositorySlug) {
6161
boolean isAdmin = this.userManager.isAdmin(userKey);
@@ -68,12 +68,17 @@ public boolean isAdmin(UserKey userKey, String projectKey, String repositorySlug
6868

6969
if (projectKey != null && repositorySlug == null) {
7070
Project project = getProject(projectKey);
71-
return this.permissionService.hasProjectPermission(project, PROJECT_ADMIN);
72-
} else if (repositorySlug != null) {
71+
boolean isAllowed = this.permissionService.hasProjectPermission(project, PROJECT_ADMIN);
72+
if (isAllowed) {
73+
return true;
74+
}
75+
}
76+
77+
if (projectKey != null && repositorySlug != null) {
7378
Repository repository = getRepo(projectKey, repositorySlug);
7479
return this.permissionService.hasRepositoryPermission(repository, REPO_ADMIN);
7580
}
76-
return isAdmin;
81+
return false;
7782
}
7883

7984
/**

src/test/java/se/bjurr/prnfb/service/UserCheckServiceTest.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
import static se.bjurr.prnfb.settings.USER_LEVEL.SYSTEM_ADMIN;
1010

1111
import java.util.List;
12+
import java.util.Set;
1213

1314
import org.junit.Before;
1415
import org.junit.Test;
1516
import org.mockito.Matchers;
1617
import org.mockito.Mock;
17-
import org.mockito.invocation.InvocationOnMock;
18-
import org.mockito.stubbing.Answer;
1918

2019
import se.bjurr.prnfb.presentation.dto.ON_OR_OFF;
2120
import se.bjurr.prnfb.settings.PrnfbButton;
2221

22+
import com.atlassian.bitbucket.permission.Permission;
2323
import com.atlassian.bitbucket.permission.PermissionService;
2424
import com.atlassian.bitbucket.project.ProjectService;
2525
import com.atlassian.bitbucket.repository.RepositoryService;
@@ -31,9 +31,33 @@
3131
import com.atlassian.sal.api.user.UserProfile;
3232

3333
public class UserCheckServiceTest {
34+
private final EscalatedSecurityContext escalatedSecurityContext = new EscalatedSecurityContext() {
3435

35-
@Mock
36-
private EscalatedSecurityContext escalatedSecurityContext;
36+
@Override
37+
public void applyToRequest() {
38+
39+
}
40+
41+
@Override
42+
public <T, E extends Throwable> T call(Operation<T, E> arg0) throws E {
43+
return arg0.perform();
44+
}
45+
46+
@Override
47+
public EscalatedSecurityContext withPermission(Object arg0, Permission arg1) {
48+
return this;
49+
}
50+
51+
@Override
52+
public EscalatedSecurityContext withPermission(Permission arg0) {
53+
return this;
54+
}
55+
56+
@Override
57+
public EscalatedSecurityContext withPermissions(Set<Permission> arg0) {
58+
return this;
59+
}
60+
};
3761

3862
@Mock
3963
private PermissionService permissionService;
@@ -62,14 +86,6 @@ public void before() throws Exception {
6286

6387
when(this.securityService.withPermission(Matchers.any(), Matchers.any()))//
6488
.thenReturn(this.escalatedSecurityContext);
65-
when(this.escalatedSecurityContext.call(Matchers.any()))//
66-
.thenAnswer(new Answer<Boolean>() {
67-
@Override
68-
public Boolean answer(InvocationOnMock invocation) throws Throwable {
69-
Operation<?, ?> op = (Operation<?, ?>) invocation.getArguments()[0];
70-
return (Boolean) op.perform();
71-
}
72-
});
7389
}
7490

7591
@Test

0 commit comments

Comments
 (0)