From 0ce77c4e398676668288ad4e065a1ff7a1e24cf1 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 5 Oct 2015 16:18:13 +0200 Subject: SONAR-6834 add property showBackgroundTasks to api/navigation/component --- .../server/computation/ws/ActivityWsAction.java | 27 ++++++++++++---------- .../server/ui/ws/ComponentNavigationAction.java | 3 +++ 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'server') diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityWsAction.java index d2122a37184..8482a3fa881 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityWsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityWsAction.java @@ -129,18 +129,6 @@ public class ActivityWsAction implements CeWsAction { } } - private void checkPermissions(CeActivityQuery query) { - List componentUuids = query.getComponentUuids(); - if (componentUuids != null && componentUuids.size() == 1) { - if (!userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) && - !userSession.hasComponentUuidPermission(UserRole.ADMIN, componentUuids.get(0))) { - throw new ForbiddenException("Requires administration permission"); - } - } else { - userSession.checkGlobalPermission(UserRole.ADMIN); - } - } - private CeActivityQuery buildQuery(DbSession dbSession, Request wsRequest) { String componentUuid = wsRequest.param(PARAM_COMPONENT_UUID); String componentQuery = wsRequest.param(PARAM_COMPONENT_QUERY); @@ -179,6 +167,17 @@ public class ActivityWsAction implements CeWsAction { } } + private void checkPermissions(CeActivityQuery query) { + List componentUuids = query.getComponentUuids(); + if (componentUuids != null && componentUuids.size() == 1) { + if (!isAllowedOnComponentUuid(userSession, componentUuids.get(0))) { + throw new ForbiddenException("Requires administration permission"); + } + } else { + userSession.checkGlobalPermission(UserRole.ADMIN); + } + } + private static RowBounds readMyBatisRowBounds(Request wsRequest) { int pageIndex = wsRequest.mandatoryParamAsInt(WebService.Param.PAGE); int pageSize = wsRequest.mandatoryParamAsInt(WebService.Param.PAGE_SIZE); @@ -189,4 +188,8 @@ public class ActivityWsAction implements CeWsAction { private static Long toTime(@Nullable Date date) { return date == null ? null : date.getTime(); } + + public static boolean isAllowedOnComponentUuid(UserSession userSession, String componentUuid) { + return userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) || userSession.hasComponentUuidPermission(UserRole.ADMIN, componentUuid); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java index 4a92ec849cb..6fcfa27eb6a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java @@ -49,7 +49,9 @@ import org.sonar.db.dashboard.ActiveDashboardDao; import org.sonar.db.dashboard.DashboardDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; +import org.sonar.server.activity.ws.ActivitiesWs; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.computation.ws.ActivityWsAction; import org.sonar.server.ui.ViewProxy; import org.sonar.server.ui.Views; import org.sonar.server.user.UserSession; @@ -138,6 +140,7 @@ public class ComponentNavigationAction implements NavigationWsAction { .prop("name", component.name()) .prop("isComparable", componentTypeHasProperty(component, PROPERTY_COMPARABLE)) .prop("canBeFavorite", userSession.isLoggedIn()) + .prop("showBackgroundTasks", ActivityWsAction.isAllowedOnComponentUuid(userSession, component.uuid())) .prop("isFavorite", isFavourite(session, component, userSession)); List dashboards = activeDashboardDao.selectProjectDashboardsForUserLogin(session, userSession.getLogin()); -- cgit v1.2.3