package org.sonar.plugins.core;
import com.google.common.collect.ImmutableList;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.Extension;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
-import org.sonar.api.PropertyType;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.*;
import org.sonar.api.checks.NoSonarFilter;
import org.sonar.api.resources.Java;
import org.sonar.plugins.core.batch.ExcludedResourceFilter;
import org.sonar.plugins.core.charts.DistributionBarChart;
import org.sonar.plugins.core.charts.XradarChart;
import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
-import org.sonar.plugins.core.dashboards.DefaultDashboard;
-import org.sonar.plugins.core.dashboards.HotspotsDashboard;
-import org.sonar.plugins.core.dashboards.MyFavouritesDashboard;
-import org.sonar.plugins.core.dashboards.ProjectsDashboard;
-import org.sonar.plugins.core.dashboards.ReviewsDashboard;
-import org.sonar.plugins.core.dashboards.TimeMachineDashboard;
-import org.sonar.plugins.core.dashboards.TreemapDashboard;
+import org.sonar.plugins.core.dashboards.*;
import org.sonar.plugins.core.filters.MyFavouritesFilter;
import org.sonar.plugins.core.filters.ProjectFilter;
import org.sonar.plugins.core.filters.TreeMapFilter;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
-import org.sonar.plugins.core.sensors.BranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.CheckAlertThresholds;
-import org.sonar.plugins.core.sensors.CommentDensityDecorator;
-import org.sonar.plugins.core.sensors.CoverageDecorator;
-import org.sonar.plugins.core.sensors.DirectoriesDecorator;
-import org.sonar.plugins.core.sensors.FilesDecorator;
-import org.sonar.plugins.core.sensors.GenerateAlertEvents;
-import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.ItCoverageDecorator;
-import org.sonar.plugins.core.sensors.ItLineCoverageDecorator;
-import org.sonar.plugins.core.sensors.LineCoverageDecorator;
-import org.sonar.plugins.core.sensors.ManualMeasureDecorator;
-import org.sonar.plugins.core.sensors.ManualViolationInjector;
-import org.sonar.plugins.core.sensors.ProfileEventsSensor;
-import org.sonar.plugins.core.sensors.ProfileSensor;
-import org.sonar.plugins.core.sensors.ProjectLinksSensor;
-import org.sonar.plugins.core.sensors.ReviewNotifications;
-import org.sonar.plugins.core.sensors.ReviewWorkflowDecorator;
-import org.sonar.plugins.core.sensors.ReviewsMeasuresDecorator;
-import org.sonar.plugins.core.sensors.UnitTestDecorator;
-import org.sonar.plugins.core.sensors.VersionEventsSensor;
-import org.sonar.plugins.core.sensors.ViolationSeverityUpdater;
-import org.sonar.plugins.core.sensors.ViolationsDecorator;
-import org.sonar.plugins.core.sensors.ViolationsDensityDecorator;
-import org.sonar.plugins.core.sensors.WeightedViolationsDecorator;
+import org.sonar.plugins.core.security.DefaultResourcePermissioning;
+import org.sonar.plugins.core.sensors.*;
import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition;
-import org.sonar.plugins.core.timemachine.NewCoverageAggregator;
-import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.NewViolationsDecorator;
-import org.sonar.plugins.core.timemachine.ReferenceAnalysis;
-import org.sonar.plugins.core.timemachine.TendencyDecorator;
-import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister;
-import org.sonar.plugins.core.timemachine.VariationDecorator;
-import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator;
-import org.sonar.plugins.core.timemachine.ViolationTrackingDecorator;
+import org.sonar.plugins.core.timemachine.*;
import org.sonar.plugins.core.web.Lcom4Viewer;
-import org.sonar.plugins.core.widgets.AlertsWidget;
-import org.sonar.plugins.core.widgets.CommentsDuplicationsWidget;
-import org.sonar.plugins.core.widgets.ComplexityWidget;
-import org.sonar.plugins.core.widgets.CoverageWidget;
-import org.sonar.plugins.core.widgets.CustomMeasuresWidget;
-import org.sonar.plugins.core.widgets.DescriptionWidget;
-import org.sonar.plugins.core.widgets.EventsWidget;
-import org.sonar.plugins.core.widgets.FilterWidget;
-import org.sonar.plugins.core.widgets.HotspotMetricWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget;
-import org.sonar.plugins.core.widgets.ItCoverageWidget;
-import org.sonar.plugins.core.widgets.RulesWidget;
-import org.sonar.plugins.core.widgets.SizeWidget;
-import org.sonar.plugins.core.widgets.TimeMachineWidget;
-import org.sonar.plugins.core.widgets.TimelineWidget;
-import org.sonar.plugins.core.widgets.TreemapWidget;
+import org.sonar.plugins.core.widgets.*;
import org.sonar.plugins.core.widgets.actionPlans.ActionPlansWidget;
-import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.PlannedReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.ProjectReviewsWidget;
-import org.sonar.plugins.core.widgets.reviews.ReviewsMetricsWidget;
-import org.sonar.plugins.core.widgets.reviews.ReviewsPerDeveloperWidget;
-import org.sonar.plugins.core.widgets.reviews.UnplannedReviewsWidget;
+import org.sonar.plugins.core.widgets.reviews.*;
import java.util.List;
@SuppressWarnings("unchecked")
public List<Class<? extends Extension>> getExtensions() {
return ImmutableList.of(
- DefaultResourceTypes.class,
- UserManagedMetrics.class,
- ProjectFileSystemLogger.class,
+ DefaultResourceTypes.class,
+ UserManagedMetrics.class,
+ ProjectFileSystemLogger.class,
- // maven
- MavenInitializer.class,
+ // maven
+ MavenInitializer.class,
- // languages
- Java.class,
+ // languages
+ Java.class,
- // pages
- TestsViewerDefinition.class,
- Lcom4Viewer.class,
+ // pages
+ TestsViewerDefinition.class,
+ Lcom4Viewer.class,
- // filters
- ProjectFilter.class,
- TreeMapFilter.class,
- MyFavouritesFilter.class,
+ // filters
+ ProjectFilter.class,
+ TreeMapFilter.class,
+ MyFavouritesFilter.class,
- // widgets
- AlertsWidget.class,
- CoverageWidget.class,
- ItCoverageWidget.class,
- CommentsDuplicationsWidget.class,
- DescriptionWidget.class,
- ComplexityWidget.class,
- RulesWidget.class,
- SizeWidget.class,
- EventsWidget.class,
- CustomMeasuresWidget.class,
- TimelineWidget.class,
- TimeMachineWidget.class,
- HotspotMetricWidget.class,
- HotspotMostViolatedResourcesWidget.class,
- HotspotMostViolatedRulesWidget.class,
- MyReviewsWidget.class,
- ProjectReviewsWidget.class,
- FalsePositiveReviewsWidget.class,
- ReviewsPerDeveloperWidget.class,
- PlannedReviewsWidget.class,
- UnplannedReviewsWidget.class,
- ActionPlansWidget.class,
- ReviewsMetricsWidget.class,
- TreemapWidget.class,
- FilterWidget.class,
+ // widgets
+ AlertsWidget.class,
+ CoverageWidget.class,
+ ItCoverageWidget.class,
+ CommentsDuplicationsWidget.class,
+ DescriptionWidget.class,
+ ComplexityWidget.class,
+ RulesWidget.class,
+ SizeWidget.class,
+ EventsWidget.class,
+ CustomMeasuresWidget.class,
+ TimelineWidget.class,
+ TimeMachineWidget.class,
+ HotspotMetricWidget.class,
+ HotspotMostViolatedResourcesWidget.class,
+ HotspotMostViolatedRulesWidget.class,
+ MyReviewsWidget.class,
+ ProjectReviewsWidget.class,
+ FalsePositiveReviewsWidget.class,
+ ReviewsPerDeveloperWidget.class,
+ PlannedReviewsWidget.class,
+ UnplannedReviewsWidget.class,
+ ActionPlansWidget.class,
+ ReviewsMetricsWidget.class,
+ TreemapWidget.class,
+ FilterWidget.class,
- // dashboards
- DefaultDashboard.class,
- HotspotsDashboard.class,
- ReviewsDashboard.class,
- TimeMachineDashboard.class,
- ProjectsDashboard.class,
- TreemapDashboard.class,
- MyFavouritesDashboard.class,
+ // dashboards
+ DefaultDashboard.class,
+ HotspotsDashboard.class,
+ ReviewsDashboard.class,
+ TimeMachineDashboard.class,
+ ProjectsDashboard.class,
+ TreemapDashboard.class,
+ MyFavouritesDashboard.class,
- // chart
- XradarChart.class,
- DistributionBarChart.class,
- DistributionAreaChart.class,
+ // chart
+ XradarChart.class,
+ DistributionBarChart.class,
+ DistributionAreaChart.class,
- // colorizers
- JavaColorizerFormat.class,
+ // colorizers
+ JavaColorizerFormat.class,
- // batch
- ProfileSensor.class,
- ProfileEventsSensor.class,
- ProjectLinksSensor.class,
- UnitTestDecorator.class,
- VersionEventsSensor.class,
- CheckAlertThresholds.class,
- GenerateAlertEvents.class,
- ViolationsDecorator.class,
- WeightedViolationsDecorator.class,
- ViolationsDensityDecorator.class,
- LineCoverageDecorator.class,
- CoverageDecorator.class,
- BranchCoverageDecorator.class,
- ItLineCoverageDecorator.class,
- ItCoverageDecorator.class,
- ItBranchCoverageDecorator.class,
- ApplyProjectRolesDecorator.class,
- ExcludedResourceFilter.class,
- CommentDensityDecorator.class,
- NoSonarFilter.class,
- DirectoriesDecorator.class,
- FilesDecorator.class,
- ReviewNotifications.class,
- ReviewWorkflowDecorator.class,
- ReferenceAnalysis.class,
- ManualMeasureDecorator.class,
- ManualViolationInjector.class,
- ViolationSeverityUpdater.class,
- IndexProjectPostJob.class,
- ReviewsMeasuresDecorator.class,
+ // batch
+ ProfileSensor.class,
+ ProfileEventsSensor.class,
+ ProjectLinksSensor.class,
+ UnitTestDecorator.class,
+ VersionEventsSensor.class,
+ CheckAlertThresholds.class,
+ GenerateAlertEvents.class,
+ ViolationsDecorator.class,
+ WeightedViolationsDecorator.class,
+ ViolationsDensityDecorator.class,
+ LineCoverageDecorator.class,
+ CoverageDecorator.class,
+ BranchCoverageDecorator.class,
+ ItLineCoverageDecorator.class,
+ ItCoverageDecorator.class,
+ ItBranchCoverageDecorator.class,
+ DefaultResourcePermissioning.class,
+ ApplyProjectRolesDecorator.class,
+ ExcludedResourceFilter.class,
+ CommentDensityDecorator.class,
+ NoSonarFilter.class,
+ DirectoriesDecorator.class,
+ FilesDecorator.class,
+ ReviewNotifications.class,
+ ReviewWorkflowDecorator.class,
+ ReferenceAnalysis.class,
+ ManualMeasureDecorator.class,
+ ManualViolationInjector.class,
+ ViolationSeverityUpdater.class,
+ IndexProjectPostJob.class,
+ ReviewsMeasuresDecorator.class,
- // time machine
- TendencyDecorator.class,
- VariationDecorator.class,
- ViolationTrackingDecorator.class,
- ViolationPersisterDecorator.class,
- NewViolationsDecorator.class,
- TimeMachineConfigurationPersister.class,
- NewCoverageFileAnalyzer.class,
- NewItCoverageFileAnalyzer.class,
- NewCoverageAggregator.class);
+ // time machine
+ TendencyDecorator.class,
+ VariationDecorator.class,
+ ViolationTrackingDecorator.class,
+ ViolationPersisterDecorator.class,
+ NewViolationsDecorator.class,
+ TimeMachineConfigurationPersister.class,
+ NewCoverageFileAnalyzer.class,
+ NewItCoverageFileAnalyzer.class,
+ NewCoverageAggregator.class);
}
}
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.database.DatabaseSession;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
+import org.sonar.api.security.ResourcePermissioning;
public class ApplyProjectRolesDecorator implements Decorator {
- private RoleManager roleManager;
+ private final ResourcePermissioning resourcePermissioning;
- ApplyProjectRolesDecorator(RoleManager roleManager) {
- this.roleManager = roleManager;
- }
-
- public ApplyProjectRolesDecorator(DatabaseSession session) {
- this.roleManager = new RoleManager(session);
+ public ApplyProjectRolesDecorator(ResourcePermissioning resourcePermissioning) {
+ this.resourcePermissioning = resourcePermissioning;
}
public boolean shouldExecuteOnProject(Project project) {
public void decorate(Resource resource, DecoratorContext context) {
if (shouldDecorateResource(resource)) {
- Project project = (Project) resource;
- roleManager.affectDefaultRolesToResource(project.getId());
+ resourcePermissioning.grantDefaultPermissions(resource);
}
}
private boolean shouldDecorateResource(Resource resource) {
- if (isProject(resource)) {
- Project project = (Project) resource;
- return project.getId() != null && countRoles(project.getId()) == 0;
- }
- return false;
+ return resource.getId() != null && isProject(resource) && !resourcePermissioning.hasPermissions(resource);
}
private boolean isProject(Resource resource) {
- if (Qualifiers.PROJECT.equals(resource.getQualifier()) ||
- Qualifiers.VIEW.equals(resource.getQualifier()) ||
- Qualifiers.SUBVIEW.equals(resource.getQualifier())) {
- return resource instanceof Project;
- }
- return false;
- }
-
- private int countRoles(int resourceId) {
- return roleManager.getUserRoles(resourceId).size() + roleManager.getGroupRoles(resourceId).size();
+ return Qualifiers.PROJECT.equals(resource.getQualifier()) || Qualifiers.VIEW.equals(resource.getQualifier());
}
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.security;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.security.DefaultGroups;
+import org.sonar.api.security.ResourcePermissioning;
+import org.sonar.api.web.UserRole;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.user.*;
+
+/**
+ * @since 3.2
+ */
+@Properties({
+ @Property(key = "sonar.role." + UserRole.ADMIN + ".TRK.defaultGroups",
+ name = "Default groups for project administrators",
+ defaultValue = DefaultGroups.ADMINISTRATORS,
+ global = false,
+ project = false),
+ @Property(key = "sonar.role." + UserRole.USER + ".TRK.defaultGroups",
+ name = "Default groups for project users",
+ defaultValue = DefaultGroups.USERS + "," + DefaultGroups.ANYONE,
+ global = false,
+ project = false),
+ @Property(key = "sonar.role." + UserRole.CODEVIEWER + ".TRK.defaultGroups",
+ name = "Default groups for project code viewers",
+ defaultValue = DefaultGroups.USERS + "," + DefaultGroups.ANYONE,
+ global = false,
+ project = false)
+})
+public class DefaultResourcePermissioning implements ResourcePermissioning, BatchExtension {
+
+ private final Settings settings;
+ private final MyBatis myBatis;
+
+ public DefaultResourcePermissioning(Settings settings, MyBatis myBatis) {
+ this.settings = settings;
+ this.myBatis = myBatis;
+ }
+
+ public boolean hasPermissions(Resource resource) {
+ if (resource.getId() != null) {
+ SqlSession session = myBatis.openSession();
+ try {
+ RoleMapper roleMapper = session.getMapper(RoleMapper.class);
+ Long resourceId = new Long(resource.getId());
+ return roleMapper.countGroupRoles(resourceId) + roleMapper.countUserRoles(resourceId) > 0;
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+ return false;
+ }
+
+ public void addUserPermissions(Resource resource, String login, String role) {
+ if (resource.getId() != null) {
+ SqlSession session = myBatis.openSession();
+ try {
+ UserDto user = session.getMapper(UserMapper.class).selectUserByLogin(login);
+ if (user != null) {
+ UserRoleDto userRole = new UserRoleDto()
+ .setRole(role)
+ .setUserId(user.getId())
+ .setResourceId(new Long(resource.getId()));
+ session.getMapper(RoleMapper.class).insertUserRole(userRole);
+ session.commit();
+ }
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+ }
+
+ public void addGroupPermissions(Resource resource, String groupName, String role) {
+ if (resource.getId() != null) {
+ SqlSession session = myBatis.openSession();
+ try {
+ GroupRoleDto groupRole = new GroupRoleDto()
+ .setRole(role)
+ .setResourceId(new Long(resource.getId()));
+ if (DefaultGroups.isAnyone(groupName)) {
+ session.getMapper(RoleMapper.class).insertGroupRole(groupRole);
+ session.commit();
+ } else {
+ GroupDto group = session.getMapper(UserMapper.class).selectGroupByName(groupName);
+ if (group != null) {
+ session.getMapper(RoleMapper.class).insertGroupRole(groupRole.setGroupId(group.getId()));
+ session.commit();
+ }
+ }
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+ }
+
+ public void grantDefaultPermissions(Resource resource) {
+ if (resource.getId() != null) {
+ SqlSession session = myBatis.openSession();
+ try {
+ removePermissions(resource, session);
+ grantDefaultPermissions(resource, UserRole.ADMIN, session);
+ grantDefaultPermissions(resource, UserRole.USER, session);
+ grantDefaultPermissions(resource, UserRole.CODEVIEWER, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+ }
+
+ private void removePermissions(Resource resource, SqlSession session) {
+ Long resourceId = new Long(resource.getId());
+ RoleMapper mapper = session.getMapper(RoleMapper.class);
+ mapper.deleteGroupRolesByResourceId(resourceId);
+ mapper.deleteUserRolesByResourceId(resourceId);
+ }
+
+ private void grantDefaultPermissions(Resource resource, String role, SqlSession session) {
+ UserMapper userMapper = session.getMapper(UserMapper.class);
+ RoleMapper roleMapper = session.getMapper(RoleMapper.class);
+ String[] groupNames = settings.getStringArrayBySeparator("sonar.role." + role + "." + resource.getQualifier() + ".defaultGroups", ",");
+ for (String groupName : groupNames) {
+ GroupRoleDto groupRole = new GroupRoleDto().setRole(role).setResourceId(new Long(resource.getId()));
+ if (DefaultGroups.isAnyone(groupName)) {
+ roleMapper.insertGroupRole(groupRole);
+ } else {
+ GroupDto group = userMapper.selectGroupByName(groupName);
+ if (group != null) {
+ roleMapper.insertGroupRole(groupRole.setGroupId(group.getId()));
+ }
+ }
+ }
+
+ String[] logins = settings.getStringArrayBySeparator("sonar.role." + role + "." + resource.getQualifier() + ".defaultUsers", ",");
+ for (String login : logins) {
+ UserDto user = userMapper.selectUserByLogin(login);
+ if (user != null) {
+ roleMapper.insertUserRole(new UserRoleDto().setRole(role).setUserId(user.getId()).setResourceId(new Long(resource.getId())));
+ }
+ }
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.core.security;
-
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.security.GroupRole;
-import org.sonar.api.security.UserRole;
-
-import javax.persistence.Query;
-import java.util.List;
-
-/**
- * @since 1.12
- */
-public class RoleManager {
-
- protected static final String DEFAULT_ROLE_PREFIX = "default-";
- private DatabaseSession session;
-
- public RoleManager(DatabaseSession session) {
- this.session = session;
- }
-
- public void affectDefaultRolesToResource(int resourceId) {
- for (UserRole defaultRole : getDefaultUserRoles()) {
- session.save(createResourceRoleFromDefault(defaultRole, resourceId));
- }
- for (GroupRole defaultRole : getDefaultGroupRoles()) {
- session.save(createResourceRoleFromDefault(defaultRole, resourceId));
- }
- session.commit();
- }
-
- public List<UserRole> getUserRoles(int resourceId) {
- return session.getResults(UserRole.class, "resourceId", resourceId);
- }
-
- public List<GroupRole> getGroupRoles(int resourceId) {
- return session.getResults(GroupRole.class, "resourceId", resourceId);
- }
-
- protected List<UserRole> getDefaultUserRoles() {
- final Query query = session.createQuery("from " + UserRole.class.getSimpleName() + " ur where ur.resourceId is null and ur.role like '" + DEFAULT_ROLE_PREFIX + "%'");
- return query.getResultList();
- }
-
- protected List<GroupRole> getDefaultGroupRoles() {
- final Query query = session.createQuery("from " + GroupRole.class.getSimpleName() + " gr where gr.resourceId is null and gr.role like '" + DEFAULT_ROLE_PREFIX + "%'");
- return query.getResultList();
- }
-
- protected UserRole createResourceRoleFromDefault(UserRole defaultUserRole, int resourceId) {
- final UserRole result = new UserRole();
- result.setRole(convertDefaultRoleName(defaultUserRole.getRole()));
- result.setResourceId(resourceId);
- result.setUserId(defaultUserRole.getUserId());
- return result;
- }
-
- protected GroupRole createResourceRoleFromDefault(GroupRole defaultUserRole, int resourceId) {
- final GroupRole result = new GroupRole();
- result.setRole(convertDefaultRoleName(defaultUserRole.getRole()));
- result.setResourceId(resourceId);
- result.setGroupId(defaultUserRole.getGroupId());
- return result;
- }
-
- protected static String convertDefaultRoleName(String defaultRoleName) {
- return StringUtils.substringAfter(defaultRoleName, DEFAULT_ROLE_PREFIX);
- }
-}
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.Project;
-import org.sonar.api.security.GroupRole;
-
-import java.util.ArrayList;
-import java.util.Arrays;
+import org.sonar.api.security.ResourcePermissioning;
import static org.mockito.Mockito.*;
public class ApplyProjectRolesDecoratorTest {
- private RoleManager roleManager;
+ private ResourcePermissioning resourcePermissioning;
private ApplyProjectRolesDecorator decorator;
@Before
public void before() {
- roleManager = mock(RoleManager.class);
- decorator = new ApplyProjectRolesDecorator(roleManager);
+ resourcePermissioning = mock(ResourcePermissioning.class);
+ decorator = new ApplyProjectRolesDecorator(resourcePermissioning);
}
@Test
- public void doNotApplySecurityWhenExistingRoles() {
+ public void doNotApplySecurityWhenExistingPermissions() {
Project project = new Project("project");
project.setId(10);
- when(roleManager.getGroupRoles(10)).thenReturn(Arrays.<GroupRole>asList(new GroupRole()));
+ when(resourcePermissioning.hasPermissions(project)).thenReturn(true);
decorator.decorate(project, null);
- verify(roleManager, never()).affectDefaultRolesToResource(anyInt());
+ verify(resourcePermissioning, never()).grantDefaultPermissions(project);
}
@Test
Project project = new Project("project");
Project module = new Project("module").setParent(project);
module.setId(10);
-
- when(roleManager.getGroupRoles(10)).thenReturn(Arrays.<GroupRole>asList());
+ when(resourcePermissioning.hasPermissions(project)).thenReturn(false);
decorator.decorate(module, null);
- verify(roleManager, never()).affectDefaultRolesToResource(anyInt());
+ verify(resourcePermissioning, never()).grantDefaultPermissions(module);
}
@Test
- public void applySecurityWhenNoRoles() {
+ public void applySecurityWhenNoPermissions() {
Project project = new Project("project");
project.setId(10);
- when(roleManager.getGroupRoles(10)).thenReturn(new ArrayList<GroupRole>());
+ when(resourcePermissioning.hasPermissions(project)).thenReturn(false);
decorator.decorate(project, null);
- verify(roleManager).affectDefaultRolesToResource(10);
+ verify(resourcePermissioning).grantDefaultPermissions(project);
}
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.security;
+
+import org.junit.Test;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.security.DefaultGroups;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultResourcePermissioningTest extends AbstractDaoTestCase {
+
+ private Resource project = new Project("project").setId(123);
+
+ @Test
+ public void addGroupPermissions() {
+ setupData("addGroupPermissions");
+
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(new Settings(), getMyBatis());
+ permissioning.addGroupPermissions(project, "sonar-administrators", "admin");
+
+ checkTables("addGroupPermissions", "group_roles");
+ }
+
+ @Test
+ public void addGroupPermissions_anyone() {
+ setupData("addGroupPermissions_anyone");
+
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(new Settings(), getMyBatis());
+ permissioning.addGroupPermissions(project, DefaultGroups.ANYONE, "admin");
+
+ checkTables("addGroupPermissions_anyone", "group_roles");
+ }
+
+ @Test
+ public void addGroupPermissions_ignore_if_group_not_found() {
+ setupData("addGroupPermissions_ignore_if_group_not_found");
+
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(new Settings(), getMyBatis());
+ permissioning.addGroupPermissions(project, "not_found", "admin");
+
+ checkTables("addGroupPermissions_ignore_if_group_not_found", "group_roles");
+ }
+
+ @Test
+ public void addGroupPermissions_ignore_if_not_persisted() {
+ setupData("addGroupPermissions_ignore_if_not_persisted");
+
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(new Settings(), getMyBatis());
+ Project resourceWithoutId = new Project("");
+ permissioning.addGroupPermissions(resourceWithoutId, "sonar-users", "admin");
+
+ checkTables("addGroupPermissions_ignore_if_not_persisted", "group_roles");
+ }
+
+ @Test
+ public void grantDefaultPermissions() {
+ setupData("grantDefaultPermissions");
+
+ Settings settings = new Settings(new PropertyDefinitions(DefaultResourcePermissioning.class));
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(settings, getMyBatis());
+ permissioning.grantDefaultPermissions(project);
+
+ checkTables("grantDefaultPermissions", "user_roles", "group_roles");
+ }
+
+ @Test
+ public void grantDefaultPermissions_unknown_group() {
+ setupData("grantDefaultPermissions_unknown_group");
+
+ Settings settings = new Settings();
+ settings.setProperty("sonar.role.admin.TRK.defaultGroups", "sonar-administrators,unknown");
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(settings, getMyBatis());
+ permissioning.grantDefaultPermissions(project);
+
+ checkTables("grantDefaultPermissions_unknown_group", "group_roles");
+ }
+
+ @Test
+ public void grantDefaultPermissions_users() {
+ setupData("grantDefaultPermissions_users");
+
+ Settings settings = new Settings();
+ settings.setProperty("sonar.role.admin.TRK.defaultUsers", "marius,disabled,notfound");
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(settings, getMyBatis());
+ permissioning.grantDefaultPermissions(project);
+
+ checkTables("grantDefaultPermissions_users", "user_roles");
+ }
+
+ @Test
+ public void hasPermissions() {
+ setupData("hasPermissions");
+ DefaultResourcePermissioning permissioning = new DefaultResourcePermissioning(new Settings(), getMyBatis());
+
+ // no groups and at least one user
+ assertThat(permissioning.hasPermissions(new Project("only_users").setId(1))).isTrue();
+
+ // no users and at least one group
+ assertThat(permissioning.hasPermissions(new Project("only_groups").setId(2))).isTrue();
+
+ // groups and users
+ assertThat(permissioning.hasPermissions(new Project("groups_and_users").setId(3))).isTrue();
+
+ // no groups, no users
+ assertThat(permissioning.hasPermissions(new Project("no_groups_no_users").setId(4))).isFalse();
+
+ // does not exist
+ assertThat(permissioning.hasPermissions(new Project("not_found"))).isFalse();
+ }
+}
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.core.security;
-
-import org.junit.Test;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class RoleManagerTest extends AbstractDbUnitTestCase {
-
- @Test
- public void affectDefaultRolesToResource() {
- setupData("affectDefaultRolesToResource");
- new RoleManager(getSession()).affectDefaultRolesToResource(10);
- checkTables("affectDefaultRolesToResource", "user_roles", "group_roles");
- }
-
- @Test
- public void affectZeroDefaultRolesToResource() {
- setupData("affectZeroDefaultRolesToResource");
- new RoleManager(getSession()).affectDefaultRolesToResource(10);
- checkTables("affectZeroDefaultRolesToResource", "user_roles", "group_roles");
- }
-
- @Test
- public void affectAnyoneDefaultRoleToResource() {
- setupData("affectAnyoneDefaultRoleToResource");
- new RoleManager(getSession()).affectDefaultRolesToResource(10);
- checkTables("affectAnyoneDefaultRoleToResource", "group_roles");
- }
-
- @Test
- public void convertDefaultRoleName() {
- assertThat(RoleManager.convertDefaultRoleName(RoleManager.DEFAULT_ROLE_PREFIX + "admin"), is("admin"));
- }
-}
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+
+ <group_roles id="1" group_id="100" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+
+ <group_roles id="1" group_id="[null]" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+
+ <!-- already existed -->
+ <group_roles id="1" group_id="[null]" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+
+ <!-- already existed -->
+ <group_roles id="1" group_id="[null]" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+
+ <!-- already existed -->
+ <group_roles id="1" group_id="[null]" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+
+ <!-- already existed -->
+ <group_roles id="1" group_id="[null]" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+
+ <!--
+ new rows : sonar-administrators (admin), sonar-users (user & codeviewer), Anyone (user & codeviewer),
+ -->
+ <group_roles id="3" group_id="100" resource_id="123" role="admin"/>
+ <group_roles id="4" group_id="101" resource_id="123" role="user"/>
+ <group_roles id="5" group_id="[null]" resource_id="123" role="user"/>
+ <group_roles id="6" group_id="101" resource_id="123" role="codeviewer"/>
+ <group_roles id="7" group_id="[null]" resource_id="123" role="codeviewer"/>
+
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]" />
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+
+ <!--
+ new rows : sonar-administrators (admin)
+ -->
+ <group_roles id="3" group_id="100" resource_id="123" role="admin"/>
+
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]" />
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+ <users id="201" login="disabled" name="Disabled" email="[null]" active="[false]"/>
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+
+ <!--
+ new row : marius (admin)
+ -->
+ <user_roles id="2" user_id="200" resource_id="123" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators" />
+ <groups id="101" name="sonar-users" />
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]" />
+ <users id="201" login="disabled" name="Disabled" email="[null]" active="[false]" />
+
+ <!-- on other resources -->
+ <group_roles id="1" group_id="100" resource_id="1" role="admin"/>
+ <group_roles id="2" group_id="101" resource_id="1" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <!-- only_users -->
+ <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
+
+ <!-- only_groups -->
+ <group_roles id="1" group_id="100" resource_id="2" role="admin"/>
+
+ <!-- groups_and_users -->
+ <group_roles id="2" group_id="101" resource_id="3" role="user"/>
+ <user_roles id="2" user_id="200" resource_id="3" role="admin"/>
+
+</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- GROUPS ***************** -->
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <group_roles id="3" group_id="[null]" role="default-admin" resource_id="[null]" />
- <group_roles id="4" group_id="[null]" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
-
-
- <!-- new project role : group 'Anyone' has admin and viewer -->
- <group_roles id="6" group_id="[null]" role="admin" resource_id="10" />
- <group_roles id="7" group_id="[null]" role="viewer" resource_id="10" />
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- GROUPS ***************** -->
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <group_roles id="3" group_id="[null]" role="default-admin" resource_id="[null]" />
- <group_roles id="4" group_id="[null]" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- USERS ***************** -->
-
- <!-- global roles -->
- <user_roles id="1" user_id="1" role="admin" resource_id="[null]" />
- <user_roles id="2" user_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <user_roles id="3" user_id="1" role="default-admin" resource_id="[null]" />
- <user_roles id="4" user_id="1" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <user_roles id="5" user_id="5" role="admin" resource_id="7" />
-
-
- <!-- new project role -->
- <user_roles id="6" user_id="1" role="admin" resource_id="10" />
- <user_roles id="7" user_id="1" role="viewer" resource_id="10" />
-
-
- <!-- GROUPS ***************** -->
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <group_roles id="3" group_id="1" role="default-admin" resource_id="[null]" />
- <group_roles id="4" group_id="1" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
- <!-- new project roles -->
- <group_roles id="6" group_id="1" role="admin" resource_id="10" />
- <group_roles id="7" group_id="1" role="viewer" resource_id="10" />
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- USERS ***************** -->
-
- <!-- global roles -->
- <user_roles id="1" user_id="1" role="admin" resource_id="[null]" />
- <user_roles id="2" user_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <user_roles id="3" user_id="1" role="default-admin" resource_id="[null]" />
- <user_roles id="4" user_id="1" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <user_roles id="5" user_id="5" role="admin" resource_id="7" />
-
-
-
- <!-- GROUPS ***************** -->
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- default project roles -->
- <group_roles id="3" group_id="1" role="default-admin" resource_id="[null]" />
- <group_roles id="4" group_id="1" role="default-viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- USERS ***************** -->
-
- <!-- global roles -->
- <user_roles id="1" user_id="1" role="admin" resource_id="[null]" />
- <user_roles id="2" user_id="2" role="viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <user_roles id="5" user_id="5" role="admin" resource_id="7" />
-
- <!-- no default project roles -->
-
-
-
- <!-- GROUPS ***************** -->
-
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
- <!-- no default project roles -->
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <!-- USERS ***************** -->
-
- <!-- global roles -->
- <user_roles id="1" user_id="1" role="admin" resource_id="[null]" />
- <user_roles id="2" user_id="2" role="viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <user_roles id="5" user_id="5" role="admin" resource_id="7" />
-
- <!-- no default project roles -->
-
-
-
- <!-- GROUPS ***************** -->
-
- <!-- global roles -->
- <group_roles id="1" group_id="1" role="admin" resource_id="[null]" />
- <group_roles id="2" group_id="2" role="viewer" resource_id="[null]" />
-
- <!-- existing project roles -->
- <group_roles id="5" group_id="5" role="admin" resource_id="7" />
-
- <!-- no default project roles -->
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <projects id="10" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="[null]"
- root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"
- long_name="[null]" />
-</dataset>
\ No newline at end of file
email_configuration.page=Email Settings
event_categories.page=Event Categories
filters.page=Filters
-global_roles.page=Global Roles
+system_administrators.page=System Administrators
manual_metrics.page=Manual Metrics
manual_measures.page=Manual Measures
manual_rules.page=Manual Rules
my_profile.page=My Profile
-project_roles.page=Project Roles
+roles.page=Roles
project_settings.page=Settings
project_links.page=Links
project_exclusions.page=Exclusions
violations_drilldown.page=Violations Drilldown
update_center.page=Update Center
lcom4_viewer.page=LCOM4
-dependencies.page=Dependencies
resource_deletion.page={0} Deletion
update_key.page=Update Key
project_quality_profile.page=Quality Profile
<configuration>
<runOrder>random</runOrder>
<argLine>-Xmx256m -Djava.awt.headless=true</argLine>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
</systemPropertyVariables>
import org.sonar.core.rule.RuleDao;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.user.AuthorDao;
-import org.sonar.core.user.RoleDao;
import org.sonar.core.user.UserDao;
import java.util.List;
ResourceKeyUpdaterDao.class,
ReviewCommentDao.class,
ReviewDao.class,
- RoleDao.class,
RuleDao.class,
UserDao.class);
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.user;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.core.persistence.MyBatis;
-
-import java.util.Collection;
-
-/**
- * @since 3.2
- */
-public class RoleDao {
- private final MyBatis mybatis;
-
- public RoleDao(MyBatis mybatis) {
- this.mybatis = mybatis;
- }
-
- public RoleDao insertGroupRoles(Collection<GroupRoleDto> groupRoles) {
- SqlSession session = mybatis.openBatchSession();
- try {
- RoleMapper mapper = session.getMapper(RoleMapper.class);
- for (GroupRoleDto groupRole : groupRoles) {
- mapper.insertGroupRole(groupRole);
- }
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- return this;
- }
-
- public RoleDao insertUserRoles(Collection<UserRoleDto> userRoles) {
- SqlSession session = mybatis.openBatchSession();
- try {
- RoleMapper mapper = session.getMapper(RoleMapper.class);
- for (UserRoleDto userRole : userRoles) {
- mapper.insertUserRole(userRole);
- }
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- return this;
- }
-}
void insertUserRole(UserRoleDto userRole);
+ void deleteGroupRolesByResourceId(Long resourceId);
+
+ void deleteUserRolesByResourceId(Long resourceId);
+
+ int countGroupRoles(Long resourceId);
+
+ int countUserRoles(Long resourceId);
}
<class>org.sonar.api.database.model.ResourceModel</class>
<class>org.sonar.api.database.model.SnapshotSource</class>
<class>org.sonar.api.database.model.RuleFailureModel</class>
- <class>org.sonar.api.security.UserRole</class>
- <class>org.sonar.api.security.GroupRole</class>
<class>org.sonar.api.rules.Rule</class>
<class>org.sonar.api.rules.RuleParam</class>
<class>org.sonar.api.resources.ProjectLink</class>
INSERT INTO GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (1, 1, null, 'admin');
ALTER TABLE GROUP_ROLES ALTER COLUMN ID RESTART WITH 2;
-INSERT INTO PROPERTIES(ID, PROP_KEY, RESOURCE_ID, TEXT_VALUE, USER_ID) VALUES (1, 'sonar.role.admin.project.defaultGroups', null, 'sonar-administrators', null);
-INSERT INTO PROPERTIES(ID, PROP_KEY, RESOURCE_ID, TEXT_VALUE, USER_ID) VALUES (2, 'sonar.role.user.project.defaultGroups', null, 'sonar-users,Anyone', null);
-INSERT INTO PROPERTIES(ID, PROP_KEY, RESOURCE_ID, TEXT_VALUE, USER_ID) VALUES (3, 'sonar.role.codeviewer.project.defaultGroups', null, 'sonar-users,Anyone', null);
-ALTER TABLE PROPERTIES ALTER COLUMN ID RESTART WITH 4;
-
INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1);
INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2);
INSERT INTO user_roles (user_id, resource_id, role)
VALUES (#{userId, jdbcType=INTEGER}, #{resourceId, jdbcType=INTEGER}, #{role, jdbcType=VARCHAR})
</insert>
+
+ <delete id="deleteGroupRolesByResourceId" parameterType="long">
+ delete from group_roles where resource_id=#{id}
+ </delete>
+
+ <delete id="deleteUserRolesByResourceId" parameterType="long">
+ delete from user_roles where resource_id=#{id}
+ </delete>
+
+ <select id="countUserRoles" parameterType="long" resultType="int">
+ SELECT count(id)
+ FROM user_roles WHERE resource_id=#{id}
+ </select>
+
+ <select id="countGroupRoles" parameterType="long" resultType="int">
+ SELECT count(id)
+ FROM group_roles WHERE resource_id=#{id}
+ </select>
</mapper>
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.user;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-
-public class RoleDaoTest extends DaoTestCase {
-
- private RoleDao dao;
-
- @Before
- public void setUp() {
- dao = new RoleDao(getMyBatis());
- }
-
- @Test
- public void insertGroupRoles() {
- setupData("insertGroupRoles");
-
- Collection<GroupRoleDto> groupRoles = Arrays.asList(
- new GroupRoleDto().setGroupId(100L).setResourceId(200L).setRole("admin"),
-
- // no group id => Anyone
- new GroupRoleDto().setResourceId(200L).setRole("user")
- );
- dao.insertGroupRoles(groupRoles);
-
- checkTables("insertGroupRoles", "group_roles");
- }
-
- @Test
- public void insertUserRoles() {
- setupData("insertUserRoles");
-
- Collection<UserRoleDto> userRoles = Arrays.asList(
- new UserRoleDto().setUserId(100L).setResourceId(200L).setRole("admin"),
- new UserRoleDto().setUserId(101L).setResourceId(200L).setRole("user")
- );
- dao.insertUserRoles(userRoles);
-
- checkTables("insertUserRoles", "user_roles");
- }
-}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.fest.assertions.Assertions.assertThat;
-public class UserDaoTest extends DaoTestCase {
+public class UserDaoTest extends AbstractDaoTestCase {
private UserDao dao;
+++ /dev/null
-<dataset>
- <group_roles id="1" group_id="100" resource_id="200" role="admin"/>
- <group_roles id="2" group_id="[null]" resource_id="200" role="user"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <user_roles id="1" user_id="100" resource_id="200" role="admin"/>
- <user_roles id="2" user_id="101" resource_id="200" role="user"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-</dataset>
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.security;
+
+/**
+ * Name of the default user groups
+ *
+ * @since 3.2
+ */
+public final class DefaultGroups {
+ private DefaultGroups() {
+ }
+
+ public static final String ANYONE = "Anyone";
+ public static final String ADMINISTRATORS = "sonar-administrators";
+ public static final String USERS = "sonar-users";
+
+ public static boolean isAnyone(String groupName) {
+ return ANYONE.equalsIgnoreCase(groupName);
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.security;
-
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.database.BaseIdentifiable;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
-/**
- * @since 1.12
- */
-@Entity
-@Table(name = "group_roles")
-public class GroupRole extends BaseIdentifiable {
-
- public static final Integer ANYONE_GROUP_ID = null;
-
- @Column(name = "group_id")
- private Integer groupId;
-
- @Column(name = "role")
- private String role;
-
- @Column(name = "resource_id")
- private Integer resourceId;
-
- public static GroupRole buildGlobalRole(Integer groupId, String role) {
- return new GroupRole().setGroupId(groupId).setRole(role);
- }
-
- public static GroupRole buildResourceRole(Integer groupId, String role, Integer resourceId) {
- return new GroupRole().setGroupId(groupId).setRole(role).setResourceId(resourceId);
- }
-
- public Integer getGroupId() {
- return groupId;
- }
-
- public GroupRole setGroupId(Integer groupId) {
- this.groupId = groupId;
- return this;
- }
-
- public String getRole() {
- return role;
- }
-
- public GroupRole setRole(String role) {
- this.role = role;
- return this;
- }
-
- public Integer getResourceId() {
- return resourceId;
- }
-
- public GroupRole setResourceId(Integer resourceId) {
- this.resourceId = resourceId;
- return this;
- }
-
- public boolean isAnyone() {
- return groupId == null;
- }
-
- @Override
- public String toString() {
- return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.security;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.resources.Resource;
+
+/**
+ * Grant access to newly created projects.
+ *
+ * <p>This component is not supposed to be called by standard plugins.</p>
+ *
+ * @since 3.2
+ */
+public interface ResourcePermissioning extends BatchComponent {
+
+ boolean hasPermissions(Resource resource);
+
+ void grantDefaultPermissions(Resource resource);
+
+ void addUserPermissions(Resource resource, String login, String role);
+
+ void addGroupPermissions(Resource resource, String groupName, String role);
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.security;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.database.BaseIdentifiable;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
-/**
- * This JPA model maps the table user_roles
- *
- * @since 1.12
- */
-@Entity
-@Table(name = "user_roles")
-public class UserRole extends BaseIdentifiable {
-
- @Column(name = "user_id")
- private Integer userId;
-
- @Column(name = "role")
- private String role;
-
- @Column(name = "resource_id")
- private Integer resourceId;
-
- public UserRole(Integer userId, String role, Integer resourceId) {
- this.userId = userId;
- this.role = role;
- this.resourceId = resourceId;
- }
-
- public UserRole() {
- }
-
- public Integer getUserId() {
- return userId;
- }
-
- public UserRole setUserId(Integer userId) {
- this.userId = userId;
- return this;
- }
-
- public String getRole() {
- return role;
- }
-
- public UserRole setRole(String role) {
- this.role = role;
- return this;
- }
-
- public Integer getResourceId() {
- return resourceId;
- }
-
- public UserRole setResourceId(Integer resourceId) {
- this.resourceId = resourceId;
- return this;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.security;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultGroupsTest {
+ @Test
+ public void isAnyone_is_not_case_sensitive() {
+ assertThat(DefaultGroups.isAnyone("ANYONE")).isTrue();
+ assertThat(DefaultGroups.isAnyone("anyone")).isTrue();
+ assertThat(DefaultGroups.isAnyone(DefaultGroups.ANYONE)).isTrue();
+
+ assertThat(DefaultGroups.isAnyone(DefaultGroups.ADMINISTRATORS)).isFalse();
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.security;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class GroupRoleTest {
-
- @Test
- public void isAnyone() {
- GroupRole gr = GroupRole.buildGlobalRole(GroupRole.ANYONE_GROUP_ID, "admin");
- assertThat(gr.isAnyone(), is(true));
-
- gr = GroupRole.buildGlobalRole(3, "admin");
- assertThat(gr.isAnyone(), is(false));
- }
-}
PER_PAGE = 2
before_filter :admin_required
- verify :method => :post, :only => [:grant_users, :grant_groups], :redirect_to => {:action => 'global'}
+ verify :method => :post, :only => [:set_users, :set_groups, :set_default_project_groups, :set_default_project_users], :redirect_to => {:action => 'global'}
+
+
+ # GET REQUESTS
def global
end
end
@qualifier = params[:qualifier] || 'TRK'
+
conditions_sql = 'projects.enabled=:enabled and projects.qualifier=:qualifier and projects.copy_resource_id is null'
conditions_values = {:enabled => true, :qualifier => @qualifier}
-
+ joins = nil
if params[:q].present?
- conditions_sql += ' and projects.id in (select ri.resource_id from resource_index ri where ri.qualifier=:qualifier and ri.kee like :search)'
- conditions_values[:search]="#{params[:q].downcase}%"
+ joins = "INNER JOIN resource_index on resource_index.resource_id=projects.id and resource_index.qualifier=#{ActiveRecord::Base::sanitize(@qualifier)} and resource_index.kee like #{ActiveRecord::Base::sanitize(params[:q] + '%')}"
end
@pagination = Api::Pagination.new(params)
@projects=Project.find(:all,
- :include => %w(user_roles group_roles index),
+ :joins => joins,
:conditions => [conditions_sql, conditions_values],
- :order => 'resource_index.kee',
+ :order => 'projects.name',
:offset => @pagination.offset,
:limit => @pagination.limit)
- @pagination.count=Project.count(:conditions => [conditions_sql, conditions_values])
+ @pagination.count=Project.count(:joins => joins, :conditions => [conditions_sql, conditions_values])
end
def edit_users
- @project=Project.by_key(params[:resource]) if !params[:resource].blank?
+ @project=Project.by_key(params[:resource]) if params[:resource].present?
@role = params[:role]
end
def edit_groups
- @project=Project.by_key(params[:resource]) if !params[:resource].blank?
+ @project=Project.by_key(params[:resource]) if params[:resource].present?
@role = params[:role]
end
- def grant_users
+ def edit_default_project_groups
+ bad_request('Missing role') if params[:role].blank?
+ bad_request('Missing qualifier') if params[:qualifier].blank?
+ end
+
+ def edit_default_project_users
+ bad_request('Missing role') if params[:role].blank?
+ bad_request('Missing qualifier') if params[:qualifier].blank?
+ end
+
+ # POST REQUESTS
+
+ def set_users
+ bad_request('Missing role') if params[:role].blank?
UserRole.grant_users(params[:users], params[:role], params[:resource])
redirect
end
- def grant_groups
+ def set_groups
+ bad_request('Missing role') if params[:role].blank?
GroupRole.grant_groups(params[:groups], params[:role], params[:resource])
redirect
end
+ def set_default_project_groups
+ bad_request('Missing role') if params[:role].blank?
+ bad_request('Missing qualifier') if params[:qualifier].blank?
+ Property.set("sonar.role.#{params[:role]}.#{params[:qualifier]}.defaultGroups", params[:groups].join(','))
+ redirect
+ end
+
+ def set_default_project_users
+ bad_request('Missing role') if params[:role].blank?
+ bad_request('Missing qualifier') if params[:qualifier].blank?
+ Property.set("sonar.role.#{params[:role]}.#{params[:qualifier]}.defaultUsers", params[:users].join(','))
+ redirect
+ end
+
private
def redirect
redirect_to(:action => params['redirect'] || 'global', :q => params[:q], :qualifier => params[:qualifier], :page => params[:page])
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
module RolesHelper
-
+
def users(role, resource_id=nil)
resource_id=(resource_id.blank? ? nil : resource_id.to_i)
user_roles=UserRole.find(:all, :include => 'user', :conditions => {:role => role, :resource_id => resource_id})
users = user_roles.map { |ur| ur.user }
- Api::Utils.insensitive_sort(users) {|user| user.name}
+ Api::Utils.insensitive_sort(users) { |user| user.name }
end
def all_users
users = User.find(:all, :conditions => ["active=?", true])
- Api::Utils.insensitive_sort(users) {|user| user.name}
+ Api::Utils.insensitive_sort(users) { |user| user.name }
end
def groups(role, resource_id=nil)
resource_id=(resource_id.blank? ? nil : resource_id.to_i)
group_roles=GroupRole.find(:all, :include => 'group', :conditions => {:role => role, :resource_id => resource_id})
- groups = group_roles.map{|ur| ur.group}
- Api::Utils.insensitive_sort(groups) {|group| group ? group.name : ''}
+ groups = group_roles.map { |ur| ur.group }
+ Api::Utils.insensitive_sort(groups) { |group| group ? group.name : '' }
end
def all_groups
- [nil].concat(Api::Utils.insensitive_sort(Group.all) {|group| group.name})
+ [nil].concat(Api::Utils.insensitive_sort(Group.all) { |group| group.name })
end
def group_name(group)
group ? group.name : 'Anyone'
end
+ def default_project_groups(role, qualifier)
+ property_value=(controller.java_facade.getConfigurationValue("sonar.role.#{role}.#{qualifier}.defaultGroups")||'')
+ Api::Utils.insensitive_sort(property_value.split(','))
+ end
+
+ def default_project_users(role, qualifier)
+ property_value=(controller.java_facade.getConfigurationValue("sonar.role.#{role}.#{qualifier}.defaultUsers") || '')
+ Api::Utils.insensitive_sort(property_value.split(','))
+ end
+
def role_name(role)
- case(role.to_s)
- when 'admin' then 'Administrators'
- when 'default-admin' then 'Administrators'
- when 'user' then 'Users'
- when 'default-user' then 'Users'
- when 'codeviewer' then 'Code viewers'
- when 'default-codeviewer' then 'Code viewers'
- else role.to_s
+ case (role.to_s)
+ when 'admin' then
+ 'Administrators'
+ when 'user' then
+ 'Users'
+ when 'codeviewer' then
+ 'Code viewers'
+ else
+ role.to_s
end
end
end
<% end %>
<% if (@project.project? || @project.view? || @project.subview?) %>
<li class="<%= 'selected' if request.request_uri.include?('/project_roles') -%>">
- <a href="<%= ApplicationController.root_context -%>/project_roles/index?resource=<%= @project.id -%>"><%= message('project_roles.page') -%></a></li>
+ <a href="<%= ApplicationController.root_context -%>/project_roles/index?resource=<%= @project.id -%>"><%= message('roles.page') -%></a></li>
<% end %>
<%
# NOTE: we keep "@project.view? || @project.subview?" in the test for backward compatibility with the Views plugin
<li class="<%= 'selected' if request.request_uri.include?('/groups') -%>">
<a href="<%= ApplicationController.root_context -%>/groups/index"><%= message('user_groups.page') -%></a></li>
<li class="<%= 'selected' if request.request_uri.include?('/roles/global') -%>">
- <a href="<%= ApplicationController.root_context -%>/roles/global"><%= message('global_roles.page') -%></a></li>
+ <a href="<%= ApplicationController.root_context -%>/roles/global"><%= message('system_administrators.page') -%></a></li>
<li class="<%= 'selected' if request.request_uri.include?('/roles/projects') -%>">
- <a href="<%= ApplicationController.root_context -%>/roles/projects"><%= message('project_roles.page') -%></a></li>
+ <a href="<%= ApplicationController.root_context -%>/roles/projects"><%= message('roles.page') -%></a></li>
<li class="h2"><%= message('sidebar.system') -%></li>
<li class="<%= 'selected' if request.request_uri.include?('/settings') -%>">
--- /dev/null
+<%
+ granted_groups=default_project_groups(params[:role], params[:qualifier])
+ all_groups = ['Anyone'].concat(Api::Utils.insensitive_sort(Group.all.map{|group| group.name}))
+ ungranted_groups=all_groups - granted_groups
+%>
+<div class="subtitle">» <a href="<%= url_for :action => params[:redirect], :q => params[:q], :qualifier => params[:qualifier] -%>">Back</a></div>
+<h1>TO BE DEFINED</h1>
+<br/>
+<div>
+ <form action="<%= url_for :action => 'set_default_project_groups' -%>" method="POST">
+ <input name="role" value="<%= params[:role] -%>" type="hidden"/>
+ <input name="redirect" value="projects" type="hidden"/>
+ <input name="q" value="<%= params[:q] -%>" type="hidden" />
+ <input name="qualifier" value="<%= params[:qualifier] -%>" type="hidden" />
+ <input name="page" value="<%= params[:page] -%>" type="hidden" />
+ <table>
+ <tbody>
+ <tr>
+ <td style="padding: 5px 0;" valign="top">
+ <h2>Ungranted groups</h2>
+ <select name="from" id="from" size="20" style="margin: 5px 0; width: 300px;" multiple="multiple">
+ <% ungranted_groups.each do |group| %>
+ <option value="<%= h group -%>"><%= group -%></option>
+ <% end %>
+ </select>
+ </td>
+ <td style="padding: 0 10px;" align="center">
+ <button id="select_right" onclick="SelectBox.move('from', 'to');SelectBox.sort('to');SelectBox.redisplay('to');return false;">select >></button><br>
+ <button id="select_right_all" onclick="SelectBox.move_all('from', 'to');return false;">select all >></button><br><br>
+ <button id="select_left" onclick="SelectBox.move('to', 'from');return false;"><< unselect</button><br>
+ <button id="select_left_all" onclick="SelectBox.move_all('to', 'from');return false;"><< unselect all</button>
+ </td>
+ <td class="box" style="padding: 5px 10px;" valign="top">
+ <h2>Role: <%= role_name(params[:role]) -%></h2>
+
+ <select name="groups[]" id="to" size="20" multiple="multiple" style="margin: 5px 0; width: 300px;">
+ <% granted_groups.each do |group| %>
+ <option value="<%= h group -%>"><%= group -%></option>
+ <% end %>
+ </select><br>
+
+ <div style="padding: 5px 0;">
+ <input id="save" value="Save" onclick="SelectBox.select_all('to');submit();return false;" type="submit">
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </form>
+ <script>
+ SelectBox.init('from');
+ SelectBox.init('to');
+ </script>
+</div>
ungranted_groups=all_groups - granted_groups
if @project
title=h(@project.name)
- elsif @role.starts_with?('default-')
- title="Default project #{role_name(@role)}"
else
- title="Global #{role_name(@role)}"
+ title='System administrators'
end
%>
<div class="subtitle">» <a href="<%= url_for :action => params[:redirect], :q => params[:q], :qualifier => params[:qualifier] -%>">Back</a></div>
<h1><%= title %></h1>
<br/>
<div>
- <form action="<%= url_for :action => 'grant_groups' -%>" method="post">
+ <form action="<%= url_for :action => 'set_groups' -%>" method="post">
<input name="resource" value="<%= params[:resource] -%>" type="hidden"/>
<input name="role" value="<%= @role -%>" type="hidden"/>
<input name="redirect" value="<%= params[:redirect] -%>" type="hidden"/>
<h1><%= title %></h1>
<br/>
<div id="main_content">
- <form action="<%= url_for :action => 'grant_users' -%>" method="post">
+ <form action="<%= url_for :action => 'set_users' -%>" method="post">
<input name="resource" value="<%= params[:resource] -%>" type="hidden"/>
<input name="role" value="<%= @role -%>" type="hidden" />
<input name="redirect" value="<%= params[:redirect] -%>" type="hidden" />
-<h1 class="marginbottom10">Global Roles</h1>
+<h1 class="marginbottom10"><%= message 'system_administrators.page' -%></h1>
<table class="data width100" id="global-roles">
<thead>
</thead>
<tbody>
<tr class="even" >
- <td valign="top"><b>Administrators</b><br/><span class="small gray">Ability to perform all administration functions for the instance: global configuration, personalization of Time Machine and homepage.</span></td>
+ <td valign="top"><b>Administrators</b><br/><span class="small gray">Ability to perform all administration functions for the instance: global configuration and personalization of default dashboards.</span></td>
<td valign="top" style="word-break:break-all;width:30%;">
<span><%= users('admin').map(&:login).join(', ') %></span>
(<%= link_to "select", {:action => 'edit_users', :role => 'admin', :redirect => 'global'}, :class => 'link-action' %>)
-<h1 class="marginbottom10">Default Roles for New <%= @qualifiers.map { |q| message("qualifiers.#{q}") }.join(', ') -%></h1>
+<h1 class="marginbottom10"><%= message('roles.page') -%></h1>
+
+<% if @qualifiers.size>1 %>
+<ul class="tabs" id="qualifier-tabs">
+ <% @qualifiers.each do |q|
+ css_class = (q==@qualifier ? 'selected' : '')
+ %>
+ <li>
+ <%= link_to message("qualifiers.#{q}"), {:action => 'projects', :qualifier => q}, {:class => css_class} -%>
+ </li>
+ <% end %>
+</ul>
+<% end %>
<table class="data width100" id="default-project-roles">
<thead>
<tr>
- <th>Role</th>
+ <th>Default Permissions For New <%= message("qualifiers.#{@qualifier}") -%></th>
<th width="35%">Users</th>
<th width="35%">Groups</th>
</tr>
</thead>
<tbody>
<tr class="even">
- <td valign="top"><b>Administrators</b><br/><span class="small gray">Ability to perform administration functions for a project by accessing its settings.</span></td>
+ <td valign="top"><b>Role: Administrators</b><br/><span class="small gray">Ability to perform administration functions for a project by accessing its settings.</span></td>
<td valign="top" style="word-break:break-all;width:35%;">
<div style="vertical-align:top">
- <span><%= users('default-admin').map(&:login).join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_users', :role => 'default-admin', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_users('admin', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_users', :role => 'admin', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</div>
</td>
<td valign="top" style="word-break:break-all;width:35%;">
- <span><%= groups('default-admin').map { |g| group_name(g) }.join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_groups', :role => 'default-admin', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_groups('admin', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_groups', :role => 'admin', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</td>
</tr>
<tr class="odd">
- <td valign="top"><b>Users</b><br/><span class="small gray">Ability to navigate through every service of a project, except viewing source code and settings.</span></td>
+ <td valign="top"><b>Role: Users</b><br/><span class="small gray">Ability to navigate through every service of a project, except viewing source code and settings.</span></td>
<td valign="top" style="word-break:break-all;width:35%;">
- <span><%= users('default-user').map(&:login).join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_users', :role => 'default-user', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_users('user', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_users', :role => 'user', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</td>
<td valign="top" style="word-break:break-all;width:35%;">
- <span><%= groups('default-user').map { |g| group_name(g) }.join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_groups', :role => 'default-user', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_groups('user', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_groups', :role => 'user', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</td>
</tr>
<tr class="even">
- <td valign="top"><b>Code viewers</b><br/><span class="small gray">Ability to view source code of a project.</span></td>
+ <td valign="top"><b>Role: Code viewers</b><br/><span class="small gray">Ability to view source code of a project.</span></td>
<td valign="top" style="word-break:break-all;width:35%;">
- <span><%= users('default-codeviewer').map(&:login).join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_users', :role => 'default-codeviewer', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_users('codeviewer', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_users', :role => 'codeviewer', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</td>
<td valign="top" style="word-break:break-all;width:35%;">
- <span><%= groups('default-codeviewer').map { |g| group_name(g) }.join(', ') %></span>
- (<%= link_to "select", {:action => 'edit_groups', :role => 'default-codeviewer', :redirect => 'projects'}, :class => 'link-action' %>)
+ <span><%= default_project_groups('codeviewer', @qualifier).join(', ') -%></span>
+ (<%= link_to "select", {:action => 'edit_default_project_groups', :role => 'codeviewer', :redirect => 'projects', :qualifier => @qualifier}, :class => 'link-action' %>)
</td>
</tr>
</tbody>
</table>
-<br/><br/>
-<% if @qualifiers.size>1 %>
-<ul class="tabs" id="qualifier-tabs">
- <% @qualifiers.each do |q|
- css_class = (q==@qualifier ? 'selected' : '')
- %>
- <li>
- <%= link_to message("qualifiers.#{q}"), {:action => 'projects', :qualifier => q}, {:class => css_class} -%>
- </li>
- <% end %>
-</ul>
-<% else %>
- <h1 class="spacer-bottom"><%= message("qualifiers.#{@qualifiers[0]}") -%></h1>
-<% end %>
+<br/><br/>
<div class="<%= @qualifiers.size>1 ? 'tabs-panel' : '' -%>">
end
def self.up
- if GroupRole.count==0
- # fresh install
- Property.delete_all(['prop_key like ?', 'sonar.role.%'])
- Property.create(:prop_key => 'sonar.role.admin.project.defaultGroups', :text_value => 'sonar-administrators')
- Property.create(:prop_key => 'sonar.role.user.project.defaultGroups', :text_value => 'sonar-users,Anyone')
- Property.create(:prop_key => 'sonar.role.codeviewer.project.defaultGroups', :text_value => 'sonar-users,Anyone')
- else
+ Group.reset_column_information
+ GroupRole.reset_column_information
+ User.reset_column_information
+ UserRole.reset_column_information
+ Property.reset_column_information
+
+ if GroupRole.count(:conditions => ['role like ?', 'default-%'])>0
# upgrade from version < 3.2.
move_groups
move_users
end
groups_per_role.each_pair do |role, groups|
- Property.create(:prop_key => "sonar.role.#{role}.project.defaultGroups", :text_value => groups.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.TRK.defaultGroups", :text_value => groups.join(','))
end
- #GroupRole.delete_all ['role like ?', 'default-%']
+ GroupRole.delete_all ['role like ?', 'default-%']
end
def self.move_users
end
users_per_role.each_pair do |role, users|
- Property.create(:prop_key => "sonar.role.#{role}.project.defaultUsers", :text_value => users.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.TRK.defaultUsers", :text_value => users.join(','))
end
- #UserRole.delete_all ['role like ?', 'default-%']
+ UserRole.delete_all ['role like ?', 'default-%']
end
end