package org.sonar.server.component;
import com.google.common.base.Optional;
+import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.ResourceTypes;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
-import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.collect.FluentIterable.from;
+import static java.lang.String.format;
+import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
+import static org.sonar.server.ws.WsUtils.checkRequest;
public class ComponentFinder {
}
public ComponentDto getByKey(DbSession dbSession, String key) {
- return getIfPresentOrFail(dbClient.componentDao().selectByKey(dbSession, key), String.format("Component key '%s' not found", key));
+ return getIfPresentOrFail(dbClient.componentDao().selectByKey(dbSession, key), format("Component key '%s' not found", key));
}
public ComponentDto getByUuid(DbSession dbSession, String uuid) {
- return getIfPresentOrFail(dbClient.componentDao().selectByUuid(dbSession, uuid), String.format("Component id '%s' not found", uuid));
+ return getIfPresentOrFail(dbClient.componentDao().selectByUuid(dbSession, uuid), format("Component id '%s' not found", uuid));
}
- public ComponentDto getProjectByUuidOrKey(DbSession dbSession, @Nullable String projectUuid, @Nullable String projectKey) {
+ /**
+ * A project can be:
+ * <ul>
+ * <li>a project – ex: SonarQube</li>
+ * <li>a view – ex: Language Team</li>
+ * <li>a developer – ex: Simon Brandhof</li>
+ * </ul>
+ */
+ public ComponentDto getRootComponentOrModuleByUuidOrKey(DbSession dbSession, @Nullable String projectUuid, @Nullable String projectKey, ResourceTypes resourceTypes) {
ComponentDto project;
if (projectUuid != null) {
- project = getIfPresentOrFail(dbClient.componentDao().selectByUuid(dbSession, projectUuid), String.format("Project id '%s' not found", projectUuid));
+ project = getIfPresentOrFail(dbClient.componentDao().selectByUuid(dbSession, projectUuid), format("Project id '%s' not found", projectUuid));
} else {
- project = getIfPresentOrFail(dbClient.componentDao().selectByKey(dbSession, projectKey), String.format("Project key '%s' not found", projectKey));
+ project = getIfPresentOrFail(dbClient.componentDao().selectByKey(dbSession, projectKey), format("Project key '%s' not found", projectKey));
}
- checkIsProjectOrModule(project);
+ checkIsProjectOrModule(project, resourceTypes);
return project;
}
return component.get();
}
- private static void checkIsProjectOrModule(ComponentDto component) {
- if (!Qualifiers.PROJECT.equals(component.qualifier()) && !Qualifiers.MODULE.equals(component.qualifier())) {
- throw new BadRequestException(String.format("Component '%s' (id: %s) must be a project or a module.", component.key(), component.uuid()));
- }
+ private void checkIsProjectOrModule(ComponentDto component, ResourceTypes resourceTypes) {
+ Set<String> rootQualifiers = from(resourceTypes.getRoots())
+ .transform(RESOURCE_TYPE_TO_QUALIFIER)
+ .toSet();
+ String qualifier = component.qualifier();
+
+ checkRequest(rootQualifiers.contains(qualifier) || Qualifiers.MODULE.equals(qualifier),
+ format("Component '%s' (id: %s) must be a project or a module.", component.key(), component.uuid()));
}
}
import com.google.common.base.Optional;
import javax.annotation.CheckForNull;
+import org.sonar.api.resources.ResourceTypes;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
public class PermissionDependenciesFinder {
private final DbClient dbClient;
private final ComponentFinder componentFinder;
+ private final ResourceTypes resourceTypes;
- public PermissionDependenciesFinder(DbClient dbClient, ComponentFinder componentFinder) {
+ public PermissionDependenciesFinder(DbClient dbClient, ComponentFinder componentFinder, ResourceTypes resourceTypes) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
+ this.resourceTypes = resourceTypes;
}
/**
}
WsProjectRef wsProjectRef = request.project().get();
- return Optional.of(componentFinder.getProjectByUuidOrKey(dbSession, wsProjectRef.uuid(), wsProjectRef.key()));
+ return Optional.of(componentFinder.getRootComponentOrModuleByUuidOrKey(dbSession, wsProjectRef.uuid(), wsProjectRef.key(), resourceTypes));
}
- public ComponentDto getProject(DbSession dbSession, WsProjectRef projectRef) {
- return componentFinder.getProjectByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key());
+ public ComponentDto getRootComponentOrModule(DbSession dbSession, WsProjectRef projectRef) {
+ return componentFinder.getRootComponentOrModuleByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key(), resourceTypes);
}
public String getGroupName(DbSession dbSession, PermissionRequest request) {
Optional<WsProjectRef> project = WsProjectRef.optionalFromRequest(wsRequest);
if (project.isPresent()) {
- return singletonList(finder.getProject(dbSession, project.get()));
+ return singletonList(finder.getRootComponentOrModule(dbSession, project.get()));
}
return dbClient.componentDao().selectComponents(dbSession, rootQualifiers, paging.offset(), paging.pageSize(), query);
DbSession dbSession = dbClient.openSession(false);
try {
PermissionTemplateDto template = finder.getTemplate(dbSession, WsTemplateRef.fromRequest(wsRequest));
- ComponentDto project = finder.getProject(dbSession, WsProjectRef.fromRequest(wsRequest));
+ ComponentDto project = finder.getRootComponentOrModule(dbSession, WsProjectRef.fromRequest(wsRequest));
ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.create(
template.getUuid(),
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.GroupDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import static org.mockito.Mockito.verify;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.permission.ws.AddGroupAction.ACTION;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_GROUP_ID;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_GROUP_NAME;
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
private PermissionUpdater permissionUpdater;
private DbClient dbClient;
private ArgumentCaptor<PermissionChange> permissionChangeCaptor;
dbClient = db.getDbClient();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
ws = new WsTester(new PermissionsWs(
- new AddGroupAction(dbClient, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder)), permissionUpdater)));
+ new AddGroupAction(dbClient, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes)), permissionUpdater)));
userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
assertThat(permissionChange.groupName()).isEqualTo("sonar-administrators");
}
+ @Test
+ public void add_with_view_uuid() throws Exception {
+ insertGroup("sonar-administrators");
+ insertComponent(newView("view-uuid").setKey("view-key"));
+ commit();
+
+ newRequest()
+ .setParam(PARAM_GROUP_NAME, "sonar-administrators")
+ .setParam(PARAM_PROJECT_ID, "view-uuid")
+ .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .execute();
+
+ verify(permissionUpdater).addPermission(permissionChangeCaptor.capture());
+ PermissionChange permissionChange = permissionChangeCaptor.getValue();
+ assertThat(permissionChange.componentKey()).isEqualTo("view-key");
+ assertThat(permissionChange.groupName()).isEqualTo("sonar-administrators");
+ }
+
@Test
public void fail_if_project_uuid_not_found() throws Exception {
expectedException.expect(NotFoundException.class);
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.permission.ws.AddUserAction.ACTION;
+import static org.sonar.server.permission.ws.PermissionsWs.ENDPOINT;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_ID;
+import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_USER_LOGIN;
-import static org.sonar.server.permission.ws.PermissionsWs.ENDPOINT;
@Category(DbTests.class)
public class AddUserActionTest {
- UserSessionRule userSession = UserSessionRule.standalone();
- WsTester ws;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private PermissionUpdater permissionUpdater;
- private DbClient dbClient;
- private DbSession dbSession;
- private ArgumentCaptor<PermissionChange> permissionChangeCaptor = ArgumentCaptor.forClass(PermissionChange.class);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule()
+ .setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
+
+ UserSessionRule userSession = UserSessionRule.standalone();
+ WsTester ws;
+ PermissionUpdater permissionUpdater;
+ DbClient dbClient;
+ DbSession dbSession;
+ ArgumentCaptor<PermissionChange> permissionChangeCaptor = ArgumentCaptor.forClass(PermissionChange.class);
@Before
public void setUp() {
dbSession = db.getSession();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
ws = new WsTester(new PermissionsWs(
- new AddUserAction(dbClient, permissionUpdater, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder)))));
+ new AddUserAction(dbClient, permissionUpdater, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes)))));
userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
assertThat(permissionChange.componentKey()).isEqualTo("project-key");
}
+ @Test
+ public void add_user_permission_with_view_uuid() throws Exception {
+ dbClient.componentDao().insert(dbSession, newView("view-uuid").setKey("view-key"));
+ commit();
+
+ ws.newPostRequest(ENDPOINT, ACTION)
+ .setParam(PARAM_USER_LOGIN, "ray.bradbury")
+ .setParam(PARAM_PROJECT_ID, "view-uuid")
+ .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .execute();
+
+ verify(permissionUpdater).addPermission(permissionChangeCaptor.capture());
+ PermissionChange permissionChange = permissionChangeCaptor.getValue();
+ assertThat(permissionChange.componentKey()).isEqualTo("view-key");
+ }
+
@Test
public void fail_when_project_uuid_is_unknown() throws Exception {
expectedException.expect(NotFoundException.class);
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.server.component.ComponentFinder;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PERMISSION;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_ID;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ ComponentDbTester componentDb = new ComponentDbTester(db);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
DbClient dbClient;
DbSession dbSession;
dbClient = db.getDbClient();
dbSession = db.getSession();
PermissionFinder permissionFinder = new PermissionFinder(dbClient);
- underTest = new GroupsAction(dbClient, userSession, permissionFinder, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient)));
+ underTest = new GroupsAction(dbClient, userSession, permissionFinder, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes));
ws = new WsActionTester(underTest);
userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
.doesNotContain("group-3");
}
+ @Test
+ public void search_groups_on_views() {
+ ComponentDto view = componentDb.insertComponent(newView("view-uuid").setKey("view-key"));
+ GroupDto group = insertGroup(new GroupDto().setName("project-group-name"));
+ insertGroupRole(new GroupRoleDto()
+ .setGroupId(group.getId())
+ .setRole(ISSUE_ADMIN)
+ .setResourceId(view.getId()));
+
+ String result = ws.newRequest()
+ .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
+ .setParam(PARAM_PROJECT_ID, "view-uuid")
+ .execute().getInput();
+
+ assertThat(result).contains("project-group-name")
+ .doesNotContain("group-1")
+ .doesNotContain("group-2")
+ .doesNotContain("group-3");
+ }
+
@Test
public void fail_if_project_permission_without_project() {
expectedException.expect(BadRequestException.class);
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.GroupDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_GROUP_ID;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_GROUP_NAME;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PERMISSION;
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
private PermissionUpdater permissionUpdater;
private ArgumentCaptor<PermissionChange> permissionChangeCaptor = ArgumentCaptor.forClass(PermissionChange.class);
private DbSession dbSession = db.getSession();
DbClient dbClient = db.getDbClient();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
ws = new WsTester(new PermissionsWs(
- new RemoveGroupAction(dbClient, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder)), permissionUpdater)));
+ new RemoveGroupAction(dbClient, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes)), permissionUpdater)));
userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
assertThat(permissionChange.componentKey()).isEqualTo("project-key");
}
+ @Test
+ public void remove_with_view_uuid() throws Exception {
+ insertComponent(newView("view-uuid").setKey("view-key"));
+ insertGroup("sonar-administrators");
+ db.commit();
+
+ newRequest()
+ .setParam(PARAM_GROUP_NAME, "sonar-administrators")
+ .setParam(PARAM_PROJECT_ID, "view-uuid")
+ .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .execute();
+
+ verify(permissionUpdater).removePermission(permissionChangeCaptor.capture());
+ PermissionChange permissionChange = permissionChangeCaptor.getValue();
+ assertThat(permissionChange.componentKey()).isEqualTo("view-key");
+ }
+
@Test
public void remove_with_project_key() throws Exception {
insertComponent(newProjectDto("project-uuid").setKey("project-key"));
insertGroup("sonar-administrators");
- commit();
+ db.commit();
newRequest()
.setParam(PARAM_GROUP_NAME, "sonar-administrators")
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PERMISSION;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_ID;
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
UserSessionRule userSession = UserSessionRule.standalone();
WsTester ws;
PermissionUpdater permissionUpdater;
dbSession = db.getSession();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
ws = new WsTester(new PermissionsWs(
- new RemoveUserAction(dbClient, permissionUpdater, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder)))));
+ new RemoveUserAction(dbClient, permissionUpdater, new PermissionChangeBuilder(new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes)))));
userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
assertThat(permissionChange.componentKey()).isEqualTo("project-key");
}
+ @Test
+ public void remove_with_view_uuid() throws Exception {
+ insertComponent(newView("view-uuid").setKey("view-key"));
+
+ ws.newPostRequest(PermissionsWs.ENDPOINT, ACTION)
+ .setParam(PARAM_USER_LOGIN, "ray.bradbury")
+ .setParam(PARAM_PROJECT_ID, "view-uuid")
+ .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .execute();
+
+ verify(permissionUpdater).removePermission(permissionChangeCaptor.capture());
+ PermissionChange permissionChange = permissionChangeCaptor.getValue();
+ assertThat(permissionChange.componentKey()).isEqualTo("view-key");
+ }
+
@Test
public void fail_when_project_does_not_exist() throws Exception {
expectedException.expect(NotFoundException.class);
resourceTypes = mock(ResourceTypes.class);
when(resourceTypes.getRoots()).thenReturn(rootResourceTypes());
ComponentFinder componentFinder = new ComponentFinder(dbClient);
- PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, componentFinder);
+ PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes);
i18n.setProjectPermissions();
dataLoader = new SearchProjectPermissionsDataLoader(dbClient, finder, resourceTypes);
insertComponent(newDeveloper("developer-name"));
insertComponent(newProjectDto("project-uuid"));
commit();
- dataLoader = new SearchProjectPermissionsDataLoader(dbClient, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient)), resourceTypes);
+ dataLoader = new SearchProjectPermissionsDataLoader(dbClient, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes), resourceTypes);
underTest = new SearchProjectPermissionsAction(dbClient, userSession, i18n, dataLoader);
ws = new WsActionTester(underTest);
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.PermissionTemplateGroupDto;
import org.sonar.db.user.GroupDto;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
DbClient dbClient;
DbSession dbSession;
public void setUp() {
dbClient = db.getDbClient();
dbSession = db.getSession();
- underTest = new TemplateGroupsAction(dbClient, userSession, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient)));
+ underTest = new TemplateGroupsAction(dbClient, userSession, new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes));
ws = new WsActionTester(underTest);
userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.PermissionTemplateUserDto;
import org.sonar.db.user.UserDto;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
DbClient dbClient = db.getDbClient();
DbSession dbSession = db.getSession();
WsActionTester ws;
@Before
public void setUp() {
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
underTest = new TemplateUsersAction(dbClient, userSession, dependenciesFinder);
ws = new WsActionTester(underTest);
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserRoleDto;
import org.sonar.server.component.ComponentFinder;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_ID;
+import static org.sonar.server.permission.ws.WsPermissionParameters.PARAM_PROJECT_KEY;
import static org.sonar.test.JsonAssert.assertJson;
@Category(DbTests.class)
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
DbClient dbClient = db.getDbClient();
DbSession dbSession = db.getSession();
WsActionTester ws;
@Before
public void setUp() {
PermissionFinder permissionFinder = new PermissionFinder(dbClient);
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
underTest = new UsersAction(dbClient, userSession, permissionFinder, dependenciesFinder);
ws = new WsActionTester(underTest);
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
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.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
dbSession = db.getSession();
userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new AddGroupToTemplateAction(dbClient, dependenciesFinder, userSession));
group = insertGroup(newGroupDto().setName(GROUP_NAME));
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
dbSession = db.getSession();
userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new AddUserToTemplateAction(dbClient, dependenciesFinder, userSession));
user = insertUser(newUserDto().setLogin(USER_LOGIN));
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.PermissionRepository;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
PermissionFinder permissionFinder = new PermissionFinder(dbClient);
ComponentFinder componentFinder = new ComponentFinder(dbClient);
PermissionService permissionService = new PermissionService(dbClient, repository, issueAuthorizationIndexer, userSession, componentFinder);
- PermissionDependenciesFinder permissionDependenciesFinder = new PermissionDependenciesFinder(dbClient, componentFinder);
+ PermissionDependenciesFinder permissionDependenciesFinder = new PermissionDependenciesFinder(dbClient, componentFinder, resourceTypes);
ApplyTemplateAction underTest = new ApplyTemplateAction(dbClient, permissionService, permissionDependenciesFinder);
ws = new WsActionTester(underTest);
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
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.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupTesting;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
dbSession = db.getSession();
defaultTemplatePermissionFinder = mock(DefaultPermissionTemplateFinder.class);
when(defaultTemplatePermissionFinder.getDefaultTemplateUuids()).thenReturn(Collections.<String>emptySet());
- PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new DeleteTemplateAction(dbClient, userSession, finder, defaultTemplatePermissionFinder));
permissionTemplate = insertTemplateAndAssociatedPermissions(newPermissionTemplateDto().setUuid(TEMPLATE_UUID));
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
dbSession = db.getSession();
userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new RemoveGroupFromTemplateAction(dbClient, dependenciesFinder, userSession));
group = insertGroup(newGroupDto().setName(GROUP_NAME));
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
public ExpectedException expectedException = ExpectedException.none();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
WsActionTester ws;
DbClient dbClient;
dbSession = db.getSession();
userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new RemoveUserFromTemplateAction(dbClient, dependenciesFinder, userSession));
user = insertUser(newUserDto().setLogin(USER_LOGIN));
ws = new WsActionTester(new SetDefaultTemplateAction(
dbClient,
- new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient)),
+ new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes),
resourceTypes,
persistentSettings,
userSession, i18n));
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.component.ComponentFinder;
WsActionTester ws;
DbClient dbClient;
DbSession dbSession;
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
PermissionTemplateDto templateDto;
dbClient = db.getDbClient();
dbSession = db.getSession();
- PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), resourceTypes);
ws = new WsActionTester(new UpdateTemplateAction(dbClient, userSession, system, finder));
--- /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.db.component;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.sonar.api.resources.ResourceType;
+import org.sonar.api.resources.ResourceTypeTree;
+import org.sonar.api.resources.ResourceTypes;
+
+public class ResourceTypesRule extends ResourceTypes {
+ private final Set<ResourceType> allResourceTypes = new HashSet<>();
+ private final Set<ResourceType> rootResourceTypes = new HashSet<>();
+
+ @Override
+ public Collection<ResourceType> getAll() {
+ return allResourceTypes;
+ }
+
+ @Override
+ public Collection<ResourceType> getRoots() {
+ return rootResourceTypes;
+ }
+
+ public ResourceTypesRule setRootQualifiers(String... qualifiers) {
+ rootResourceTypes.clear();
+ for (String qualifier : qualifiers) {
+ rootResourceTypes.add(ResourceType.builder(qualifier).build());
+ }
+
+ return this;
+ }
+
+ public ResourceTypesRule setAllQualifiers(String... qualifiers) {
+ allResourceTypes.clear();
+ for (String qualifier : qualifiers) {
+ allResourceTypes.add(ResourceType.builder(qualifier).build());
+ }
+
+ return this;
+ }
+
+ @Override
+ public ResourceType get(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<ResourceType> getAllWithPropertyKey(String propertyKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, String propertyValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, boolean propertyValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<String> getChildrenQualifiers(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<ResourceType> getChildren(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<String> getLeavesQualifiers(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ResourceTypeTree getTree(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ResourceType getRoot(String qualifier) {
+ throw new UnsupportedOperationException();
+ }
+}