@@ -551,20 +551,12 @@ ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID" | |||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); | |||
CREATE TABLE "PERM_TEMPLATES_GROUPS"( | |||
<<<<<<< HEAD | |||
"GROUP_ID" INTEGER, | |||
======= | |||
"TEMPLATE_ID" INTEGER NOT NULL, | |||
>>>>>>> SONAR-13221 change PK of GROUPS and update FKs | |||
"PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, | |||
"CREATED_AT" TIMESTAMP, | |||
"UPDATED_AT" TIMESTAMP, | |||
"UUID" VARCHAR(40) NOT NULL, | |||
<<<<<<< HEAD | |||
"TEMPLATE_UUID" VARCHAR(40) NOT NULL | |||
======= | |||
"TEMPLATE_UUID" VARCHAR(40) NOT NULL, | |||
"GROUP_UUID" VARCHAR(40) | |||
>>>>>>> SONAR-13221 change PK of GROUPS and update FKs | |||
); | |||
ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID"); | |||
@@ -63,7 +63,7 @@ public class LiveMeasureDaoTest { | |||
} | |||
@Test | |||
public void selectByComponentUuidsAndMetricIds() { | |||
public void selectByComponentUuidsAndMetricUuids() { | |||
LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid()); | |||
LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric.getUuid()); | |||
underTest.insert(db.getSession(), measure1); | |||
@@ -82,7 +82,7 @@ public class LiveMeasureDaoTest { | |||
} | |||
@Test | |||
public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_metric_does_not_match() { | |||
public void selectByComponentUuidsAndMetricUuids_returns_empty_list_if_metric_does_not_match() { | |||
LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); | |||
underTest.insert(db.getSession(), measure); | |||
@@ -93,7 +93,7 @@ public class LiveMeasureDaoTest { | |||
} | |||
@Test | |||
public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_component_does_not_match() { | |||
public void selectByComponentUuidsAndMetricUuids_returns_empty_list_if_component_does_not_match() { | |||
LiveMeasureDto measure = newLiveMeasure(); | |||
underTest.insert(db.getSession(), measure); | |||
@@ -402,7 +402,7 @@ public class LiveMeasureDaoTest { | |||
} | |||
@Test | |||
public void deleteByComponentUuidExcludingMetricIds() { | |||
public void deleteByComponentUuidExcludingMetricUuids() { | |||
LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1"); | |||
LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2"); | |||
LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("3"); | |||
@@ -438,7 +438,7 @@ public class LiveMeasureDaoTest { | |||
} | |||
@Test | |||
public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() { | |||
public void deleteByComponentUuidExcludingMetricUuids_with_empty_metrics() { | |||
LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1"); | |||
LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2"); | |||
LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("2"); |
@@ -58,7 +58,7 @@ public class AuthorizationDaoTest { | |||
private static final String PROJECT_UUID = "uuid"; | |||
private static final int MISSING_ID = -1; | |||
private static final String MISSING_UUID = "unkown"; | |||
private static final String MISSING_UUID = "unknown"; | |||
private static final String A_PERMISSION = "a-permission"; | |||
private static final String DOES_NOT_EXIST = "does-not-exist"; | |||
@@ -583,7 +583,7 @@ public class ActiveRuleDaoTest { | |||
} | |||
@Test | |||
public void deleteParamsByActiveRuleIds() { | |||
public void deleteParamsByActiveRuleUuids() { | |||
ActiveRuleDto ar1 = underTest.insert(dbSession, newRow(profile1, rule1)); | |||
ActiveRuleParamDto param = ActiveRuleParamDto.createFor(rule1Param1).setValue("foo"); | |||
underTest.insertParam(dbSession, ar1, param); |
@@ -1,38 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder; | |||
public class AddPrimaryKeyOnUuidColumnOfMetricsTable extends DdlChange { | |||
public AddPrimaryKeyOnUuidColumnOfMetricsTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute(new AddPrimaryKeyBuilder("metrics", "uuid").build()); | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable; | |||
public class AddUuidColumnToMetricsTable extends AddUuidColumnToTable { | |||
private static final String TABLE = "metrics"; | |||
public AddUuidColumnToMetricsTable(Database db) { | |||
super(db, TABLE); | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn; | |||
public class DropIdColumnOfMetricsTable extends DropIdColumn { | |||
private static final String TABLE = "metrics"; | |||
public DropIdColumnOfMetricsTable(Database db) { | |||
super(db, TABLE); | |||
} | |||
} |
@@ -1,32 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn; | |||
import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; | |||
public class DropPrimaryKeyOnIdColumnOfMetricsTable extends DropPrimaryKeyOnIdColumn { | |||
private static final String TABLE_NAME = "metrics"; | |||
public DropPrimaryKeyOnIdColumnOfMetricsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { | |||
super(db, dropPrimaryKeySqlGenerator, TABLE_NAME); | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable; | |||
public class MakeMetricsUuidColumnNotNullable extends MakeUuidColumnNotNullable { | |||
private static final String TABLE = "metrics"; | |||
public MakeMetricsUuidColumnNotNullable(Database db) { | |||
super(db, TABLE); | |||
} | |||
} |
@@ -1,50 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 SonarSource SA | |||
* mailto:info 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.server.platform.db.migration.version.v83.groups; | |||
import java.sql.SQLException; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import org.sonar.server.platform.db.migration.step.MassUpdate; | |||
public class PopulateMetricsUuid extends DataChange { | |||
private final UuidFactory uuidFactory; | |||
public PopulateMetricsUuid(Database db, UuidFactory uuidFactory) { | |||
super(db); | |||
this.uuidFactory = uuidFactory; | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id from metrics where uuid is null order by id asc"); | |||
massUpdate.update("update metrics set uuid = ? where id = ?"); | |||
massUpdate.execute((row, update) -> { | |||
update.setString(1, uuidFactory.create()); | |||
update.setLong(2, row.getLong(1)); | |||
return true; | |||
}); | |||
} | |||
} |
@@ -76,10 +76,10 @@ public class OrganisationSupport { | |||
} | |||
private void createDefaultMembersGroup(DbSession dbSession, String defaultOrganizationUuid) { | |||
GroupDto sonarUsersGroupId = defaultGroupFinder.findDefaultGroup(dbSession, defaultOrganizationUuid); | |||
GroupDto sonarUsersGroup = defaultGroupFinder.findDefaultGroup(dbSession, defaultOrganizationUuid); | |||
GroupDto members = defaultGroupCreator.create(dbSession, defaultOrganizationUuid); | |||
copySonarUsersGroupPermissionsToMembersGroup(dbSession, defaultOrganizationUuid, sonarUsersGroupId, members); | |||
copySonarUsersGroupPermissionTemplatesToMembersGroup(dbSession, sonarUsersGroupId, members); | |||
copySonarUsersGroupPermissionsToMembersGroup(dbSession, defaultOrganizationUuid, sonarUsersGroup, members); | |||
copySonarUsersGroupPermissionTemplatesToMembersGroup(dbSession, sonarUsersGroup, members); | |||
associateMembersOfDefaultOrganizationToGroup(dbSession, defaultOrganizationUuid, members); | |||
} | |||
@@ -102,9 +102,9 @@ class RuleActivationContext { | |||
} | |||
private void register(Collection<ActiveRuleDto> activeRules, Collection<ActiveRuleParamDto> activeRuleParams) { | |||
ListMultimap<String, ActiveRuleParamDto> paramsByActiveRuleId = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleUuid)); | |||
ListMultimap<String, ActiveRuleParamDto> paramsByActiveRuleUuid = activeRuleParams.stream().collect(index(ActiveRuleParamDto::getActiveRuleUuid)); | |||
for (ActiveRuleDto activeRule : activeRules) { | |||
ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleId.get(activeRule.getUuid())); | |||
ActiveRuleWrapper wrapper = new ActiveRuleWrapper(activeRule, paramsByActiveRuleUuid.get(activeRule.getUuid())); | |||
this.activeRulesByKey.put(activeRule.getKey(), wrapper); | |||
} | |||
} |
@@ -71,7 +71,7 @@ public class RegisterPermissionTemplatesTest { | |||
@Test | |||
public void fail_with_ISE_if_default_template_must_be_created_and_default_group_does_not_exist() { | |||
setDefaultGroupId(new GroupDto().setUuid("22")); | |||
setDefaultGroup(new GroupDto().setUuid("22")); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Default group with id 22 for organization " + db.getDefaultOrganization().getUuid() + " doesn't exist"); | |||
@@ -199,14 +199,14 @@ public class RegisterPermissionTemplatesTest { | |||
assertThat(defaultTemplates.get().getProjectUuid()).isEqualTo(DEFAULT_TEMPLATE_UUID); | |||
} | |||
private void setDefaultGroupId(GroupDto defaultGroup) { | |||
private void setDefaultGroup(GroupDto defaultGroup) { | |||
db.getDbClient().organizationDao().setDefaultGroupUuid(db.getSession(), db.getDefaultOrganization().getUuid(), defaultGroup); | |||
db.commit(); | |||
} | |||
private GroupDto createAndSetDefaultGroup() { | |||
GroupDto res = db.users().insertGroup(db.getDefaultOrganization()); | |||
setDefaultGroupId(res); | |||
setDefaultGroup(res); | |||
return res; | |||
} | |||
} |
@@ -89,7 +89,7 @@ public class CreateAction implements CustomMeasuresWsAction { | |||
.setExampleValue(KEY_PROJECT_EXAMPLE_001); | |||
action.createParam(PARAM_METRIC_ID) | |||
.setDescription("Metric id") | |||
.setDescription("Metric uuid") | |||
.setExampleValue("16"); | |||
action.createParam(PARAM_METRIC_KEY) |
@@ -23,15 +23,15 @@ import javax.annotation.Nullable; | |||
public class GroupPermissionChange extends PermissionChange { | |||
private final GroupUuidOrAnyone groupId; | |||
private final GroupUuidOrAnyone group; | |||
public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectUuid projectUuid, | |||
GroupUuidOrAnyone groupId, PermissionService permissionService) { | |||
super(operation, groupId.getOrganizationUuid(), permission, projectUuid, permissionService); | |||
this.groupId = groupId; | |||
GroupUuidOrAnyone group, PermissionService permissionService) { | |||
super(operation, group.getOrganizationUuid(), permission, projectUuid, permissionService); | |||
this.group = group; | |||
} | |||
public GroupUuidOrAnyone getGroupIdOrAnyone() { | |||
return groupId; | |||
public GroupUuidOrAnyone getGroupUuidOrAnyone() { | |||
return group; | |||
} | |||
} |
@@ -79,7 +79,7 @@ public class GroupPermissionChanger { | |||
private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) { | |||
return project.isPrivate() | |||
&& change.getOperation() == REMOVE | |||
&& change.getGroupIdOrAnyone().isAnyone(); | |||
&& change.getGroupUuidOrAnyone().isAnyone(); | |||
} | |||
private static void ensureConsistencyWithVisibility(GroupPermissionChange change) { | |||
@@ -96,7 +96,7 @@ public class GroupPermissionChanger { | |||
private static boolean isAttemptToAddPermissionToAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) { | |||
return project.isPrivate() | |||
&& change.getOperation() == ADD | |||
&& change.getGroupIdOrAnyone().isAnyone(); | |||
&& change.getGroupUuidOrAnyone().isAnyone(); | |||
} | |||
private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectUuid project) { | |||
@@ -110,12 +110,12 @@ public class GroupPermissionChanger { | |||
return false; | |||
} | |||
validateNotAnyoneAndAdminPermission(change.getPermission(), change.getGroupIdOrAnyone()); | |||
validateNotAnyoneAndAdminPermission(change.getPermission(), change.getGroupUuidOrAnyone()); | |||
GroupPermissionDto addedDto = new GroupPermissionDto() | |||
.setUuid(uuidFactory.create()) | |||
.setRole(change.getPermission()) | |||
.setOrganizationUuid(change.getOrganizationUuid()) | |||
.setGroupUuid(change.getGroupIdOrAnyone().getUuid()) | |||
.setGroupUuid(change.getGroupUuidOrAnyone().getUuid()) | |||
.setComponentUuid(change.getProjectUuid()); | |||
dbClient.groupPermissionDao().insert(dbSession, addedDto); | |||
return true; | |||
@@ -134,7 +134,7 @@ public class GroupPermissionChanger { | |||
dbClient.groupPermissionDao().delete(dbSession, | |||
change.getPermission(), | |||
change.getOrganizationUuid(), | |||
change.getGroupIdOrAnyone().getUuid(), | |||
change.getGroupUuidOrAnyone().getUuid(), | |||
change.getProjectUuid()); | |||
return true; | |||
} | |||
@@ -144,21 +144,21 @@ public class GroupPermissionChanger { | |||
if (projectUuid != null) { | |||
return dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, | |||
change.getOrganizationUuid(), | |||
change.getGroupIdOrAnyone().getUuid(), | |||
change.getGroupUuidOrAnyone().getUuid(), | |||
projectUuid); | |||
} | |||
return dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, | |||
change.getOrganizationUuid(), | |||
change.getGroupIdOrAnyone().getUuid()); | |||
change.getGroupUuidOrAnyone().getUuid()); | |||
} | |||
private void checkIfRemainingGlobalAdministrators(DbSession dbSession, GroupPermissionChange change) { | |||
if (SYSTEM_ADMIN.equals(change.getPermission()) && | |||
!change.getGroupIdOrAnyone().isAnyone() && | |||
!change.getGroupUuidOrAnyone().isAnyone() && | |||
change.getProjectUuid() == null) { | |||
// removing global admin permission from group | |||
int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroup(dbSession, | |||
change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupIdOrAnyone().getUuid()); | |||
change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupUuidOrAnyone().getUuid()); | |||
checkRequest(remaining > 0, "Last group with permission '%s'. Permission cannot be removed.", SYSTEM_ADMIN); | |||
} | |||
} |
@@ -75,15 +75,15 @@ public class AddGroupToTemplateAction implements PermissionsWsAction { | |||
public void handle(Request request, Response response) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
String permission = request.mandatoryParam(PARAM_PERMISSION); | |||
GroupUuidOrAnyone groupId = support.findGroup(dbSession, request); | |||
checkRequest(!SYSTEM_ADMIN.equals(permission) || !groupId.isAnyone(), | |||
GroupUuidOrAnyone group = support.findGroup(dbSession, request); | |||
checkRequest(!SYSTEM_ADMIN.equals(permission) || !group.isAnyone(), | |||
format("It is not possible to add the '%s' permission to the group 'Anyone'.", permission)); | |||
PermissionTemplateDto template = support.findTemplate(dbSession, fromRequest(request)); | |||
checkGlobalAdmin(userSession, template.getOrganizationUuid()); | |||
if (!groupAlreadyAdded(dbSession, template.getUuid(), permission, groupId)) { | |||
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), groupId.getUuid(), permission); | |||
if (!groupAlreadyAdded(dbSession, template.getUuid(), permission, group)) { | |||
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission); | |||
dbSession.commit(); | |||
} | |||
} |
@@ -74,10 +74,10 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction { | |||
String permission = request.mandatoryParam(PARAM_PERMISSION); | |||
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.fromRequest(request)); | |||
checkGlobalAdmin(userSession, template.getOrganizationUuid()); | |||
GroupUuidOrAnyone groupId = wsSupport.findGroup(dbSession, request); | |||
checkArgument(groupId.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations"); | |||
GroupUuidOrAnyone group = wsSupport.findGroup(dbSession, request); | |||
checkArgument(group.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations"); | |||
dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), groupId.getUuid(), permission); | |||
dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission); | |||
dbSession.commit(); | |||
} | |||
response.noContent(); |
@@ -145,7 +145,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction { | |||
// grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project | |||
PUBLIC_PERMISSIONS.forEach(permission -> { | |||
dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) | |||
.forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId)); | |||
.forEach(group -> insertProjectPermissionOnGroup(dbSession, component, permission, group)); | |||
dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) | |||
.forEach(userId -> insertProjectPermissionOnUser(dbSession, component, permission, userId)); | |||
}); |
@@ -94,8 +94,8 @@ public class AddUserAction implements UserGroupsWsAction { | |||
} | |||
} | |||
private boolean isMemberOf(DbSession dbSession, UserDto user, GroupDto groupId) { | |||
return dbClient.groupMembershipDao().selectGroupUuidsByUserId(dbSession, user.getId()).contains(groupId.getUuid()); | |||
private boolean isMemberOf(DbSession dbSession, UserDto user, GroupDto group) { | |||
return dbClient.groupMembershipDao().selectGroupUuidsByUserId(dbSession, user.getId()).contains(group.getUuid()); | |||
} | |||
private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) { |
@@ -87,15 +87,15 @@ public class DeleteAction implements UserGroupsWsAction { | |||
checkArgument(remaining > 0, "The last system admin group cannot be deleted"); | |||
} | |||
private void removeGroupPermissions(DbSession dbSession, GroupDto groupId) { | |||
dbClient.roleDao().deleteGroupRolesByGroupUuid(dbSession, groupId.getUuid()); | |||
private void removeGroupPermissions(DbSession dbSession, GroupDto group) { | |||
dbClient.roleDao().deleteGroupRolesByGroupUuid(dbSession, group.getUuid()); | |||
} | |||
private void removeFromPermissionTemplates(DbSession dbSession, GroupDto groupId) { | |||
dbClient.permissionTemplateDao().deleteByGroup(dbSession, groupId.getUuid()); | |||
private void removeFromPermissionTemplates(DbSession dbSession, GroupDto group) { | |||
dbClient.permissionTemplateDao().deleteByGroup(dbSession, group.getUuid()); | |||
} | |||
private void removeGroupMembers(DbSession dbSession, GroupDto groupId) { | |||
dbClient.userGroupDao().deleteByGroupUuid(dbSession, groupId.getUuid()); | |||
private void removeGroupMembers(DbSession dbSession, GroupDto group) { | |||
dbClient.userGroupDao().deleteByGroupUuid(dbSession, group.getUuid()); | |||
} | |||
} |
@@ -72,29 +72,29 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void apply_adds_organization_permission_to_group() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(GlobalPermissions.QUALITY_GATE_ADMIN); | |||
} | |||
@Test | |||
public void apply_adds_organization_permission_to_group_AnyOne() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, null)).containsOnly(GlobalPermissions.QUALITY_GATE_ADMIN); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_adding_any_permission_to_group_AnyOne_on_private_project() { | |||
GroupUuidOrAnyone anyOneGroupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone anyOneGroup = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
permissionService.getAllProjectPermissions() | |||
.forEach(perm -> { | |||
try { | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), anyOneGroup, permissionService)); | |||
fail("a BadRequestException should have been thrown"); | |||
} catch (BadRequestException e) { | |||
assertThat(e).hasMessage("No permission can be granted to Anyone on a private component"); | |||
@@ -107,10 +107,10 @@ public class GroupPermissionChangerTest { | |||
permissionService.getAllProjectPermissions() | |||
.forEach(this::unsafeInsertProjectPermissionOnAnyone); | |||
GroupUuidOrAnyone anyOneGroupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone anyOneGroup = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
permissionService.getAllProjectPermissions() | |||
.forEach(perm -> { | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectUuid(privateProject), anyOneGroup, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, privateProject)).contains(perm); | |||
}); | |||
@@ -142,9 +142,9 @@ public class GroupPermissionChangerTest { | |||
} | |||
private void applyAddsPermissionToGroupOnPrivateProject(String permission) { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); | |||
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission); | |||
@@ -176,78 +176,78 @@ public class GroupPermissionChangerTest { | |||
} | |||
private void applyRemovesPermissionFromGroupOnPrivateProject(String permission) { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertProjectPermissionOnGroup(group, permission, privateProject); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission); | |||
} | |||
@Test | |||
public void apply_has_no_effect_when_adding_USER_permission_to_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); | |||
} | |||
@Test | |||
public void apply_has_no_effect_when_adding_CODEVIEWER_permission_to_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_adding_permission_ADMIN_to_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("It is not possible to add the 'admin' permission to group 'Anyone'"); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
} | |||
@Test | |||
public void apply_adds_permission_ISSUE_ADMIN_to_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(UserRole.ISSUE_ADMIN); | |||
} | |||
@Test | |||
public void apply_adds_permission_SCAN_EXECUTION_to_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(GlobalPermissions.SCAN_EXECUTION); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_removing_USER_permission_from_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Permission user can't be removed from a public component"); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_removing_CODEVIEWER_permission_from_group_AnyOne_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
} | |||
@Test | |||
@@ -266,40 +266,40 @@ public class GroupPermissionChangerTest { | |||
} | |||
private void applyRemovesPermissionFromGroupAnyOneOnAPublicProject(String permission) { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(org.getUuid()); | |||
db.users().insertProjectPermissionOnAnyone(permission, publicProject); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_removing_USER_permission_from_a_group_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Permission user can't be removed from a public component"); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
} | |||
@Test | |||
public void apply_fails_with_BadRequestException_when_removing_CODEVIEWER_permission_from_a_group_on_a_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
} | |||
@Test | |||
public void add_permission_to_anyone() { | |||
OrganizationDto defaultOrganization = db.getDefaultOrganization(); | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(defaultOrganization.getUuid()); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.forAnyone(defaultOrganization.getUuid()); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); | |||
assertThat(db.users().selectAnyonePermissions(defaultOrganization, null)).containsOnly(GlobalPermissions.QUALITY_GATE_ADMIN); | |||
@@ -307,24 +307,24 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void do_nothing_when_adding_permission_that_already_exists() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, ADMINISTER_QUALITY_GATES.getKey(), null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, ADMINISTER_QUALITY_GATES.getKey(), null, groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(ADMINISTER_QUALITY_GATES.getKey()); | |||
} | |||
@Test | |||
public void fail_to_add_global_permission_but_SCAN_and_ADMIN_on_private_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
permissionService.getAllOrganizationPermissions().stream() | |||
.map(OrganizationPermission::getKey) | |||
.filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm)) | |||
.forEach(perm -> { | |||
try { | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), groupUuid, permissionService)); | |||
fail("a BadRequestException should have been thrown for permission " + perm); | |||
} catch (BadRequestException e) { | |||
assertThat(e).hasMessage("Invalid project permission '" + perm + | |||
@@ -335,14 +335,14 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void fail_to_add_global_permission_but_SCAN_and_ADMIN_on_public_project() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
permissionService.getAllOrganizationPermissions().stream() | |||
.map(OrganizationPermission::getKey) | |||
.filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm)) | |||
.forEach(perm -> { | |||
try { | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(publicProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(publicProject), groupUuid, permissionService)); | |||
fail("a BadRequestException should have been thrown for permission " + perm); | |||
} catch (BadRequestException e) { | |||
assertThat(e).hasMessage("Invalid project permission '" + perm + | |||
@@ -353,14 +353,14 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void fail_to_add_project_permission_but_SCAN_and_ADMIN_on_global_group() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
permissionService.getAllProjectPermissions() | |||
.stream() | |||
.filter(perm -> !GlobalPermissions.SCAN_EXECUTION.equals(perm) && !OrganizationPermission.ADMINISTER.getKey().equals(perm)) | |||
.forEach(permission -> { | |||
try { | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, null, groupUuid, permissionService)); | |||
fail("a BadRequestException should have been thrown for permission " + permission); | |||
} catch (BadRequestException e) { | |||
assertThat(e).hasMessage("Invalid global permission '" + permission + "'. Valid values are [admin, gateadmin, profileadmin, provisioning, scan]"); | |||
@@ -370,23 +370,23 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void remove_permission_from_group() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); | |||
db.users().insertPermissionOnGroup(group, PROVISION_PROJECTS); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER_QUALITY_GATES.getKey(), null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER_QUALITY_GATES.getKey(), null, groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(PROVISION_PROJECTS.getKey()); | |||
} | |||
@Test | |||
public void remove_project_permission_from_group() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); | |||
db.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject); | |||
db.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(ADMINISTER_QUALITY_GATES.getKey()); | |||
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(UserRole.CODEVIEWER); | |||
@@ -394,9 +394,9 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void do_not_fail_if_removing_a_permission_that_does_not_exist() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); | |||
assertThat(db.users().selectGroupPermissions(group, privateProject)).isEmpty(); | |||
@@ -404,23 +404,23 @@ public class GroupPermissionChangerTest { | |||
@Test | |||
public void fail_to_remove_admin_permission_if_no_more_admins() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertPermissionOnGroup(group, ADMINISTER); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Last group with permission 'admin'. Permission cannot be removed."); | |||
underTest.apply(db.getSession(), new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupId, permissionService)); | |||
underTest.apply(db.getSession(), new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupUuid, permissionService)); | |||
} | |||
@Test | |||
public void remove_admin_group_if_still_other_admins() { | |||
GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); | |||
GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group); | |||
db.users().insertPermissionOnGroup(group, ADMINISTER); | |||
UserDto admin = db.users().insertUser(); | |||
db.users().insertPermissionOnUser(org, admin, ADMINISTER); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupId, permissionService)); | |||
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupUuid, permissionService)); | |||
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); | |||
} |
@@ -211,7 +211,7 @@ public class RegisterQualityGatesTest { | |||
} | |||
@Test | |||
public void builtin_quality_gate_with_incorrect_metricId_should_not_throw_an_exception() { | |||
public void builtin_quality_gate_with_incorrect_metricuuid_should_not_throw_an_exception() { | |||
insertMetrics(); | |||
QualityGateConditionDto conditionDto = new QualityGateConditionDto() | |||
.setUuid(Uuids.createFast()) |