import java.util.List;
import org.sonar.api.server.ServerSide;
-import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ResourceDto;
import org.sonar.db.permission.PermissionRepository;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.issue.index.IssueAuthorizationIndexer;
import org.sonar.server.user.UserSession;
ComponentDto component = componentFinder.getByKey(session, componentKey);
ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
if (provisioned == null) {
- checkProjectAdminPermission(componentKey);
+ checkProjectAdminUserByComponentKey(userSession, componentKey);
} else {
userSession.checkGlobalPermission(GlobalPermissions.PROVISIONING);
}
indexProjectPermissions();
}
- private void checkProjectAdminPermission(String projectKey) {
- if (!userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) && !userSession.hasProjectPermission(UserRole.ADMIN, projectKey)) {
- throw new ForbiddenException("Insufficient privileges");
- }
- }
-
private void indexProjectPermissions() {
issueAuthorizationIndexer.index();
}
import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Ordering.natural;
+import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
-import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
public class DefaultPermissionTemplateFinder {
private final Settings settings;
@Override
public String apply(@Nonnull String qualifier) {
- String effectiveTemplateUuid = effectiveTemplateUuid(settings, qualifier);
- return effectiveTemplateUuid;
+ return effectiveTemplateUuid(settings, qualifier);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.permission.ws.template;
+
+import com.google.common.collect.HashBasedTable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
+
+import static java.util.Collections.singletonList;
+import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+
+public class SearchTemplatesDataTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ SearchTemplatesData.Builder underTest = SearchTemplatesData.newBuilder()
+ .defaultTemplates(singletonList(new DefaultPermissionTemplateFinder.TemplateUuidQualifier("template_uuid", Qualifiers.PROJECT)))
+ .templates(singletonList(newPermissionTemplateDto()))
+ .userCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create())
+ .groupCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create());
+
+ @Test
+ public void fail_if_templates_is_null() {
+ expectedException.expect(IllegalStateException.class);
+ underTest.templates(null);
+
+ underTest.build();
+ }
+
+ @Test
+ public void fail_if_default_templates_are_null() {
+ expectedException.expect(IllegalStateException.class);
+ underTest.defaultTemplates(null);
+
+ underTest.build();
+ }
+
+ @Test
+ public void fail_if_user_count_is_null() {
+ expectedException.expect(IllegalStateException.class);
+ underTest.userCountByTemplateIdAndPermission(null);
+
+ underTest.build();
+ }
+
+ @Test
+ public void fail_if_group_count_is_null() {
+ expectedException.expect(IllegalStateException.class);
+ underTest.groupCountByTemplateIdAndPermission(null);
+
+ underTest.build();
+ }
+}