INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1);
INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2);
+-- see migration 320
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (1, 'sonar.role.admin.TRK.defaultGroups', NULL, 'sonar-administrators', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (2, 'sonar.role.user.TRK.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (3, 'sonar.role.codeviewer.TRK.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (4, 'sonar.role.admin.VW.defaultGroups', NULL, 'sonar-administrators', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (5, 'sonar.role.user.VW.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (6, 'sonar.role.codeviewer.VW.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (7, 'sonar.role.admin.SVW.defaultGroups', NULL, 'sonar-administrators', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (8, 'sonar.role.user.SVW.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+INSERT INTO PROPERTIES(ID, prop_key, resource_id, text_value, user_id) VALUES (9, 'sonar.role.codeviewer.SVW.defaultGroups', NULL, 'Anyone,sonar-users', NULL);
+ALTER TABLE PROPERTIES ALTER COLUMN ID RESTART WITH 10;
+
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('2');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('10');
*/
package org.sonar.server.platform;
-import org.sonar.api.config.EmailSettings;
-
import org.apache.commons.configuration.BaseConfiguration;
import org.slf4j.LoggerFactory;
import org.sonar.api.Plugins;
+import org.sonar.api.config.EmailSettings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.Server;
import org.sonar.api.profiles.AnnotationProfileParser;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
-import org.sonar.core.persistence.DaoUtils;
-import org.sonar.core.persistence.DatabaseMigrator;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.persistence.DefaultDatabase;
-import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.persistence.*;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.core.user.DefaultUserFinder;
import org.sonar.server.filters.FilterExecutor;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
-import org.sonar.server.plugins.ApplicationDeployer;
-import org.sonar.server.plugins.DefaultServerPluginRepository;
-import org.sonar.server.plugins.PluginDeployer;
-import org.sonar.server.plugins.PluginDownloader;
-import org.sonar.server.plugins.ServerExtensionInstaller;
-import org.sonar.server.plugins.UpdateCenterClient;
-import org.sonar.server.plugins.UpdateCenterMatrixFactory;
+import org.sonar.server.plugins.*;
import org.sonar.server.qualitymodel.DefaultModelManager;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
startupContainer.addSingleton(GeneratePluginIndex.class);
startupContainer.addSingleton(RegisterNewFilters.class);
startupContainer.addSingleton(RegisterNewDashboards.class);
- startupContainer.addSingleton(SetDefaultProjectPermissions.class);
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
+++ /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.server.startup;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.server.platform.PersistentSettings;
-
-import java.util.Map;
-
-/**
- * @since 3.2
- */
-public class SetDefaultProjectPermissions {
- private static final String SONAR_ADMINISTRATORS = "sonar-administrators";
- private static final String ANYONE_AND_USERS = "Anyone,sonar-users";
- private static final String SUFFIX = ".defaultGroups";
-
- private final PersistentSettings persistentSettings;
-
- public SetDefaultProjectPermissions(PersistentSettings persistentSettings) {
- this.persistentSettings = persistentSettings;
- }
-
- public void start() {
- Map<String, String> props = Maps.newHashMap();
- props.putAll(missingProperties("TRK"));
-
- // Support old versions of Views plugin
- props.putAll(missingProperties("VW"));
- props.putAll(missingProperties("SVW"));
-
- if (!props.isEmpty()) {
- LoggerFactory.getLogger(SetDefaultProjectPermissions.class).info("Set default project roles");
- persistentSettings.saveProperties(props);
- }
- }
-
- private Map<String, String> missingProperties(String qualifier) {
- Map<String, String> props = Maps.newHashMap();
- if (StringUtils.isBlank(persistentSettings.getSettings().getString("sonar.role.user." + qualifier + SUFFIX))) {
- completeDefaultRoles(qualifier, props);
- }
- return props;
- }
-
- private void completeDefaultRoles(String qualifier, Map<String, String> props) {
- props.put("sonar.role.admin." + qualifier + SUFFIX, SONAR_ADMINISTRATORS);
- props.put("sonar.role.user." + qualifier + SUFFIX, ANYONE_AND_USERS);
- props.put("sonar.role.codeviewer." + qualifier + SUFFIX, ANYONE_AND_USERS);
- }
-}
# upgrade from version < 3.2.
move_groups
move_users
+ else
+ # fresh install
+ create_default_roles('TRK')
+ create_default_roles('VW')
+ create_default_roles('SVW')
end
end
groups_per_role.each_pair do |role, groups|
Property.create(:prop_key => "sonar.role.#{role}.TRK.defaultGroups", :text_value => groups.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.VW.defaultGroups", :text_value => groups.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.SVW.defaultGroups", :text_value => groups.join(','))
end
GroupRole.delete_all ['role like ?', 'default-%']
users_per_role.each_pair do |role, users|
Property.create(:prop_key => "sonar.role.#{role}.TRK.defaultUsers", :text_value => users.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.VW.defaultUsers", :text_value => users.join(','))
+ Property.create(:prop_key => "sonar.role.#{role}.SVW.defaultUsers", :text_value => users.join(','))
end
UserRole.delete_all ['role like ?', 'default-%']
end
+
+ def self.create_default_roles(qualifier)
+ Property.create(:prop_key => "sonar.role.admin.#{qualifier}.defaultGroups", :text_value => 'sonar-administrators')
+ Property.create(:prop_key => "sonar.role.user.#{qualifier}.defaultGroups", :text_value => 'Anyone,sonar-users')
+ Property.create(:prop_key => "sonar.role.codeviewer.#{qualifier}.defaultGroups", :text_value => 'Anyone,sonar-users')
+ end
+
end
+++ /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.server.startup;
-
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.config.Settings;
-import org.sonar.server.platform.PersistentSettings;
-
-import java.util.Map;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class SetDefaultProjectPermissionsTest {
- @Test
- public void set_default_permissions_if_none() {
- PersistentSettings persistentSettings = mock(PersistentSettings.class);
- Settings settings = new Settings();
- when(persistentSettings.getSettings()).thenReturn(settings);
-
- new SetDefaultProjectPermissions(persistentSettings).start();
-
- verify(persistentSettings).saveProperties(argThat(new ArgumentMatcher<Map<String, String>>() {
- @Override
- public boolean matches(Object o) {
- Map<String, String> map = (Map<String, String>) o;
- return map.size()>1 && map.get("sonar.role.admin.TRK.defaultGroups").equals("sonar-administrators");
- }
- }));
- }
-
- @Test
- public void do_not_set_default_permissions_if_exist() {
- PersistentSettings persistentSettings = mock(PersistentSettings.class);
- Settings settings = new Settings()
- .setProperty("sonar.role.user.TRK.defaultGroups", "custom-group")
- .setProperty("sonar.role.user.VW.defaultGroups", "custom-group")
- .setProperty("sonar.role.user.SVW.defaultGroups", "custom-group");
- when(persistentSettings.getSettings()).thenReturn(settings);
-
- new SetDefaultProjectPermissions(persistentSettings).start();
-
- verify(persistentSettings, never()).saveProperties(any(Map.class));
- }
-}