diff --git a/CHANGELOG.md b/CHANGELOG.md index 33a03578..00f713a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Changelog of Pull Request Notifier for Bitbucket. ### No issue Using git changelog plugin 1.20 - [2a8a6b934a6a6b2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/2a8a6b934a6a6b2) Tomas Bjerre *2016-03-15 21:10:32* + [97dc36d24773408](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/97dc36d24773408) Tomas Bjerre *2016-03-15 21:15:55* ## 2.16 ### GitHub [#103](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/103) Support Bitbucket Server 4.4 diff --git a/src/main/java/se/bjurr/prnfb/ManualResource.java b/src/main/java/se/bjurr/prnfb/ManualResource.java index 3990329d..4952dd2b 100644 --- a/src/main/java/se/bjurr/prnfb/ManualResource.java +++ b/src/main/java/se/bjurr/prnfb/ManualResource.java @@ -42,13 +42,12 @@ import se.bjurr.prnfb.settings.PrnfbSettings; import com.atlassian.annotations.security.XsrfProtectionExcluded; +import com.atlassian.bitbucket.auth.AuthenticationContext; import com.atlassian.bitbucket.pull.PullRequest; import com.atlassian.bitbucket.pull.PullRequestService; import com.atlassian.bitbucket.repository.RepositoryService; import com.atlassian.bitbucket.server.ApplicationPropertiesService; -import com.atlassian.bitbucket.user.ApplicationUser; import com.atlassian.bitbucket.user.SecurityService; -import com.atlassian.bitbucket.user.UserService; import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; import com.atlassian.sal.api.user.UserKey; import com.atlassian.sal.api.user.UserManager; @@ -59,13 +58,13 @@ public class ManualResource { private static Gson gson = new Gson(); private final UserManager userManager; - private final UserService userService; private final PullRequestService pullRequestService; private final PrnfbPullRequestEventListener prnfbPullRequestEventListener; private final SecurityService securityService; private final PluginSettingsFactory pluginSettingsFactory; private final ApplicationPropertiesService propertiesService; private final RepositoryService repositoryService; + private final AuthenticationContext authenticationContext; private static final List adminOk = newArrayList(); private static final List systemAdminOk = newArrayList(); static { @@ -74,11 +73,12 @@ public class ManualResource { systemAdminOk.add(SYSTEM_ADMIN); } - public ManualResource(UserManager userManager, UserService userService, PluginSettingsFactory pluginSettingsFactory, - PullRequestService pullRequestService, PrnfbPullRequestEventListener prnfbPullRequestEventListener, - RepositoryService repositoryService, ApplicationPropertiesService propertiesService, SecurityService securityService) { + public ManualResource(AuthenticationContext authenticationContext, UserManager userManager, + PluginSettingsFactory pluginSettingsFactory, PullRequestService pullRequestService, + PrnfbPullRequestEventListener prnfbPullRequestEventListener, RepositoryService repositoryService, + ApplicationPropertiesService propertiesService, SecurityService securityService) { + this.authenticationContext = authenticationContext; this.userManager = userManager; - this.userService = userService; this.pullRequestService = pullRequestService; this.prnfbPullRequestEventListener = prnfbPullRequestEventListener; this.securityService = securityService; @@ -159,9 +159,8 @@ private Map> getVariables(final PrnfbSettings se private PrnfbRenderer getRenderer(final PullRequest pullRequest, PrnfbNotification prnfbNotification, PrnfbPullRequestAction pullRequestAction, Map> variables, HttpServletRequest request) { - ApplicationUser bitbucketUser = userService.getUserBySlug(userManager.getRemoteUser(request).getUsername()); - return new PrnfbRenderer(pullRequest, pullRequestAction, bitbucketUser, repositoryService, propertiesService, - prnfbNotification, variables); + return new PrnfbRenderer(pullRequest, pullRequestAction, authenticationContext.getCurrentUser(), repositoryService, + propertiesService, prnfbNotification, variables); } static boolean allowedUseButton(PrnfbButton candidate, boolean isAdmin, boolean isSystemAdmin) { diff --git a/src/test/java/se/bjurr/prnb/admin/utils/PrnfbTestBuilder.java b/src/test/java/se/bjurr/prnb/admin/utils/PrnfbTestBuilder.java index 31a9fa36..de6944e8 100644 --- a/src/test/java/se/bjurr/prnb/admin/utils/PrnfbTestBuilder.java +++ b/src/test/java/se/bjurr/prnb/admin/utils/PrnfbTestBuilder.java @@ -54,6 +54,7 @@ import se.bjurr.prnfb.settings.PrnfbSettings; import se.bjurr.prnfb.settings.SettingsStorage; +import com.atlassian.bitbucket.auth.AuthenticationContext; import com.atlassian.bitbucket.event.pull.PullRequestEvent; import com.atlassian.bitbucket.permission.Permission; import com.atlassian.bitbucket.pull.PullRequest; @@ -63,7 +64,6 @@ import com.atlassian.bitbucket.server.ApplicationPropertiesService; import com.atlassian.bitbucket.user.EscalatedSecurityContext; import com.atlassian.bitbucket.user.SecurityService; -import com.atlassian.bitbucket.user.UserService; import com.atlassian.bitbucket.util.Operation; import com.atlassian.sal.api.pluginsettings.PluginSettings; import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; @@ -134,6 +134,8 @@ public static PrnfbTestBuilder prnfbTestBuilder() { private PullRequest pullRequest; + private AuthenticationContext authenticationContext; + private PrnfbTestBuilder() { fakeRandomCounter = 0L; fakeRandom(new FakeRandom()); @@ -159,10 +161,10 @@ public T execute(TransactionCallback action) { pullRequestService = mock(PullRequestService.class); listener = new PrnfbPullRequestEventListener(pluginSettingsFactory, repositoryService, propertiesService, pullRequestService, new SyncExecutorService()); - UserService userService = mock(UserService.class); withPullRequest(pullRequestEventBuilder().build().getPullRequest()); - manualResouce = new ManualResource(userManager, userService, pluginSettingsFactory, pullRequestService, listener, - repositoryService, propertiesService, securityService); + authenticationContext = mock(AuthenticationContext.class); + manualResouce = new ManualResource(authenticationContext, userManager, pluginSettingsFactory, pullRequestService, + listener, repositoryService, propertiesService, securityService); } public PrnfbTestBuilder delete(String id) throws Exception { diff --git a/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java index 2a31314e..4249604b 100644 --- a/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java @@ -1603,19 +1603,23 @@ public void testThatEventTriggeredByButtonCanResultInSeveralNotifications() thro .withFieldValue(FORM_TYPE, TRIGGER_CONFIG_FORM.name()) // .build() // ) // - .store().withNotification( // + .store()// + .withNotification( // notificationBuilder() // .withFieldValue(url, "http://bjurr.se/?456=${" + BUTTON_TRIGGER_TITLE + "}") // .withFieldValue(events, BUTTON_TRIGGER) // .withFieldValue(filter_string, "${" + BUTTON_TRIGGER_TITLE + "}") // .withFieldValue(filter_regexp, "button") // - .withFieldValue(FORM_TYPE, TRIGGER_CONFIG_FORM.name()).build()) // - .store().withNotification( // + .withFieldValue(FORM_TYPE, TRIGGER_CONFIG_FORM.name())// + .build()) // + .store()// + .withNotification( // notificationBuilder() // .withFieldValue(FORM_IDENTIFIER, "Button Form") // .withFieldValue(FORM_TYPE, BUTTON_CONFIG_FORM.name()) // .withFieldValue(button_title, "button text 123") // - .withFieldValue(button_visibility, EVERYONE.name()).build()) // + .withFieldValue(button_visibility, EVERYONE.name())// + .build()) // .store() // .triggerButton("Button Form") // .invokedUrl(0, "http://bjurr.se/?123=button+text+123") //