diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-10-04 11:39:21 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-10-04 11:50:56 +0200 |
commit | 33f64654b6fa84ef1264393b8fc5b11a47601192 (patch) | |
tree | 48ffd2ca861bbc671999a54bc56f3d45e596ace9 /sonar-core | |
parent | e5ecf075db0a36e45c07bb20669cc654c014293b (diff) | |
download | sonarqube-33f64654b6fa84ef1264393b8fc5b11a47601192.tar.gz sonarqube-33f64654b6fa84ef1264393b8fc5b11a47601192.zip |
SONAR-3871 SONAR-4709 Fix permission checks for project provisioning
Allow users with 'provisioning' permission to apply default permission
template on provisioned project
Hide 'provisioning' section to users w/o 'provisioning' permission
Check for 'provisioning' permission (instead of 'admin') for provisioned
project manipulation
Diffstat (limited to 'sonar-core')
4 files changed, 34 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index 74666be78a4..712039e149c 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -261,6 +261,18 @@ public class ResourceDao { } } + /** + * Return provisioned project with given key + */ + public ResourceDto selectProvisionedProject(String key) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(ResourceMapper.class).selectProvisionedProject(key); + } finally { + MyBatis.closeQuietly(session); + } + } + public static ComponentDto toComponent(ResourceDto resourceDto){ return new ComponentDto() .setId(resourceDto.getId()) diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java index c3bcc36277c..82c25ad1cd0 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java @@ -82,7 +82,10 @@ public interface ResourceMapper { List<ResourceDto> selectProvisionedProjects(@Param("qualifiers") Collection<String> qualifier); + ResourceDto selectProvisionedProject(@Param("key") String key); + void insert(ResourceDto resource); void update(ResourceDto resource); + } diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index ffc899c4641..cc0fbcfe1bd 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -193,6 +193,16 @@ </where> </select> + <select id="selectProvisionedProject" parameterType="string" resultMap="resourceResultMap"> + select p.* from projects p + left join snapshots s on s.project_id=p.id + <where> + and s.id is null + and p.kee = #{key} + and p.copy_resource_id is null + </where> + </select> + <select id="selectAuthorizedChildrenComponentIds" parameterType="map" resultType="int"> <include refid="selectAuthorizedChildrenComponentIdsQuery" /> </select> diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index d9dd9c775e5..57a728b7c29 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -361,6 +361,15 @@ public class ResourceDaoTest extends AbstractDaoTestCase { assertThat(dao.selectProvisionedProjects(Collections.<String>emptyList())).isEmpty(); } + @Test + public void should_select_provisioned_project_by_key(){ + setupData("fixture-including-ghost-projects-and-technical-project"); + + String key = "org.sample:sample"; + assertThat(dao.selectProvisionedProject(key).getKey()).isEqualTo(key); + assertThat(dao.selectProvisionedProject("unknown")).isNull(); + } + private List<String> getKeys(final List<Component> components){ return newArrayList(Iterables.transform(components, new Function<Component, String>() { @Override |