@GET @Produces(APPLICATION_JSON) public Response get( @Context HttpServletRequest request, @QueryParam("repositoryId") Integer repositoryId, @QueryParam("pullRequestId") Long pullRequestId) throws Exception { if (userManager.getRemoteUser(request) == null) { return status(UNAUTHORIZED).build(); } List<PrnfsButton> buttons = newArrayList(); final PrnfsSettings settings = getSettings(); for (PrnfsButton candidate : settings.getButtons()) { UserKey userKey = userManager.getRemoteUserKey(); PrnfsPullRequestAction pullRequestAction = PrnfsPullRequestAction.valueOf(BUTTON_TRIGGER); final PullRequest pullRequest = pullRequestService.getById(repositoryId, pullRequestId); Map<PrnfsVariable, Supplier<String>> variables = getVariables(settings, candidate.getFormIdentifier()); if (allowedUseButton( candidate, userManager.isAdmin(userKey), userManager.isSystemAdmin(userKey)) && triggeredByAction(settings, pullRequestAction, pullRequest, variables, request)) { buttons.add(candidate); } } return ok(gson.toJson(buttons), APPLICATION_JSON).build(); }
static boolean allowedUseButton(PrnfsButton candidate, boolean isAdmin, boolean isSystemAdmin) { if (candidate.getVisibility().equals(EVERYONE)) { return TRUE; } if (isSystemAdmin && systemAdminOk.contains(candidate.getVisibility())) { return TRUE; } else if (isAdmin && adminOk.contains(candidate.getVisibility())) { return TRUE; } else if (candidate.getVisibility().equals(EVERYONE)) { return TRUE; } return FALSE; }