diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-11 15:03:51 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-11 17:27:14 +0100 |
commit | 556ba8154b2c6406b15cd4357cc74a06f3094e3a (patch) | |
tree | e1333b3eadb13cf2968f0c94ac2d2206ccfddac1 /sonar-core | |
parent | 43b1b11b368983c5712122fc853e02ca758febb5 (diff) | |
download | sonarqube-556ba8154b2c6406b15cd4357cc74a06f3094e3a.tar.gz sonarqube-556ba8154b2c6406b15cd4357cc74a06f3094e3a.zip |
SONAR-6156 The search of projects on contextualized Issues page should support views
Diffstat (limited to 'sonar-core')
11 files changed, 212 insertions, 128 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java index ca3a0b67a30..ecad07f8bbd 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java @@ -105,7 +105,7 @@ public class ComponentDto extends Dto<String> implements Component { } /** - * Return the root project id. On a root project, return itself + * Return the root project uuid. On a root project, return itself */ public String projectUuid() { return projectUuid; diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentIndexMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentIndexMapper.java new file mode 100644 index 00000000000..114b8da6ba0 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentIndexMapper.java @@ -0,0 +1,30 @@ +/* + * 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.core.component.db; + +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ComponentIndexMapper { + + List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewOrSubViewUuid") String viewOrSubViewUuid); +} diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java index 269ede5a461..1f057c62dc8 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java @@ -35,21 +35,12 @@ import java.util.List; */ public interface ComponentMapper { - /** - * Warning, projectId is always null - */ @CheckForNull ComponentDto selectByKey(String key); - /** - * Warning, projectId is always null - */ @CheckForNull ComponentDto selectById(long id); - /** - * Warning, projectId is always null - */ @CheckForNull ComponentDto selectByUuid(String uuid); @@ -65,6 +56,8 @@ public interface ComponentMapper { List<ComponentDto> findByKeys(@Param("keys") Collection<String> keys); + List<ComponentDto> findByIds(@Param("ids") Collection<Long> ids); + List<ComponentDto> findByUuids(@Param("uuids") Collection<String> uuids); List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 0390d6fabdf..2b5fa87277f 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -25,11 +25,7 @@ import com.google.common.io.Closeables; import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.Environment; -import org.apache.ibatis.session.Configuration; -import org.apache.ibatis.session.ExecutorType; -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.apache.ibatis.session.*; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.type.JdbcType; import org.slf4j.LoggerFactory; @@ -43,19 +39,13 @@ import org.sonar.core.component.ComponentDto; import org.sonar.core.component.FilePathWithHashDto; import org.sonar.core.component.SnapshotDto; import org.sonar.core.component.UuidWithProjectUuidDto; +import org.sonar.core.component.db.ComponentIndexMapper; import org.sonar.core.component.db.ComponentMapper; import org.sonar.core.component.db.SnapshotMapper; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.computation.db.AnalysisReportMapper; import org.sonar.core.config.Logback; -import org.sonar.core.dashboard.ActiveDashboardDto; -import org.sonar.core.dashboard.ActiveDashboardMapper; -import org.sonar.core.dashboard.DashboardDto; -import org.sonar.core.dashboard.DashboardMapper; -import org.sonar.core.dashboard.WidgetDto; -import org.sonar.core.dashboard.WidgetMapper; -import org.sonar.core.dashboard.WidgetPropertyDto; -import org.sonar.core.dashboard.WidgetPropertyMapper; +import org.sonar.core.dashboard.*; import org.sonar.core.dependency.DependencyDto; import org.sonar.core.dependency.DependencyMapper; import org.sonar.core.dependency.ResourceSnapshotDto; @@ -64,33 +54,11 @@ import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; import org.sonar.core.graph.jdbc.GraphDto; import org.sonar.core.graph.jdbc.GraphDtoMapper; -import org.sonar.core.issue.db.ActionPlanDto; -import org.sonar.core.issue.db.ActionPlanMapper; -import org.sonar.core.issue.db.ActionPlanStatsDto; -import org.sonar.core.issue.db.ActionPlanStatsMapper; -import org.sonar.core.issue.db.BatchIssueDto; -import org.sonar.core.issue.db.IssueChangeDto; -import org.sonar.core.issue.db.IssueChangeMapper; -import org.sonar.core.issue.db.IssueDto; -import org.sonar.core.issue.db.IssueFilterDto; -import org.sonar.core.issue.db.IssueFilterFavouriteDto; -import org.sonar.core.issue.db.IssueFilterFavouriteMapper; -import org.sonar.core.issue.db.IssueFilterMapper; -import org.sonar.core.issue.db.IssueMapper; -import org.sonar.core.measure.db.MeasureDto; -import org.sonar.core.measure.db.MeasureFilterDto; -import org.sonar.core.measure.db.MeasureFilterMapper; -import org.sonar.core.measure.db.MeasureMapper; -import org.sonar.core.measure.db.MetricDto; -import org.sonar.core.measure.db.MetricMapper; +import org.sonar.core.issue.db.*; +import org.sonar.core.measure.db.*; import org.sonar.core.notification.db.NotificationQueueDto; import org.sonar.core.notification.db.NotificationQueueMapper; -import org.sonar.core.permission.GroupWithPermissionDto; -import org.sonar.core.permission.PermissionTemplateDto; -import org.sonar.core.permission.PermissionTemplateGroupDto; -import org.sonar.core.permission.PermissionTemplateMapper; -import org.sonar.core.permission.PermissionTemplateUserDto; -import org.sonar.core.permission.UserWithPermissionDto; +import org.sonar.core.permission.*; import org.sonar.core.persistence.dialect.Dialect; import org.sonar.core.persistence.migration.v44.Migration44Mapper; import org.sonar.core.persistence.migration.v45.Migration45Mapper; @@ -100,22 +68,9 @@ import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.IdUuidPair; import org.sonar.core.purge.PurgeMapper; import org.sonar.core.purge.PurgeableSnapshotDto; -import org.sonar.core.qualitygate.db.ProjectQgateAssociationDto; -import org.sonar.core.qualitygate.db.ProjectQgateAssociationMapper; -import org.sonar.core.qualitygate.db.QualityGateConditionDto; -import org.sonar.core.qualitygate.db.QualityGateConditionMapper; -import org.sonar.core.qualitygate.db.QualityGateDto; -import org.sonar.core.qualitygate.db.QualityGateMapper; -import org.sonar.core.qualityprofile.db.ActiveRuleDto; -import org.sonar.core.qualityprofile.db.ActiveRuleMapper; -import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; -import org.sonar.core.qualityprofile.db.QualityProfileDto; -import org.sonar.core.qualityprofile.db.QualityProfileMapper; -import org.sonar.core.resource.ResourceDto; -import org.sonar.core.resource.ResourceIndexDto; -import org.sonar.core.resource.ResourceIndexerMapper; -import org.sonar.core.resource.ResourceKeyUpdaterMapper; -import org.sonar.core.resource.ResourceMapper; +import org.sonar.core.qualitygate.db.*; +import org.sonar.core.qualityprofile.db.*; +import org.sonar.core.resource.*; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleMapper; import org.sonar.core.rule.RuleParamDto; @@ -125,19 +80,7 @@ import org.sonar.core.technicaldebt.db.CharacteristicMapper; import org.sonar.core.technicaldebt.db.RequirementMigrationDto; import org.sonar.core.template.LoadedTemplateDto; import org.sonar.core.template.LoadedTemplateMapper; -import org.sonar.core.user.AuthorDto; -import org.sonar.core.user.AuthorMapper; -import org.sonar.core.user.GroupDto; -import org.sonar.core.user.GroupMapper; -import org.sonar.core.user.GroupMembershipDto; -import org.sonar.core.user.GroupMembershipMapper; -import org.sonar.core.user.GroupRoleDto; -import org.sonar.core.user.RoleMapper; -import org.sonar.core.user.UserDto; -import org.sonar.core.user.UserGroupDto; -import org.sonar.core.user.UserGroupMapper; -import org.sonar.core.user.UserMapper; -import org.sonar.core.user.UserRoleDto; +import org.sonar.core.user.*; import javax.annotation.Nullable; @@ -262,7 +205,7 @@ public class MyBatis implements BatchComponent, ServerComponent { GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class, ProjectQgateAssociationMapper.class, - AnalysisReportMapper.class, + AnalysisReportMapper.class, ComponentIndexMapper.class, Migration45Mapper.class, Migration50Mapper.class }; loadMappers(conf, mappers); diff --git a/sonar-core/src/main/java/org/sonar/core/user/AuthorizationDao.java b/sonar-core/src/main/java/org/sonar/core/user/AuthorizationDao.java index 530c9609f4d..31b778a4a5c 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/AuthorizationDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/AuthorizationDao.java @@ -19,14 +19,17 @@ */ package org.sonar.core.user; -import com.google.common.collect.ImmutableMap; +import com.google.common.base.Function; import com.google.common.collect.Sets; import org.apache.ibatis.session.SqlSession; import org.sonar.api.ServerComponent; import org.sonar.core.persistence.DaoComponent; +import org.sonar.core.persistence.DaoUtils; +import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import javax.annotation.Nullable; + import java.util.*; import static com.google.common.collect.Maps.newHashMap; @@ -40,38 +43,48 @@ public class AuthorizationDao implements ServerComponent, DaoComponent { this.mybatis = mybatis; } - public Set<String> keepAuthorizedComponentKeys(Set<String> componentKeys, @Nullable Integer userId, String role) { - SqlSession session = mybatis.openSession(false); - try { - return keepAuthorizedComponentKeys(componentKeys, userId, role, session); + public Collection<Long> keepAuthorizedProjectIds(final DbSession session, final Collection<Long> componentIds, @Nullable final Integer userId, final String role) { + if (componentIds.isEmpty()) { + return Collections.emptySet(); + } + return DaoUtils.executeLargeInputs(componentIds, new Function<List<Long>, List<Long>>() { + @Override + public List<Long> apply(List<Long> partition) { + if (userId == null) { + return session.getMapper(AuthorizationMapper.class).keepAuthorizedProjectIdsForAnonymous(role, componentIds); + } else { + return session.getMapper(AuthorizationMapper.class).keepAuthorizedProjectIdsForUser(userId, role, componentIds); + } + } + }); + } + /** + * Used by the Views Plugin + */ + public boolean isAuthorizedComponentKey(String componentKey, @Nullable Integer userId, String role) { + DbSession session = mybatis.openSession(false); + try { + return keepAuthorizedComponentKeys(session, Sets.newHashSet(componentKey), userId, role).size() == 1; } finally { MyBatis.closeQuietly(session); } } - public Set<String> keepAuthorizedComponentKeys(Set<String> componentKeys, @Nullable Integer userId, String role, SqlSession session) { + private Set<String> keepAuthorizedComponentKeys(final DbSession session, final Set<String> componentKeys, @Nullable final Integer userId, final String role) { if (componentKeys.isEmpty()) { return Collections.emptySet(); } - String sql; - Map<String, Object> params; - if (userId == null) { - sql = "keepAuthorizedComponentKeysForAnonymous"; - params = ImmutableMap.of("role", role, "componentKeys", componentKeys); - } else { - sql = "keepAuthorizedComponentKeysForUser"; - params = ImmutableMap.of(USER_ID_PARAM, userId, "role", role, "componentKeys", componentKeys); - } - - return Sets.newHashSet(session.<String>selectList(sql, params)); - } - - /** - * Used by the Views Plugin - */ - public boolean isAuthorizedComponentKey(String componentKey, @Nullable Integer userId, String role) { - return keepAuthorizedComponentKeys(Sets.newHashSet(componentKey), userId, role).size() == 1; + return Sets.newHashSet(DaoUtils.executeLargeInputs(componentKeys, new Function<List<String>, List<String>>() { + @Override + public List<String> apply(List<String> partition) { + if (userId == null) { + return session.getMapper(AuthorizationMapper.class).keepAuthorizedComponentKeysForAnonymous(role, componentKeys); + } else { + return session.getMapper(AuthorizationMapper.class).keepAuthorizedComponentKeysForUser(userId, role, componentKeys); + } + } + })); } public Collection<String> selectAuthorizedRootProjectsKeys(@Nullable Integer userId, String role) { diff --git a/sonar-core/src/main/java/org/sonar/core/user/AuthorizationMapper.java b/sonar-core/src/main/java/org/sonar/core/user/AuthorizationMapper.java new file mode 100644 index 00000000000..10d137dffbd --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/user/AuthorizationMapper.java @@ -0,0 +1,38 @@ +/* + * 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.core.user; + +import org.apache.ibatis.annotations.Param; + +import java.util.Collection; +import java.util.List; + +public interface AuthorizationMapper { + + List<Long> keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection<Long> componentIds); + + List<Long> keepAuthorizedProjectIdsForUser(@Param("userId") Integer userId, @Param("role") String role, @Param("componentIds") Collection<Long> componentIds); + + List<String> keepAuthorizedComponentKeysForAnonymous(@Param("role") String role, @Param("componentKeys") Collection<String> componentKeys); + + List<String> keepAuthorizedComponentKeysForUser(@Param("userId") Integer userId, @Param("role") String role, @Param("componentKeys") Collection<String> componentKeys); + +} diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentIndexMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentIndexMapper.xml new file mode 100644 index 00000000000..6b80ef94aac --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentIndexMapper.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.sonar.core.component.db.ComponentIndexMapper"> + + <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long"> + SELECT r.resource_id FROM resource_index r + INNER JOIN projects copy ON copy.copy_resource_id = r.resource_id + <where> + AND copy.module_uuid_path LIKE #{viewOrSubViewUuid} + AND r.kee LIKE #{query} + </where> + ORDER BY r.name_size + </select> + +</mapper> + diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml index 98426094cd2..ee96cd81563 100644 --- a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml @@ -86,6 +86,19 @@ </where> </select> + <select id="findByIds" parameterType="long" resultType="Component"> + select + <include refid="componentColumns"/> + from projects p + <where> + p.enabled=${_true} + and p.id in + <foreach collection="ids" open="(" close=")" item="id" separator=","> + #{id} + </foreach> + </where> + </select> + <select id="findByUuids" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p diff --git a/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml index 12e1e32da23..1e757eaf58b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml @@ -30,6 +30,33 @@ <foreach collection="componentKeys" open="(" close=")" item="element" index="index" separator=" or " >p.kee=#{element}</foreach> </select> + <select id="keepAuthorizedProjectIdsForUser" parameterType="map" resultType="long"> + SELECT gr.resource_id + FROM group_roles gr + WHERE + gr.role=#{role} + and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId})) + and + <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">gr.resource_id=#{element}</foreach> + UNION + SELECT p.id + FROM user_roles ur, projects p + WHERE + ur.role=#{role} + and ur.user_id=#{userId} and + <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">p.id=#{element}</foreach> + </select> + + <select id="keepAuthorizedProjectIdsForAnonymous" parameterType="map" resultType="long"> + SELECT gr.resource_id + FROM group_roles gr + WHERE + gr.role=#{role} + and gr.group_id is null + and + <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">gr.resource_id=#{element}</foreach> + </select> + <select id="selectAuthorizedRootProjectsKeys" parameterType="map" resultType="string"> <include refid="selectAuthorizedRootProjectsKeysQuery" /> </select> diff --git a/sonar-core/src/test/java/org/sonar/core/user/AuthorizationDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/AuthorizationDaoTest.java index 2e267d391ad..521d0af66a3 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/AuthorizationDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/AuthorizationDaoTest.java @@ -20,19 +20,33 @@ package org.sonar.core.user; import com.google.common.collect.Sets; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.persistence.DbSession; import java.util.Collection; -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; public class AuthorizationDaoTest extends AbstractDaoTestCase { private static final int USER = 100; - private static final String PROJECT = "pj-w-snapshot", PACKAGE = "pj-w-snapshot:package", FILE = "pj-w-snapshot:file", FILE_IN_OTHER_PROJECT = "another", - EMPTY_PROJECT = "pj-wo-snapshot"; + private static final Long PROJECT_ID = 300L, EMPTY_PROJECT_ID = 400L; + private static final String PROJECT = "pj-w-snapshot"; + + DbSession session; + + @Before + public void setUp() throws Exception { + session = getMyBatis().openSession(false); + } + + @After + public void tearDown() throws Exception { + session.close(); + } @Test public void user_should_be_authorized() { @@ -40,15 +54,15 @@ public class AuthorizationDaoTest extends AbstractDaoTestCase { setupData("user_should_be_authorized"); AuthorizationDao authorization = new AuthorizationDao(getMyBatis()); - Set<String> componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + Collection<Long> componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), USER, "user"); - assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE, EMPTY_PROJECT); + assertThat(componentIds).containsOnly(PROJECT_ID, EMPTY_PROJECT_ID); // user does not have the role "admin" - componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE), + componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID), USER, "admin"); assertThat(componentIds).isEmpty(); } @@ -72,15 +86,15 @@ public class AuthorizationDaoTest extends AbstractDaoTestCase { setupData("group_should_be_authorized"); AuthorizationDao authorization = new AuthorizationDao(getMyBatis()); - Set<String> componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + Collection<Long> componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), USER, "user"); - assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE, EMPTY_PROJECT); + assertThat(componentIds).containsOnly(PROJECT_ID, EMPTY_PROJECT_ID); // group does not have the role "admin" - componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), USER, "admin"); assertThat(componentIds).isEmpty(); } @@ -91,15 +105,15 @@ public class AuthorizationDaoTest extends AbstractDaoTestCase { setupData("group_should_have_global_authorization"); AuthorizationDao authorization = new AuthorizationDao(getMyBatis()); - Set<String> componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + Collection<Long> componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), USER, "user"); - assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE, EMPTY_PROJECT); + assertThat(componentIds).containsOnly(PROJECT_ID, EMPTY_PROJECT_ID); // group does not have the role "admin" - componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), USER, "admin"); assertThat(componentIds).isEmpty(); } @@ -109,15 +123,15 @@ public class AuthorizationDaoTest extends AbstractDaoTestCase { setupData("anonymous_should_be_authorized"); AuthorizationDao authorization = new AuthorizationDao(getMyBatis()); - Set<String> componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT, EMPTY_PROJECT), + Collection<Long> componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID, EMPTY_PROJECT_ID), null, "user"); - assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE, EMPTY_PROJECT); + assertThat(componentIds).containsOnly(PROJECT_ID, EMPTY_PROJECT_ID); // group does not have the role "admin" - componentIds = authorization.keepAuthorizedComponentKeys( - Sets.<String>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT), + componentIds = authorization.keepAuthorizedProjectIds(session, + Sets.newHashSet(PROJECT_ID), null, "admin"); assertThat(componentIds).isEmpty(); } diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml index b6371a7e0b1..3771e09738d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml @@ -6,9 +6,6 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="200" resource_id="999" role="user"/> - <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD" module_uuid="DEFG"/> - <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE" module_uuid="DEFG"/> - <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" module_uuid="DEFG"/> <projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/> <projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/> </dataset> |