forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-5596 Purge permission on modules
- Loading branch information
Julien Lancelot
committed
Feb 18, 2015
1 parent
235184a
commit d6c79a0
Showing
10 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...src/main/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.db.migrations.v51; | ||
|
||
import org.sonar.core.persistence.Database; | ||
import org.sonar.server.db.migrations.BaseDataChange; | ||
import org.sonar.server.db.migrations.MassUpdate; | ||
import org.sonar.server.db.migrations.Select; | ||
import org.sonar.server.db.migrations.SqlStatement; | ||
|
||
import java.sql.SQLException; | ||
|
||
/** | ||
* See http://jira.codehaus.org/browse/SONAR-5596 | ||
* | ||
* It's no possible to set permission on a module or a sub-view, but the batch was setting default permission on it on their creation. | ||
* As now it's no more the case, we need to purge this useless data. | ||
* | ||
* @since 5.1 | ||
*/ | ||
public class RemovePermissionsOnModulesMigration extends BaseDataChange { | ||
|
||
public RemovePermissionsOnModulesMigration(Database db) { | ||
super(db); | ||
} | ||
|
||
@Override | ||
public void execute(Context context) throws SQLException { | ||
removeUserRolePermissions(context, "user_roles", "user roles"); | ||
removeUserRolePermissions(context, "group_roles", "group roles"); | ||
} | ||
|
||
private void removeUserRolePermissions(Context context, String tableName, String pluralName) throws SQLException { | ||
MassUpdate massUpdate = context.prepareMassUpdate(); | ||
massUpdate.select("SELECT r.id " + | ||
"FROM " + tableName + " r " + | ||
" INNER JOIN projects ON projects.id = r.resource_id " + | ||
"WHERE projects.module_uuid IS NOT NULL;"); | ||
massUpdate.update("DELETE FROM " + tableName + " WHERE id=?"); | ||
massUpdate.rowPluralName(pluralName); | ||
massUpdate.execute(new MassUpdate.Handler() { | ||
@Override | ||
public boolean handle(Select.Row row, SqlStatement update) throws SQLException { | ||
update.setLong(1, row.getLong(1)); | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.server.db.migrations.v51; | ||
|
||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.sonar.core.persistence.DbTester; | ||
import org.sonar.server.db.migrations.DatabaseMigration; | ||
|
||
public class RemovePermissionsOnModulesMigrationTest { | ||
|
||
@ClassRule | ||
public static DbTester db = new DbTester().schema(RemovePermissionsOnModulesMigrationTest.class, "schema.sql"); | ||
|
||
DatabaseMigration migration; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
migration = new RemovePermissionsOnModulesMigration(db.database()); | ||
} | ||
|
||
@Test | ||
public void execute() throws Exception { | ||
db.prepareDbUnit(getClass(), "migrate.xml"); | ||
|
||
migration.execute(); | ||
|
||
db.assertDbUnit(getClass(), "migrate-result.xml", "user_roles", "group_roles"); | ||
} | ||
|
||
@Test | ||
public void nothing_to_do_when_already_migrated() throws Exception { | ||
db.prepareDbUnit(getClass(), "nothing_to_do_when_already_migrated.xml"); | ||
|
||
migration.execute(); | ||
|
||
db.assertDbUnit(getClass(), "nothing_to_do_when_already_migrated.xml", "user_roles", "group_roles"); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest/migrate-result.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<dataset> | ||
|
||
<projects id="100" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="the description" long_name="Apache Struts" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<projects id="101" root_id="[null]" scope="PRJ" qualifier="BRC" kee="org.struts:struts-server" name="Struts Server" description="the description" long_name="Apache Struts Server" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<!-- Permissions on project --> | ||
<user_roles id="1" user_id="200" resource_id="100" role="user"/> | ||
<user_roles id="2" user_id="200" resource_id="100" role="admin"/> | ||
<group_roles id="1" group_id="100" resource_id="100" role="codeviewer"/> | ||
|
||
<!-- No more permissions on module --> | ||
|
||
<!-- Global permissions --> | ||
<user_roles id="10" user_id="200" resource_id="[null]" role="admin"/> | ||
<group_roles id="10" group_id="200" resource_id="[null]" role="admin"/> | ||
|
||
</dataset> |
25 changes: 25 additions & 0 deletions
25
...es/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest/migrate.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<dataset> | ||
|
||
<projects id="100" uuid="ABCD" module_uuid="[null]" project_uuid="ABCD" module_uuid_path=".ABCD." root_id="[null]" | ||
scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="the description" long_name="Apache Struts" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<projects id="101" uuid="BCDE" module_uuid="ABCD" project_uuid="ABCD" module_uuid_path=".ABCD.BCDE." root_id="100" | ||
scope="PRJ" qualifier="BRC" kee="org.struts:struts-server" name="Struts Server" description="the description" long_name="Apache Struts Server" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<!-- Permissions on project --> | ||
<user_roles id="1" user_id="200" resource_id="100" role="user"/> | ||
<user_roles id="2" user_id="200" resource_id="100" role="admin"/> | ||
<group_roles id="1" group_id="100" resource_id="100" role="codeviewer"/> | ||
|
||
<!-- Permissions on module : should be deleted --> | ||
<user_roles id="3" user_id="200" resource_id="101" role="user"/> | ||
<user_roles id="4" user_id="200" resource_id="101" role="admin"/> | ||
<group_roles id="2" group_id="100" resource_id="101" role="codeviewer"/> | ||
|
||
<!-- Global permissions --> | ||
<user_roles id="10" user_id="200" resource_id="[null]" role="admin"/> | ||
<group_roles id="10" group_id="200" resource_id="[null]" role="admin"/> | ||
|
||
</dataset> |
18 changes: 18 additions & 0 deletions
18
...tions/v51/RemovePermissionsOnModulesMigrationTest/nothing_to_do_when_already_migrated.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<dataset> | ||
|
||
<projects id="100" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="the description" long_name="Apache Struts" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<projects id="101" root_id="[null]" scope="PRJ" qualifier="BRC" kee="org.struts:struts-server" name="Struts Server" description="the description" long_name="Apache Struts Server" | ||
enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="123456789"/> | ||
|
||
<!-- Permissions on project --> | ||
<user_roles id="1" user_id="200" resource_id="100" role="user"/> | ||
<user_roles id="2" user_id="200" resource_id="100" role="admin"/> | ||
<group_roles id="1" group_id="100" resource_id="100" role="codeviewer"/> | ||
|
||
<!-- Global permissions --> | ||
<user_roles id="10" user_id="200" resource_id="[null]" role="admin"/> | ||
<group_roles id="10" group_id="200" resource_id="[null]" role="admin"/> | ||
|
||
</dataset> |
49 changes: 49 additions & 0 deletions
49
...ces/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 | ||
); | ||
|
||
CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES" ("RESOURCE_ID"); | ||
|
||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES" ("USER_ID"); | ||
|
||
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 INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES" ("RESOURCE_ID"); | ||
|
||
CREATE INDEX "GROUP_ROLES_GROUP" ON "GROUP_ROLES" ("GROUP_ID"); | ||
|
||
CREATE INDEX "GROUP_ROLES_ROLE" ON "GROUP_ROLES" ("ROLE"); | ||
|
||
CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES" ("GROUP_ID", "RESOURCE_ID", "ROLE"); | ||
|
||
CREATE TABLE "PROJECTS" ( | ||
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | ||
"KEE" VARCHAR(400), | ||
"ROOT_ID" INTEGER, | ||
"UUID" VARCHAR(50), | ||
"PROJECT_UUID" VARCHAR(50), | ||
"MODULE_UUID" VARCHAR(50), | ||
"MODULE_UUID_PATH" VARCHAR(4000), | ||
"NAME" VARCHAR(256), | ||
"DESCRIPTION" VARCHAR(2000), | ||
"ENABLED" BOOLEAN NOT NULL DEFAULT TRUE, | ||
"SCOPE" VARCHAR(3), | ||
"QUALIFIER" VARCHAR(10), | ||
"DEPRECATED_KEE" VARCHAR(400), | ||
"PATH" VARCHAR(2000), | ||
"LANGUAGE" VARCHAR(20), | ||
"COPY_RESOURCE_ID" INTEGER, | ||
"LONG_NAME" VARCHAR(256), | ||
"PERSON_ID" INTEGER, | ||
"CREATED_AT" TIMESTAMP, | ||
"AUTHORIZATION_UPDATED_AT" BIGINT | ||
); | ||
|
31 changes: 31 additions & 0 deletions
31
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/795_remove_permissions_on_modules.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# 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.1 | ||
# SONAR-5596 | ||
# | ||
class RemovePermissionsOnModules < ActiveRecord::Migration | ||
|
||
def self.up | ||
execute_java_migration 'org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigration' | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters