--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.4
+# SONAR-7242
+#
+class RemovePreviewPermission < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.db.version.v54.RemovePreviewPermission')
+ end
+
+end
public class DatabaseVersion {
- public static final int LAST_VERSION = 1014;
+ public static final int LAST_VERSION = 1015;
/**
* The minimum supported version which can be upgraded. Lower
import org.sonar.db.version.v54.MigrateQualityGatesConditions;
import org.sonar.db.version.v54.MigrateUsersIdentity;
import org.sonar.db.version.v54.RemoveComponentPageProperties;
+import org.sonar.db.version.v54.RemovePreviewPermission;
public class MigrationStepModule extends Module {
@Override
AddUsersIdentityColumns.class,
MigrateUsersIdentity.class,
MigrateQualityGatesConditions.class,
- MigrateDisabledUsersToOnlyKeepLoginAndName.class
+ MigrateDisabledUsersToOnlyKeepLoginAndName.class,
+ RemovePreviewPermission.class
);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.version.v54;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.BaseDataChange;
+import org.sonar.db.version.MassUpdate;
+import org.sonar.db.version.Select;
+import org.sonar.db.version.SqlStatement;
+
+/**
+ * Remove the "Execute Preview Analysis" (dryRunScan) permission
+ */
+public class RemovePreviewPermission extends BaseDataChange {
+
+ public RemovePreviewPermission(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ execute(context, "group_roles", "groups");
+ execute(context, "user_roles", "users");
+ }
+
+ private void execute(Context context, String tableName, String displayName) throws SQLException {
+ MassUpdate update = context.prepareMassUpdate().rowPluralName(displayName);
+ update.select("SELECT r.id FROM " + tableName + " r WHERE r.role=?").setString(1, "dryRunScan");
+ update.update("DELETE FROM " + tableName + " WHERE id=?");
+ update.execute(MigrationHandler.INSTANCE);
+ }
+
+ private enum MigrationHandler implements MassUpdate.Handler {
+ INSTANCE;
+
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ update.setLong(1, row.getLong(1));
+ return true;
+ }
+ }
+}
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1012');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1013');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1014');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1015');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(49);
+ assertThat(container.size()).isEqualTo(50);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.version.v54;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.version.MigrationStep;
+
+public class RemovePreviewPermissionTest {
+
+ static final String GROUP_ROLES_TABLE = "group_roles";
+ static final String USER_ROLES_TABLE = "user_roles";
+
+ @ClassRule
+ public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemovePreviewPermissionTest.class, "schema.sql");
+
+ MigrationStep migration;
+
+ @Before
+ public void setUp() {
+ db.executeUpdateSql("truncate table " + GROUP_ROLES_TABLE);
+ db.executeUpdateSql("truncate table " + USER_ROLES_TABLE);
+ migration = new RemovePreviewPermission(db.database());
+ }
+
+ @Test
+ public void migrate_empty_db() throws Exception {
+ migration.execute();
+ }
+
+ @Test
+ public void migrate() throws Exception {
+ db.prepareDbUnit(this.getClass(), "migrate.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "migrate-result.xml", GROUP_ROLES_TABLE, USER_ROLES_TABLE);
+ }
+
+ @Test
+ public void nothing_to_do_on_already_migrated_data() throws Exception {
+ db.prepareDbUnit(this.getClass(), "migrate-result.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "migrate-result.xml", GROUP_ROLES_TABLE, USER_ROLES_TABLE);
+ }
+
+}
--- /dev/null
+<dataset>
+
+ <!-- Groups -->
+ <group_roles id="1" group_id="[null]" role="scan" resource_id="[null]"/>
+ <!--<group_roles id="2" group_id="[null]" role="dryRunScan" resource_id="[null]"/>-->
+
+ <group_roles id="3" group_id="102" role="admin" resource_id="1"/>
+ <!--<group_roles id="4" group_id="102" role="dryRunScan" resource_id="1"/>-->
+
+ <!-- Users -->
+ <user_roles id="1" user_id="200" role="admin" resource_id="[null]"/>
+ <!--<user_roles id="2" user_id="201" role="dryRunScan" resource_id="[null]"/>-->
+ <!--<user_roles id="3" user_id="201" role="dryRunScan" resource_id="1"/>-->
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Groups -->
+ <group_roles id="1" group_id="[null]" role="scan" resource_id="[null]"/>
+ <group_roles id="2" group_id="[null]" role="dryRunScan" resource_id="[null]"/>
+
+ <group_roles id="3" group_id="102" role="admin" resource_id="1"/>
+ <group_roles id="4" group_id="102" role="dryRunScan" resource_id="1"/>
+
+ <!-- Users -->
+ <user_roles id="1" user_id="200" role="admin" resource_id="[null]"/>
+ <user_roles id="2" user_id="201" role="dryRunScan" resource_id="[null]"/>
+ <user_roles id="3" user_id="201" role="dryRunScan" resource_id="1"/>
+
+</dataset>
--- /dev/null
+CREATE TABLE "GROUP_ROLES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+
+CREATE TABLE "USER_ROLES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);