aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml2
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java24
4 files changed, 9 insertions, 23 deletions
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
index 2dbdc19172d..75b607bff32 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
@@ -68,14 +68,12 @@
<insert id="insert" parameterType="Group" useGeneratedKeys="false">
insert into groups (
uuid,
- organization_uuid,
name,
description,
created_at,
updated_at
) values (
#{uuid,jdbcType=VARCHAR},
- 'asd',
#{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP},
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 25052cb6ecc..eba030939d8 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -325,14 +325,14 @@ CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID", "COMPONENT_UUID", "ROLE");
CREATE TABLE "GROUPS"(
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "NAME" VARCHAR(500),
+ "NAME" VARCHAR(500) NOT NULL,
"DESCRIPTION" VARCHAR(200),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUPS_NAME" ON "GROUPS"("NAME");
CREATE TABLE "GROUPS_USERS"(
"GROUP_UUID" VARCHAR(40) NOT NULL,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
index 4d1443c728a..97f6c71dbfb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
@@ -137,7 +137,7 @@ public class AuthorizationDaoTest {
db.users().insertMember(group2, user3);
// group3 has the permission "perm1" but has no users
- GroupDto group3 = db.users().insertGroup("g2");
+ GroupDto group3 = db.users().insertGroup("g3");
db.users().insertPermissionOnGroup(group3, "perm1");
db.users().insertPermissionOnUser(user4, "perm1");
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
index 7ee38344a1e..a916bf7de82 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.function.Consumer;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.security.DefaultGroups;
import org.sonar.api.web.UserRole;
import org.sonar.core.util.Uuids;
import org.sonar.core.util.stream.MoreCollectors;
@@ -40,10 +41,10 @@ import org.sonar.db.permission.UserPermissionDto;
import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
-import static java.lang.String.format;
import static java.util.Arrays.stream;
import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
+import static org.sonar.db.user.GroupTesting.newGroupDto;
public class UserDbTester {
private static final Set<String> PUBLIC_PERMISSIONS = ImmutableSet.of(UserRole.USER, UserRole.CODEVIEWER); // FIXME to check with Simon
@@ -141,12 +142,12 @@ public class UserDbTester {
// GROUPS
public GroupDto insertGroup(String name) {
- GroupDto group = GroupTesting.newGroupDto().setName(name);
+ GroupDto group = newGroupDto().setName(name);
return insertGroup(group);
}
public GroupDto insertGroup() {
- GroupDto group = GroupTesting.newGroupDto();
+ GroupDto group = newGroupDto();
return insertGroup(group);
}
@@ -156,25 +157,12 @@ public class UserDbTester {
return dto;
}
- public GroupDto insertDefaultGroup(GroupDto dto) {
- db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), db.getDefaultOrganization().getUuid())
- .ifPresent(groupUuid -> {
- throw new IllegalArgumentException(format("Organization '%s' has already a default group", db.getDefaultOrganization().getUuid()));
- });
- db.getDbClient().groupDao().insert(db.getSession(), dto);
- db.getDbClient().organizationDao().setDefaultGroupUuid(db.getSession(), db.getDefaultOrganization().getUuid(), dto);
+ public GroupDto insertDefaultGroup() {
+ GroupDto dto = db.getDbClient().groupDao().insert(db.getSession(), newGroupDto().setName(DefaultGroups.USERS).setDescription("Users"));
db.commit();
return dto;
}
- public GroupDto insertDefaultGroup(String name) {
- return insertDefaultGroup(GroupTesting.newGroupDto().setName(name));
- }
-
- public GroupDto insertDefaultGroup() {
- return insertDefaultGroup(GroupTesting.newGroupDto());
- }
-
@CheckForNull
public GroupDto selectGroupByUuid(String groupUuid) {
return db.getDbClient().groupDao().selectByUuid(db.getSession(), groupUuid);