@@ -58,7 +58,6 @@ public class UserPermissionDao implements Dao { | |||
return paginate(mapper(dbSession).selectUserIdsByQueryAndScope(query), query); | |||
} | |||
private static List<Integer> paginate(List<Integer> results, PermissionQuery query) { | |||
return results | |||
.stream() | |||
@@ -86,8 +85,8 @@ public class UserPermissionDao implements Dao { | |||
* | |||
* @return the global permissions. An empty list is returned if user or organization do not exist. | |||
*/ | |||
public List<String> selectGlobalPermissionsOfUser(DbSession dbSession, int userId, String organizationUuid) { | |||
return mapper(dbSession).selectGlobalPermissionsOfUser(userId, organizationUuid); | |||
public List<String> selectGlobalPermissionsOfUser(DbSession dbSession, String userUuid, String organizationUuid) { | |||
return mapper(dbSession).selectGlobalPermissionsOfUser(userUuid, organizationUuid); | |||
} | |||
/** | |||
@@ -95,12 +94,12 @@ public class UserPermissionDao implements Dao { | |||
* | |||
* @return the project permissions. An empty list is returned if project or user do not exist. | |||
*/ | |||
public List<String> selectProjectPermissionsOfUser(DbSession dbSession, int userId, String projectUuid) { | |||
return mapper(dbSession).selectProjectPermissionsOfUser(userId, projectUuid); | |||
public List<String> selectProjectPermissionsOfUser(DbSession dbSession, String userUuid, String projectUuid) { | |||
return mapper(dbSession).selectProjectPermissionsOfUser(userUuid, projectUuid); | |||
} | |||
public Set<Integer> selectUserIdsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) { | |||
return mapper(session).selectUserIdsWithPermissionOnProjectBut(projectUuid, permission); | |||
public Set<String> selectUserUuidsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) { | |||
return mapper(session).selectUserUuidsWithPermissionOnProjectBut(projectUuid, permission); | |||
} | |||
public void insert(DbSession dbSession, UserPermissionDto dto) { | |||
@@ -122,15 +121,15 @@ public class UserPermissionDao implements Dao { | |||
/** | |||
* Removes a single global permission from user | |||
*/ | |||
public void deleteGlobalPermission(DbSession dbSession, int userId, String permission, String organizationUuid) { | |||
mapper(dbSession).deleteGlobalPermission(userId, permission, organizationUuid); | |||
public void deleteGlobalPermission(DbSession dbSession, String userUuid, String permission, String organizationUuid) { | |||
mapper(dbSession).deleteGlobalPermission(userUuid, permission, organizationUuid); | |||
} | |||
/** | |||
* Removes a single project permission from user | |||
*/ | |||
public void deleteProjectPermission(DbSession dbSession, int userId, String permission, String projectUuid) { | |||
mapper(dbSession).deleteProjectPermission(userId, permission, projectUuid); | |||
public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, String projectUuid) { | |||
mapper(dbSession).deleteProjectPermission(userUuid, permission, projectUuid); | |||
} | |||
/** | |||
@@ -151,12 +150,12 @@ public class UserPermissionDao implements Dao { | |||
mapper(dbSession).deleteByOrganization(organizationUuid); | |||
} | |||
public void deleteOrganizationMemberPermissions(DbSession dbSession, String organizationUuid, int userId) { | |||
mapper(dbSession).deleteOrganizationMemberPermissions(organizationUuid, userId); | |||
public void deleteOrganizationMemberPermissions(DbSession dbSession, String organizationUuid, String userUuid) { | |||
mapper(dbSession).deleteOrganizationMemberPermissions(organizationUuid, userUuid); | |||
} | |||
public void deleteByUserId(DbSession dbSession, int userId) { | |||
mapper(dbSession).deleteByUserId(userId); | |||
public void deleteByUserUuid(DbSession dbSession, String userUuid) { | |||
mapper(dbSession).deleteByUserUuid(userUuid); | |||
} | |||
private static UserPermissionMapper mapper(DbSession dbSession) { |
@@ -26,18 +26,18 @@ public class UserPermissionDto { | |||
private String uuid; | |||
private String organizationUuid; | |||
private String permission; | |||
private int userId; | |||
private String userUuid; | |||
private String componentUuid; | |||
public UserPermissionDto() { | |||
// used by MyBatis | |||
} | |||
public UserPermissionDto(String uuid, String organizationUuid, String permission, int userId, @Nullable String componentUuid) { | |||
public UserPermissionDto(String uuid, String organizationUuid, String permission, String userUuid, @Nullable String componentUuid) { | |||
this.uuid = uuid; | |||
this.organizationUuid = organizationUuid; | |||
this.permission = permission; | |||
this.userId = userId; | |||
this.userUuid = userUuid; | |||
this.componentUuid = componentUuid; | |||
} | |||
@@ -49,8 +49,8 @@ public class UserPermissionDto { | |||
return permission; | |||
} | |||
public int getUserId() { | |||
return userId; | |||
public String getUserUuid() { | |||
return userUuid; | |||
} | |||
public String getOrganizationUuid() { | |||
@@ -69,7 +69,7 @@ public class UserPermissionDto { | |||
public String toString() { | |||
StringBuilder sb = new StringBuilder("UserPermissionDto{"); | |||
sb.append("permission='").append(permission).append('\''); | |||
sb.append(", userId=").append(userId); | |||
sb.append(", userUuid=").append(userUuid); | |||
sb.append(", organizationUuid=").append(organizationUuid); | |||
sb.append(", componentUuid=").append(componentUuid); | |||
sb.append('}'); |
@@ -50,27 +50,27 @@ public interface UserPermissionMapper { | |||
/** | |||
* select id of users with at least one permission on the specified project but which do not have the specified permission. | |||
*/ | |||
Set<Integer> selectUserIdsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("permission") String permission); | |||
Set<String> selectUserUuidsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("permission") String permission); | |||
void insert(UserPermissionDto dto); | |||
void deleteGlobalPermission(@Param("userId") int userId, @Param("permission") String permission, | |||
void deleteGlobalPermission(@Param("userUuid") String userUuid, @Param("permission") String permission, | |||
@Param("organizationUuid") String organizationUuid); | |||
void deleteProjectPermission(@Param("userId") int userId, @Param("permission") String permission, | |||
void deleteProjectPermission(@Param("userUuid") String userUuid, @Param("permission") String permission, | |||
@Param("projectUuid") String projectUuid); | |||
void deleteProjectPermissions(@Param("projectUuid") String projectUuid); | |||
int deleteProjectPermissionOfAnyUser(@Param("projectUuid") String projectUuid, @Param("permission") String permission); | |||
List<String> selectGlobalPermissionsOfUser(@Param("userId") int userId, @Param("organizationUuid") String organizationUuid); | |||
List<String> selectGlobalPermissionsOfUser(@Param("userUuid") String userUuid, @Param("organizationUuid") String organizationUuid); | |||
List<String> selectProjectPermissionsOfUser(@Param("userId") int userId, @Param("projectUuid") String projectUuid); | |||
List<String> selectProjectPermissionsOfUser(@Param("userUuid") String userUuid, @Param("projectUuid") String projectUuid); | |||
void deleteByOrganization(@Param("organizationUuid") String organizationUuid); | |||
void deleteOrganizationMemberPermissions(@Param("organizationUuid") String organizationUuid, @Param("userId") int login); | |||
void deleteOrganizationMemberPermissions(@Param("organizationUuid") String organizationUuid, @Param("userUuid") String userUuid); | |||
void deleteByUserId(@Param("userId") int userId); | |||
void deleteByUserUuid(@Param("userUuid") String userUuid); | |||
} |
@@ -150,8 +150,7 @@ | |||
from organizations org | |||
inner join user_roles ur on | |||
ur.organization_uuid = org.uuid | |||
inner join users u on ur.user_id = u.id | |||
and u.uuid = #{userUuid,jdbcType=VARCHAR} | |||
and ur.user_uuid = #{userUuid,jdbcType=VARCHAR} | |||
and ur.component_uuid is null | |||
and ur.role = #{permission,jdbcType=VARCHAR} | |||
union |
@@ -25,10 +25,9 @@ | |||
select ur.role | |||
from user_roles ur | |||
inner join users u on ur.user_id=u.id | |||
where | |||
ur.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and | |||
u.uuid=#{userUuid, jdbcType=VARCHAR} | |||
ur.user_uuid=#{userUuid, jdbcType=VARCHAR} | |||
and ur.component_uuid is null | |||
</select> | |||
@@ -56,9 +55,8 @@ | |||
union | |||
select u.uuid | |||
select ur.user_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id = u.id | |||
where | |||
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and | |||
ur.component_uuid is null and | |||
@@ -81,14 +79,13 @@ | |||
union | |||
select u.uuid | |||
select ur.user_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id = u.id | |||
where | |||
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and | |||
ur.component_uuid is null and | |||
ur.role = #{permission, jdbcType=VARCHAR} and | |||
u.uuid != #{excludedUserUuid, jdbcType=VARCHAR} | |||
ur.user_uuid != #{excludedUserUuid, jdbcType=VARCHAR} | |||
) remaining | |||
</select> | |||
@@ -104,9 +101,8 @@ | |||
union | |||
select u.uuid | |||
select ur.user_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id = u.id | |||
where | |||
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and | |||
ur.component_uuid is null and | |||
@@ -128,9 +124,8 @@ | |||
union | |||
select u.uuid | |||
select ur.user_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id = u.id | |||
where | |||
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and | |||
ur.component_uuid is null and | |||
@@ -152,14 +147,13 @@ | |||
union | |||
select u.uuid | |||
select ur.user_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id=u.id | |||
where | |||
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and | |||
ur.component_uuid is null and | |||
ur.role = #{permission, jdbcType=VARCHAR} and | |||
u.uuid != #{userUuid, jdbcType=VARCHAR} | |||
ur.user_uuid != #{userUuid, jdbcType=VARCHAR} | |||
) remaining | |||
</select> | |||
@@ -177,11 +171,10 @@ | |||
select ur.organization_uuid | |||
from user_roles ur | |||
inner join users u on ur.user_id=u.id | |||
where | |||
ur.component_uuid is null and | |||
ur.role = #{permission, jdbcType=VARCHAR} and | |||
u.uuid = #{userUuid, jdbcType=VARCHAR} | |||
ur.user_uuid = #{userUuid, jdbcType=VARCHAR} | |||
</select> | |||
<select id="keepAuthorizedProjectUuidsForUser" parameterType="map" resultType="String"> | |||
@@ -213,12 +206,11 @@ | |||
p.uuid | |||
from | |||
user_roles ur | |||
inner join users u on ur.user_id=u.id | |||
inner join components p on | |||
p.uuid = ur.component_uuid | |||
where | |||
ur.role=#{role, jdbcType=VARCHAR} | |||
and u.uuid=#{userUuid, jdbcType=INTEGER} | |||
and ur.user_uuid=#{userUuid, jdbcType=INTEGER} | |||
and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or "> | |||
p.uuid=#{element, jdbcType=VARCHAR} | |||
</foreach> | |||
@@ -276,14 +268,13 @@ | |||
union | |||
select | |||
u.uuid | |||
ur.user_uuid | |||
from | |||
user_roles ur | |||
inner join users u on ur.user_id=u.id | |||
where | |||
ur.component_uuid=#{componentUuid, jdbcType=VARCHAR} | |||
and ur.role=#{role, jdbcType=VARCHAR} | |||
and u.uuid IN | |||
and ur.user_uuid IN | |||
<foreach collection="userUuids" open="(" close=")" item="uuid" separator=","> | |||
#{uuid, jdbcType=VARCHAR} | |||
</foreach> | |||
@@ -315,11 +306,10 @@ | |||
select ur.role | |||
from user_roles ur | |||
inner join components p on p.uuid = ur.component_uuid | |||
inner join users u on ur.user_id=u.id | |||
where | |||
p.uuid = #{projectUuid, jdbcType=VARCHAR} and | |||
p.organization_uuid = ur.organization_uuid and | |||
u.uuid = #{userUuid, jdbcType=VARCHAR} | |||
ur.user_uuid = #{userUuid, jdbcType=VARCHAR} | |||
union | |||
@@ -362,7 +352,7 @@ | |||
from | |||
users u | |||
inner join user_roles ur on | |||
ur.user_id = u.id | |||
ur.user_uuid = u.uuid | |||
and ur.role=#{permission, jdbcType=VARCHAR} | |||
and ur.component_uuid is null | |||
where | |||
@@ -399,7 +389,7 @@ | |||
where | |||
p.kee = #{projectKey, jdbcType=VARCHAR} | |||
and ur.role = #{permission, jdbcType=VARCHAR} | |||
and ur.user_id = u.id | |||
and ur.user_uuid = u.uuid | |||
) or exists ( | |||
select 1 | |||
from components p |
@@ -5,7 +5,7 @@ | |||
<select id="selectUserPermissionsByQueryAndUserIds" parameterType="map" resultType="org.sonar.db.permission.UserPermissionDto"> | |||
select | |||
u.id as userId, | |||
u.uuid as userUuid, | |||
ur.organization_uuid as organizationUuid, | |||
ur.component_uuid as componentUuid, | |||
ur.role as permission | |||
@@ -31,7 +31,7 @@ | |||
select | |||
u.id, lower(u.name) | |||
from users u | |||
left join user_roles ur on ur.user_id = u.id and ur.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} | |||
left join user_roles ur on ur.user_uuid = u.uuid and ur.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} | |||
<choose> | |||
<when test="query.componentUuid == null"> | |||
and ur.component_uuid is null | |||
@@ -59,7 +59,7 @@ | |||
<sql id="sqlQueryJoins"> | |||
from users u | |||
left join user_roles ur on ur.user_id = u.id | |||
left join user_roles ur on ur.user_uuid = u.uuid | |||
left join components p on ur.component_uuid = p.uuid | |||
inner join organization_members om on u.uuid=om.user_uuid and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} | |||
</sql> | |||
@@ -93,7 +93,7 @@ | |||
from user_roles ur | |||
where | |||
ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and | |||
ur.user_id = #{userId,jdbcType=INTEGER} and | |||
ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and | |||
ur.component_uuid is null | |||
</select> | |||
@@ -101,23 +101,23 @@ | |||
select ur.role | |||
from user_roles ur | |||
where | |||
ur.user_id = #{userId,jdbcType=INTEGER} and | |||
ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and | |||
ur.component_uuid = #{projectUuid,jdbcType=VARCHAR} | |||
</select> | |||
<select id="countUsersByProjectPermission" resultType="org.sonar.db.permission.CountPerProjectPermission"> | |||
select ur.component_uuid as componentUuid, ur.role as permission, count(u.login) as count | |||
from users u | |||
inner join user_roles ur on ur.user_id = u.id | |||
inner join user_roles ur on ur.user_uuid = u.uuid | |||
inner join components p on p.uuid = ur.component_uuid | |||
where u.active = ${_true} | |||
and p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" separator=",">#{projectUuid}</foreach> | |||
group by ur.component_uuid, ur.role | |||
</select> | |||
<select id="selectUserIdsWithPermissionOnProjectBut" resultType="Integer"> | |||
<select id="selectUserUuidsWithPermissionOnProjectBut" resultType="String"> | |||
select | |||
distinct ur1.user_id | |||
distinct ur1.user_uuid | |||
from | |||
user_roles ur1 | |||
where | |||
@@ -130,7 +130,7 @@ | |||
user_roles ur2 | |||
where | |||
ur2.component_uuid = ur1.component_uuid | |||
and ur2.user_id = ur1.user_id | |||
and ur2.user_uuid = ur1.user_uuid | |||
and role = #{permission,jdbcType=VARCHAR} | |||
) | |||
</select> | |||
@@ -139,13 +139,13 @@ | |||
insert into user_roles ( | |||
uuid, | |||
organization_uuid, | |||
user_id, | |||
user_uuid, | |||
component_uuid, | |||
role | |||
) values ( | |||
#{uuid,jdbcType=VARCHAR}, | |||
#{organizationUuid,jdbcType=VARCHAR}, | |||
#{userId,jdbcType=INTEGER}, | |||
#{userUuid,jdbcType=VARCHAR}, | |||
#{componentUuid,jdbcType=VARCHAR}, | |||
#{permission,jdbcType=VARCHAR} | |||
) | |||
@@ -155,7 +155,7 @@ | |||
delete from user_roles | |||
where | |||
role = #{permission,jdbcType=VARCHAR} and | |||
user_id = #{userId,jdbcType=INTEGER} and | |||
user_uuid = #{userUuid,jdbcType=VARCHAR} and | |||
organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and | |||
component_uuid is null | |||
</delete> | |||
@@ -164,7 +164,7 @@ | |||
delete from user_roles | |||
where | |||
role = #{permission,jdbcType=VARCHAR} and | |||
user_id = #{userId,jdbcType=INTEGER} and | |||
user_uuid = #{userUuid,jdbcType=VARCHAR} and | |||
component_uuid = #{projectUuid,jdbcType=VARCHAR} | |||
</delete> | |||
@@ -194,10 +194,10 @@ | |||
user_roles | |||
where | |||
organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and | |||
user_id = #{userId,jdbcType=INTEGER} | |||
user_uuid = #{userUuid,jdbcType=VARCHAR} | |||
</delete> | |||
<delete id="deleteByUserId" parameterType="int"> | |||
DELETE FROM user_roles WHERE user_id=#{userId,jdbcType=INTEGER} | |||
<delete id="deleteByUserUuid" parameterType="String"> | |||
DELETE FROM user_roles WHERE user_uuid=#{userUuid,jdbcType=VARCHAR} | |||
</delete> | |||
</mapper> |
@@ -8,9 +8,8 @@ | |||
ur.component_uuid | |||
from | |||
user_roles ur | |||
inner join users u on ur.user_id = u.id | |||
where | |||
u.uuid = #{userUuid,jdbcType=VARCHAR} | |||
ur.user_uuid = #{userUuid,jdbcType=VARCHAR} | |||
and ur.role = #{permission,jdbcType=VARCHAR} | |||
and ur.component_uuid is not null | |||
union |
@@ -915,14 +915,14 @@ CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES"("USER_U | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(40) | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID"); | |||
CREATE TABLE "USER_TOKENS"( | |||
"USER_UUID" VARCHAR(255) NOT NULL, |
@@ -397,23 +397,23 @@ public class UserPermissionDaoTest { | |||
addProjectPermission(organization, "perm4", user2, project2); | |||
// user2 does not have global permissions -> do nothing | |||
underTest.deleteGlobalPermission(dbSession, user2.getId(), "perm1", db.getDefaultOrganization().getUuid()); | |||
underTest.deleteGlobalPermission(dbSession, user2.getUuid(), "perm1", db.getDefaultOrganization().getUuid()); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); | |||
// global permission is not granted -> do nothing | |||
underTest.deleteGlobalPermission(dbSession, user1.getId(), "notGranted", db.getDefaultOrganization().getUuid()); | |||
underTest.deleteGlobalPermission(dbSession, user1.getUuid(), "notGranted", db.getDefaultOrganization().getUuid()); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); | |||
// permission is on project -> do nothing | |||
underTest.deleteGlobalPermission(dbSession, user1.getId(), "perm3", db.getDefaultOrganization().getUuid()); | |||
underTest.deleteGlobalPermission(dbSession, user1.getUuid(), "perm3", db.getDefaultOrganization().getUuid()); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); | |||
// global permission on another organization-> do nothing | |||
underTest.deleteGlobalPermission(dbSession, user1.getId(), "notGranted", "anotherOrg"); | |||
underTest.deleteGlobalPermission(dbSession, user1.getUuid(), "notGranted", "anotherOrg"); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); | |||
// global permission exists -> delete it, but not the project permission with the same name ! | |||
underTest.deleteGlobalPermission(dbSession, user1.getId(), "perm1", organization.getUuid()); | |||
underTest.deleteGlobalPermission(dbSession, user1.getUuid(), "perm1", organization.getUuid()); | |||
assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='perm1' and component_uuid is null")).isEqualTo(0); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4); | |||
} | |||
@@ -431,10 +431,10 @@ public class UserPermissionDaoTest { | |||
addProjectPermission(organization, "perm", user2, project1); | |||
// no such provision -> ignore | |||
underTest.deleteProjectPermission(dbSession, user1.getId(), "anotherPerm", project1.uuid()); | |||
underTest.deleteProjectPermission(dbSession, user1.getUuid(), "anotherPerm", project1.uuid()); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4); | |||
underTest.deleteProjectPermission(dbSession, user1.getId(), "perm", project1.uuid()); | |||
underTest.deleteProjectPermission(dbSession, user1.getUuid(), "perm", project1.uuid()); | |||
assertThatProjectPermissionDoesNotExist(user1, "perm", project1); | |||
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3); | |||
} | |||
@@ -470,10 +470,10 @@ public class UserPermissionDaoTest { | |||
addProjectPermission(organization, "perm4", user1, project); | |||
addProjectPermission(organization, "perm5", user1, project); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), org.getUuid())).containsOnly("perm3"); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), db.getDefaultOrganization().getUuid())).containsOnly("perm1"); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), "otherOrg")).isEmpty(); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user3.getId(), org.getUuid())).isEmpty(); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid(), org.getUuid())).containsOnly("perm3"); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid(), db.getDefaultOrganization().getUuid())).containsOnly("perm1"); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid(), "otherOrg")).isEmpty(); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user3.getUuid(), org.getUuid())).isEmpty(); | |||
} | |||
@Test | |||
@@ -490,9 +490,9 @@ public class UserPermissionDaoTest { | |||
addProjectPermission(organization, "perm4", user1, project2); | |||
addProjectPermission(organization, "perm5", user2, project1); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).containsOnly("perm2", "perm3"); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly("perm4"); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project3.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project1.uuid())).containsOnly("perm2", "perm3"); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly("perm4"); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project3.uuid())).isEmpty(); | |||
} | |||
@Test | |||
@@ -502,7 +502,7 @@ public class UserPermissionDaoTest { | |||
UserDto user = insertUser(organization); | |||
db.users().insertProjectPermissionOnUser(user, "foo", project); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER)) | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER)) | |||
.isEmpty(); | |||
} | |||
@@ -515,12 +515,12 @@ public class UserPermissionDaoTest { | |||
db.users().insertProjectPermissionOnUser(user1, "p1", project); | |||
db.users().insertProjectPermissionOnUser(user2, "p2", project); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2")) | |||
.containsOnly(user1.getId()); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1")) | |||
.containsOnly(user2.getId()); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3")) | |||
.containsOnly(user1.getId(), user2.getId()); | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2")) | |||
.containsOnly(user1.getUuid()); | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1")) | |||
.containsOnly(user2.getUuid()); | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3")) | |||
.containsOnly(user1.getUuid(), user2.getUuid()); | |||
} | |||
@Test | |||
@@ -532,10 +532,10 @@ public class UserPermissionDaoTest { | |||
db.users().insertProjectPermissionOnUser(user1, "p1", project); | |||
db.users().insertProjectPermissionOnUser(user2, "p2", project); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2")) | |||
.containsOnly(user1.getId()); | |||
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1")) | |||
.containsOnly(user2.getId()); | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2")) | |||
.containsOnly(user1.getUuid()); | |||
assertThat(underTest.selectUserUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1")) | |||
.containsOnly(user2.getUuid()); | |||
} | |||
@Test | |||
@@ -599,7 +599,7 @@ public class UserPermissionDaoTest { | |||
db.users().insertPermissionOnUser(organization1, user2, SCAN); | |||
db.users().insertProjectPermissionOnUser(user2, UserRole.CODEVIEWER, project); | |||
underTest.deleteOrganizationMemberPermissions(dbSession, organization1.getUuid(), user1.getId()); | |||
underTest.deleteOrganizationMemberPermissions(dbSession, organization1.getUuid(), user1.getUuid()); | |||
dbSession.commit(); | |||
// user 1 permissions | |||
@@ -623,12 +623,12 @@ public class UserPermissionDaoTest { | |||
db.users().insertPermissionOnUser(user2, SCAN); | |||
db.users().insertProjectPermissionOnUser(user2, ADMINISTER_QUALITY_GATES.getKey(), project); | |||
underTest.deleteByUserId(dbSession, user1.getId()); | |||
underTest.deleteByUserUuid(dbSession, user1.getUuid()); | |||
dbSession.commit(); | |||
assertThat(db.select("select user_id as \"userId\", component_uuid as \"projectUuid\", role as \"permission\" from user_roles")) | |||
.extracting((row) -> row.get("userId"), (row) -> row.get("projectUuid"), (row) -> row.get("permission")) | |||
.containsOnly(tuple(user2.getId().longValue(), null, SCAN.getKey()), tuple(user2.getId().longValue(), project.uuid(), ADMINISTER_QUALITY_GATES.getKey())); | |||
assertThat(db.select("select user_uuid as \"userUuid\", component_uuid as \"projectUuid\", role as \"permission\" from user_roles")) | |||
.extracting((row) -> row.get("userUuid"), (row) -> row.get("projectUuid"), (row) -> row.get("permission")) | |||
.containsOnly(tuple(user2.getUuid(), null, SCAN.getKey()), tuple(user2.getUuid(), project.uuid(), ADMINISTER_QUALITY_GATES.getKey())); | |||
} | |||
@Test | |||
@@ -640,7 +640,7 @@ public class UserPermissionDaoTest { | |||
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey()); | |||
assertThat(deletedCount).isEqualTo(0); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
} | |||
@Test | |||
@@ -653,7 +653,7 @@ public class UserPermissionDaoTest { | |||
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey()); | |||
assertThat(deletedCount).isEqualTo(0); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
} | |||
@Test | |||
@@ -667,8 +667,8 @@ public class UserPermissionDaoTest { | |||
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1"); | |||
assertThat(deletedCount).isEqualTo(0); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getUuid(), project.uuid())).containsOnly(SCAN.getKey()); | |||
} | |||
@Test | |||
@@ -689,22 +689,22 @@ public class UserPermissionDaoTest { | |||
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey()); | |||
assertThat(deletedCount).isEqualTo(2); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.uuid())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project2.uuid())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey()); | |||
deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey()); | |||
assertThat(deletedCount).isEqualTo(2); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getId(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.uuid())).containsOnly(PROVISION_PROJECTS.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getUuid(), organization.getUuid())).containsOnly(SCAN.getKey()); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project1.uuid())).isEmpty(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly(); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project2.uuid())).containsOnly(PROVISION_PROJECTS.getKey()); | |||
} | |||
private ComponentDto randomPublicOrPrivateProject(OrganizationDto organization) { | |||
@@ -746,35 +746,35 @@ public class UserPermissionDaoTest { | |||
List<UserPermissionDto> currentPermissions = underTest.selectUserPermissionsByQuery(dbSession, query, expectedUserIds); | |||
assertThat(currentPermissions).hasSize(expectedPermissions.length); | |||
Tuple[] expectedPermissionsAsTuple = Arrays.stream(expectedPermissions) | |||
.map(expectedPermission -> tuple(expectedPermission.getUserId(), expectedPermission.getPermission(), expectedPermission.getComponentUuid(), | |||
.map(expectedPermission -> tuple(expectedPermission.getUserUuid(), expectedPermission.getPermission(), expectedPermission.getComponentUuid(), | |||
expectedPermission.getOrganizationUuid())) | |||
.toArray(Tuple[]::new); | |||
assertThat(currentPermissions) | |||
.extracting(UserPermissionDto::getUserId, UserPermissionDto::getPermission, UserPermissionDto::getComponentUuid, UserPermissionDto::getOrganizationUuid) | |||
.extracting(UserPermissionDto::getUserUuid, UserPermissionDto::getPermission, UserPermissionDto::getComponentUuid, UserPermissionDto::getOrganizationUuid) | |||
.containsOnly(expectedPermissionsAsTuple); | |||
// test method "countUsers()" | |||
long distinctUsers = stream(expectedPermissions).mapToLong(UserPermissionDto::getUserId).distinct().count(); | |||
long distinctUsers = stream(expectedPermissions).map(UserPermissionDto::getUserUuid).distinct().count(); | |||
assertThat((long) underTest.countUsersByQuery(dbSession, query)).isEqualTo(distinctUsers); | |||
} | |||
private UserPermissionDto addGlobalPermission(OrganizationDto org, String permission, UserDto user) { | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getId(), null); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getUuid(), null); | |||
underTest.insert(dbSession, dto); | |||
db.commit(); | |||
return dto; | |||
} | |||
private UserPermissionDto addProjectPermission(OrganizationDto org, String permission, UserDto user, ComponentDto project) { | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getId(), project.uuid()); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getUuid(), project.uuid()); | |||
underTest.insert(dbSession, dto); | |||
db.commit(); | |||
return dto; | |||
} | |||
private void assertThatProjectPermissionDoesNotExist(UserDto user, String permission, ComponentDto project) { | |||
assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='" + permission + "' and user_id=" + user.getId() | |||
+ " and component_uuid='" + project.uuid() + "'")) | |||
assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='" + permission + "' and user_uuid='" + user.getUuid() | |||
+ "' and component_uuid='" + project.uuid() + "'")) | |||
.isEqualTo(0); | |||
} | |||
@@ -783,12 +783,12 @@ public class UserPermissionDaoTest { | |||
} | |||
private void assertOrgPermissionsOfUser(UserDto user, OrganizationDto organization, OrganizationPermission... permissions) { | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid()).stream() | |||
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid(), organization.getUuid()).stream() | |||
.map(OrganizationPermission::fromKey)) | |||
.containsOnly(permissions); | |||
} | |||
private void assertProjectPermissionsOfUser(UserDto user, ComponentDto project, String... permissions) { | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).containsOnly(permissions); | |||
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getUuid(), project.uuid())).containsOnly(permissions); | |||
} | |||
} |
@@ -326,7 +326,7 @@ public class UserDbTester { | |||
*/ | |||
@Deprecated | |||
public UserPermissionDto insertPermissionOnUser(OrganizationDto org, UserDto user, String permission) { | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getId(), null); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), org.getUuid(), permission, user.getUuid(), null); | |||
db.getDbClient().userPermissionDao().insert(db.getSession(), dto); | |||
db.commit(); | |||
return dto; | |||
@@ -340,12 +340,12 @@ public class UserDbTester { | |||
} | |||
public void deletePermissionFromUser(OrganizationDto org, UserDto user, OrganizationPermission permission) { | |||
db.getDbClient().userPermissionDao().deleteGlobalPermission(db.getSession(), user.getId(), permission.getKey(), org.getUuid()); | |||
db.getDbClient().userPermissionDao().deleteGlobalPermission(db.getSession(), user.getUuid(), permission.getKey(), org.getUuid()); | |||
db.commit(); | |||
} | |||
public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) { | |||
db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getId(), permission, project.uuid()); | |||
db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getUuid(), permission, project.uuid()); | |||
db.commit(); | |||
} | |||
@@ -356,7 +356,7 @@ public class UserDbTester { | |||
checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission), | |||
"%s can't be granted on a public project", permission); | |||
checkArgument(project.getMainBranchProjectUuid() == null, "Permissions can't be granted on branches"); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), project.getOrganizationUuid(), permission, user.getId(), project.uuid()); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), project.getOrganizationUuid(), permission, user.getUuid(), project.uuid()); | |||
db.getDbClient().userPermissionDao().insert(db.getSession(), dto); | |||
db.commit(); | |||
return dto; | |||
@@ -364,11 +364,11 @@ public class UserDbTester { | |||
public List<OrganizationPermission> selectPermissionsOfUser(UserDto user, OrganizationDto organization) { | |||
return toListOfOrganizationPermissions(db.getDbClient().userPermissionDao() | |||
.selectGlobalPermissionsOfUser(db.getSession(), user.getId(), organization.getUuid())); | |||
.selectGlobalPermissionsOfUser(db.getSession(), user.getUuid(), organization.getUuid())); | |||
} | |||
public List<String> selectProjectPermissionsOfUser(UserDto user, ComponentDto project) { | |||
return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.uuid()); | |||
return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getUuid(), project.uuid()); | |||
} | |||
private static List<OrganizationPermission> toListOfOrganizationPermissions(List<String> keys) { |
@@ -288,6 +288,11 @@ import org.sonar.server.platform.db.migration.version.v83.users.fk.qprofileeditu | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.qprofileeditusers.DropUserIdColumnOfQProfileEditUsersTable; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.qprofileeditusers.MakeQProfileEditUsersUserUuidColumnNotNullable; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.qprofileeditusers.PopulateQProfileEditUsersUserUuid; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.userroles.AddIndexOnUserUuidOfUserRolesTable; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.userroles.AddUserUuidColumnToUserRoles; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.userroles.DropIndexOnUserIdOfUserRolesTable; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.userroles.DropUserIdColumnOfUserRolesTable; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.userroles.PopulateUserRolesUserUuid; | |||
import org.sonar.server.platform.db.migration.version.v83.usertokens.AddPrimaryKeyOnUuidColumnOfUserTokensTable; | |||
import org.sonar.server.platform.db.migration.version.v83.usertokens.AddUuidColumnToUserTokens; | |||
import org.sonar.server.platform.db.migration.version.v83.usertokens.DropIdColumnOfUserTokensTable; | |||
@@ -684,17 +689,23 @@ public class DbVersion83 implements DbVersion { | |||
.add(3654, "Drop column on 'user_id' column of 'PERM_TEMPLATES_USERS' table", DropUserIdColumnOfPermTemplatesUsersTable.class) | |||
// Migration of FK in PROPERTIES to USERS | |||
.add(3616, "Add 'user_uuid' column on 'PROPERTIES' table", AddUserUuidColumnToPropertiesUsers.class) | |||
.add(3617, "Populate 'user_uuid' for 'PROPERTIES'", PopulatePropertiesUserUuid.class) | |||
.add(3618, "Drop column on 'user_id' column of 'PROPERTIES' table", DropUserIdColumnOfPropertiesTable.class) | |||
.add(3655, "Add 'user_uuid' column on 'PROPERTIES' table", AddUserUuidColumnToPropertiesUsers.class) | |||
.add(3656, "Populate 'user_uuid' for 'PROPERTIES'", PopulatePropertiesUserUuid.class) | |||
.add(3657, "Drop column on 'user_id' column of 'PROPERTIES' table", DropUserIdColumnOfPropertiesTable.class) | |||
// Migration of FK in QPROFILE_EDIT_USERS to USERS | |||
.add(3619, "Add 'user_uuid' column on 'QPROFILE_EDIT_USERS' table", AddUserUuidColumnToQProfileEditUsers.class) | |||
.add(3620, "Populate 'user_uuid' for 'QPROFILE_EDIT_USERS'", PopulateQProfileEditUsersUserUuid.class) | |||
.add(3621, "Make 'user_uuid' not-null for 'QPROFILE_EDIT_USERS'", MakeQProfileEditUsersUserUuidColumnNotNullable.class) | |||
.add(3622, "Drop unique index on 'user_id','qprofile_uuid' columns of 'QPROFILE_EDIT_USERS' table", DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.class) | |||
.add(3623, "Add unique index on 'user_uuid','qprofile_uuid' columns of 'QPROFILE_EDIT_USERS' table", AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.class) | |||
.add(3624, "Drop column on 'user_id' column of 'QPROFILE_EDIT_USERS' table", DropUserIdColumnOfQProfileEditUsersTable.class) | |||
.add(3658, "Add 'user_uuid' column on 'QPROFILE_EDIT_USERS' table", AddUserUuidColumnToQProfileEditUsers.class) | |||
.add(3659, "Populate 'user_uuid' for 'QPROFILE_EDIT_USERS'", PopulateQProfileEditUsersUserUuid.class) | |||
.add(3660, "Make 'user_uuid' not-null for 'QPROFILE_EDIT_USERS'", MakeQProfileEditUsersUserUuidColumnNotNullable.class) | |||
.add(3661, "Drop unique index on 'user_id','qprofile_uuid' columns of 'QPROFILE_EDIT_USERS' table", DropUniqueIndexOnUserIdAndQProfileUuidOfQProfileEditUsersTable.class) | |||
.add(3662, "Add unique index on 'user_uuid','qprofile_uuid' columns of 'QPROFILE_EDIT_USERS' table", AddUniqueIndexOnUserUuidAndQProfileUuidOfQProfileEditUsersTable.class) | |||
.add(3663, "Drop column on 'user_id' column of 'QPROFILE_EDIT_USERS' table", DropUserIdColumnOfQProfileEditUsersTable.class) | |||
.add(3664, "Add 'user_uuid' column on 'USER_ROLES' table", AddUserUuidColumnToUserRoles.class) | |||
.add(3665, "Populate 'user_uuid' for 'USER_ROLES'", PopulateUserRolesUserUuid.class) | |||
.add(3666, "Drop unique index on 'user_id' column of 'USER_ROLES' table", DropIndexOnUserIdOfUserRolesTable.class) | |||
.add(3667, "Add unique index on 'user_uuid' columns of 'USER_ROLES' table", AddIndexOnUserUuidOfUserRolesTable.class) | |||
.add(3668, "Drop column on 'user_id' column of 'USER_ROLES' table", DropUserIdColumnOfUserRolesTable.class) | |||
; | |||
} |
@@ -0,0 +1,60 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.Connection; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.DatabaseUtils; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; | |||
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; | |||
public class AddIndexOnUserUuidOfUserRolesTable extends DdlChange { | |||
private static final String TABLE_NAME = "user_roles"; | |||
private static final String INDEX_NAME = "user_roles_user"; | |||
public AddIndexOnUserUuidOfUserRolesTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (!indexExists()) { | |||
context.execute(new CreateIndexBuilder() | |||
.setUnique(false) | |||
.setTable(TABLE_NAME) | |||
.setName(INDEX_NAME) | |||
.addColumn(newVarcharColumnDefBuilder() | |||
.setColumnName("user_uuid") | |||
.setLimit(UUID_SIZE) | |||
.build()) | |||
.build()); | |||
} | |||
} | |||
private boolean indexExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); | |||
} | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.version.v83.users.fk.util.AddUserUuidColumnToTable; | |||
public class AddUserUuidColumnToUserRoles extends AddUserUuidColumnToTable { | |||
public AddUserUuidColumnToUserRoles(Database db) { | |||
super(db, "user_roles"); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.Connection; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.DatabaseUtils; | |||
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class DropIndexOnUserIdOfUserRolesTable extends DdlChange { | |||
private static final String TABLE_NAME = "user_roles"; | |||
private static final String INDEX_NAME = "user_roles_user"; | |||
public DropIndexOnUserIdOfUserRolesTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (indexExists()) { | |||
context.execute(new DropIndexBuilder(getDialect()) | |||
.setTable(TABLE_NAME) | |||
.setName(INDEX_NAME) | |||
.build()); | |||
} | |||
} | |||
private boolean indexExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection); | |||
} | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class DropUserIdColumnOfUserRolesTable extends DdlChange { | |||
public DropUserIdColumnOfUserRolesTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute(new DropColumnsBuilder(getDialect(), "user_roles", "user_id").build()); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
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 PopulateUserRolesUserUuid extends DataChange { | |||
public PopulateUserRolesUserUuid(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select ur.uuid, u.uuid " + | |||
"from user_roles ur " + | |||
"join users u on ur.user_id = u.id where ur.user_uuid is null"); | |||
massUpdate.update("update user_roles set user_uuid = ? where uuid = ?"); | |||
massUpdate.execute((row, update, index) -> { | |||
String userRolesUuid = row.getString(1); | |||
String userUuid = row.getString(2); | |||
update.setString(1, userUuid); | |||
update.setString(2, userRolesUuid); | |||
return true; | |||
}); | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class AddIndexOnUserUuidOfUserRolesTableTest { | |||
private static final String TABLE_NAME = "user_roles"; | |||
private static final String INDEX_NAME = "user_roles_user"; | |||
@Rule | |||
public CoreDbTester dbTester = CoreDbTester.createForSchema(AddIndexOnUserUuidOfUserRolesTableTest.class, "schema.sql"); | |||
DdlChange underTest = new AddIndexOnUserUuidOfUserRolesTable(dbTester.database()); | |||
@Test | |||
public void add_index() throws SQLException { | |||
underTest.execute(); | |||
dbTester.assertIndex(TABLE_NAME, INDEX_NAME, "user_uuid"); | |||
} | |||
@Test | |||
public void migration_is_reentrant() throws SQLException { | |||
underTest.execute(); | |||
dbTester.assertIndex(TABLE_NAME, INDEX_NAME, "user_uuid"); | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import java.sql.Types; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class AddUserUuidColumnToUserRolesTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(AddUserUuidColumnToUserRolesTest.class, "schema.sql"); | |||
private DdlChange underTest = new AddUserUuidColumnToUserRoles(db.database()); | |||
@Before | |||
public void setup() { | |||
insertUserRole(Uuids.createFast(), 1L); | |||
insertUserRole(Uuids.createFast(), 2L); | |||
insertUserRole(Uuids.createFast(), 3L); | |||
} | |||
@Test | |||
public void add_uuid_column() throws SQLException { | |||
underTest.execute(); | |||
db.assertColumnDefinition("user_roles", "user_uuid", Types.VARCHAR, 40, true); | |||
assertThat(db.countSql("select count(*) from user_roles")) | |||
.isEqualTo(3); | |||
} | |||
private void insertUserRole(String uuid, Long userId) { | |||
db.executeInsert("user_roles", | |||
"uuid", uuid, | |||
"organization_uuid", Uuids.createFast(), | |||
"user_id", userId, | |||
"role", Uuids.createFast()); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class DropIndexOnUserIdOfUserRolesTableTest { | |||
private static final String TABLE_NAME = "user_roles"; | |||
private static final String INDEX_NAME = "user_roles_user"; | |||
@Rule | |||
public CoreDbTester dbTester = CoreDbTester.createForSchema(DropIndexOnUserIdOfUserRolesTableTest.class, "schema.sql"); | |||
DdlChange underTest = new DropIndexOnUserIdOfUserRolesTable(dbTester.database()); | |||
@Test | |||
public void add_index() throws SQLException { | |||
underTest.execute(); | |||
dbTester.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); | |||
} | |||
@Test | |||
public void migration_is_reentrant() throws SQLException { | |||
underTest.execute(); | |||
// re-entrant | |||
underTest.execute(); | |||
dbTester.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class DropUserIdColumnOfUserRolesTableTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(DropUserIdColumnOfUserRolesTableTest.class, "schema.sql"); | |||
private DdlChange underTest = new DropUserIdColumnOfUserRolesTable(db.database()); | |||
@Test | |||
public void execute() throws SQLException { | |||
underTest.execute(); | |||
db.assertColumnDoesNotExist("user_roles", "user_id"); | |||
} | |||
@Test | |||
public void migration_is_not_re_entrant() throws SQLException { | |||
underTest.execute(); | |||
assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); | |||
} | |||
} |
@@ -0,0 +1,145 @@ | |||
/* | |||
* 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.users.fk.userroles; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class PopulateUserRolesUserUuidTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(PopulateUserRolesUserUuidTest.class, "schema.sql"); | |||
private DataChange underTest = new PopulateUserRolesUserUuid(db.database()); | |||
@Test | |||
public void populate_uuids() throws SQLException { | |||
long userId_1 = 1L; | |||
String userUuid_1 = "uuid-1"; | |||
insertUser(userId_1, userUuid_1); | |||
long userId_2 = 2L; | |||
String userUuid_2 = "uuid-2"; | |||
insertUser(userId_2, userUuid_2); | |||
long userId_3 = 3L; | |||
String userUuid_3 = "uuid-3"; | |||
insertUser(userId_3, userUuid_3); | |||
long userId_4 = 4L; | |||
String userUuid_4 = "uuid-4"; | |||
insertUser(userId_4, userUuid_4); | |||
String userRoleUuid_1 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_1, userId_1); | |||
String userRoleUuid_2 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_2, userId_2); | |||
String userRoleUuid_3 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_3, userId_3); | |||
String userRoleUuid_4 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_4, userId_4); | |||
String userRoleUuid_5 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_5, userId_1); | |||
underTest.execute(); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_1, userUuid_1); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_2, userUuid_2); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_3, userUuid_3); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_4, userUuid_4); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_5, userUuid_1); | |||
} | |||
@Test | |||
public void migration_is_reentrant() throws SQLException { | |||
long userId_1 = 1L; | |||
String userUuid_1 = "uuid-1"; | |||
insertUser(userId_1, userUuid_1); | |||
long userId_2 = 2L; | |||
String userUuid_2 = "uuid-2"; | |||
insertUser(userId_2, userUuid_2); | |||
long userId_3 = 3L; | |||
String userUuid_3 = "uuid-3"; | |||
insertUser(userId_3, userUuid_3); | |||
long userId_4 = 4L; | |||
String userUuid_4 = "uuid-4"; | |||
insertUser(userId_4, userUuid_4); | |||
String userRoleUuid_1 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_1, userId_1); | |||
String userRoleUuid_2 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_2, userId_2); | |||
String userRoleUuid_3 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_3, userId_3); | |||
underTest.execute(); | |||
String userRoleUuid_4 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_4, userId_4); | |||
String userRoleUuid_5 = Uuids.createFast(); | |||
insertUserRole(userRoleUuid_5, userId_1); | |||
// re-entrant | |||
underTest.execute(); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_1, userUuid_1); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_2, userUuid_2); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_3, userUuid_3); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_4, userUuid_4); | |||
assertThatUserRoleUserUuidIsEqualTo(userRoleUuid_5, userUuid_1); | |||
} | |||
private void assertThatUserRoleUserUuidIsEqualTo(String userRoleUuid, String expectedUuid) { | |||
assertThat(db.select(String.format("select user_uuid from user_roles where uuid = '%s'", userRoleUuid)) | |||
.stream() | |||
.map(row -> row.get("USER_UUID")) | |||
.findFirst()) | |||
.hasValue(expectedUuid); | |||
} | |||
private void insertUserRole(String uuid, Long userId) { | |||
db.executeInsert("user_roles", | |||
"uuid", uuid, | |||
"organization_uuid", Uuids.createFast(), | |||
"user_id", userId, | |||
"role", Uuids.createFast()); | |||
} | |||
private void insertUser(Long id, String uuid) { | |||
db.executeInsert("users", | |||
"id", id, | |||
"uuid", uuid, | |||
"login", "login" + id, | |||
"external_login", "ex-login" + id, | |||
"external_identity_provider", "ex-provider" + id, | |||
"external_id", id + 1, | |||
"is_root", false, | |||
"onboarded", false); | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(40) | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); |
@@ -0,0 +1,10 @@ | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); |
@@ -0,0 +1,11 @@ | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(40) | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); |
@@ -0,0 +1,11 @@ | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(40) | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); |
@@ -0,0 +1,42 @@ | |||
CREATE TABLE "USERS"( | |||
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), | |||
"UUID" VARCHAR(255) NOT NULL, | |||
"LOGIN" VARCHAR(255) NOT NULL, | |||
"ORGANIZATION_UUID" VARCHAR(40), | |||
"NAME" VARCHAR(200), | |||
"EMAIL" VARCHAR(100), | |||
"CRYPTED_PASSWORD" VARCHAR(100), | |||
"SALT" VARCHAR(40), | |||
"HASH_METHOD" VARCHAR(10), | |||
"ACTIVE" BOOLEAN DEFAULT TRUE, | |||
"SCM_ACCOUNTS" VARCHAR(4000), | |||
"EXTERNAL_LOGIN" VARCHAR(255) NOT NULL, | |||
"EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100) NOT NULL, | |||
"EXTERNAL_ID" VARCHAR(255) NOT NULL, | |||
"IS_ROOT" BOOLEAN NOT NULL, | |||
"USER_LOCAL" BOOLEAN, | |||
"ONBOARDED" BOOLEAN NOT NULL, | |||
"HOMEPAGE_TYPE" VARCHAR(40), | |||
"HOMEPAGE_PARAMETER" VARCHAR(40), | |||
"LAST_CONNECTION_DATE" BIGINT, | |||
"CREATED_AT" BIGINT, | |||
"UPDATED_AT" BIGINT | |||
); | |||
ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("ID"); | |||
CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN"); | |||
CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT"); | |||
CREATE UNIQUE INDEX "USERS_UUID" ON "USERS"("UUID"); | |||
CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_ID"); | |||
CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_LOGIN"); | |||
CREATE TABLE "USER_ROLES"( | |||
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL, | |||
"USER_ID" INTEGER, | |||
"ROLE" VARCHAR(64) NOT NULL, | |||
"COMPONENT_UUID" VARCHAR(40), | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(40) | |||
); | |||
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); | |||
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID"); | |||
CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID"); |
@@ -40,7 +40,7 @@ public class NewAuthorizedIndex extends NewIndex<NewAuthorizedIndex> { | |||
this.mainType = IndexType.main(index, TYPE_AUTHORIZATION); | |||
super.createTypeMapping(mainType) | |||
.keywordFieldBuilder(FIELD_GROUP_IDS).build() | |||
.createLongField(FIELD_USER_IDS) | |||
.keywordFieldBuilder(FIELD_USER_IDS).build() | |||
.createBooleanField(FIELD_ALLOW_ANYONE); | |||
} | |||
@@ -43,7 +43,7 @@ public class AuthorizationDoc extends BaseDoc { | |||
if (dto.isAllowAnyone()) { | |||
return res.setAllowAnyone(); | |||
} | |||
return res.setRestricted(dto.getGroupUuids(), dto.getUserIds()); | |||
return res.setRestricted(dto.getGroupUuids(), dto.getUserUuids()); | |||
} | |||
@Override | |||
@@ -73,10 +73,10 @@ public class AuthorizationDoc extends BaseDoc { | |||
return this; | |||
} | |||
private AuthorizationDoc setRestricted(List<String> groupUuids, List<Integer> userIds) { | |||
private AuthorizationDoc setRestricted(List<String> groupUuids, List<String> userUuids) { | |||
setField(FIELD_ALLOW_ANYONE, false); | |||
setField(FIELD_GROUP_IDS, groupUuids); | |||
setField(FIELD_USER_IDS, userIds); | |||
setField(FIELD_USER_IDS, userUuids); | |||
return this; | |||
} | |||
} |
@@ -25,7 +25,7 @@ import java.util.List; | |||
public final class IndexPermissions { | |||
private final String projectUuid; | |||
private final String qualifier; | |||
private final List<Integer> userIds = new ArrayList<>(); | |||
private final List<String> userUuids = new ArrayList<>(); | |||
private final List<String> groupUuids = new ArrayList<>(); | |||
private boolean allowAnyone = false; | |||
@@ -42,12 +42,12 @@ public final class IndexPermissions { | |||
return qualifier; | |||
} | |||
public List<Integer> getUserIds() { | |||
return userIds; | |||
public List<String> getUserUuids() { | |||
return userUuids; | |||
} | |||
public IndexPermissions addUserId(int l) { | |||
userIds.add(l); | |||
public IndexPermissions addUserUuid(String l) { | |||
userUuids.add(l); | |||
return this; | |||
} | |||
@@ -22,21 +22,18 @@ package org.sonar.server.es.newindex; | |||
import com.google.common.collect.ImmutableMap; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.server.es.Index; | |||
import org.sonar.server.es.IndexType; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.assertj.core.api.Assertions.entry; | |||
import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder; | |||
public class NewAuthorizedIndexTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private String someIndexName = randomAlphabetic(10).toLowerCase(Locale.ENGLISH); | |||
private Index someIndex = Index.withRelations(someIndexName); | |||
@@ -47,10 +44,9 @@ public class NewAuthorizedIndexTest { | |||
public void constructor_fails_with_IAE_if_index_does_not_support_relations() { | |||
Index simpleIndex = Index.simple(someIndexName); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Index must accept relations"); | |||
new NewAuthorizedIndex(simpleIndex, defaultSettingsConfiguration); | |||
assertThatThrownBy(() -> new NewAuthorizedIndex(simpleIndex, defaultSettingsConfiguration)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Index must accept relations"); | |||
} | |||
@Test | |||
@@ -64,10 +60,9 @@ public class NewAuthorizedIndexTest { | |||
public void build_fails_if_no_relation_mapping_has_been_created() { | |||
NewAuthorizedIndex underTest = new NewAuthorizedIndex(someIndex, defaultSettingsConfiguration); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("At least one relation mapping must be defined"); | |||
underTest.build(); | |||
assertThatThrownBy(() -> underTest.build()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("At least one relation mapping must be defined"); | |||
} | |||
@Test | |||
@@ -108,7 +103,7 @@ public class NewAuthorizedIndexTest { | |||
assertThat(getFieldAsMap(properties, "auth_groupIds")) | |||
.contains(entry("type", "keyword")); | |||
assertThat(getFieldAsMap(properties, "auth_userIds")) | |||
.containsOnly(entry("type", "long")); | |||
.contains(entry("type", "keyword")); | |||
assertThat(getFieldAsMap(properties, "auth_allowAnyone")) | |||
.containsOnly(entry("type", "boolean")); | |||
} |
@@ -123,15 +123,15 @@ public class AuthorizationDocTest { | |||
@Test | |||
public void fromDto_defines_userIds_and_groupIds_if_allowAnyone_is_false() { | |||
IndexPermissions underTest = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addUserId); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(String::valueOf).forEach(underTest::addUserUuid); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(underTest::addGroupUuid); | |||
AuthorizationDoc doc = AuthorizationDoc.fromDto(IndexType.main(Index.simple("foo"), "bar"), underTest); | |||
boolean auth_allowAnyone = doc.getField("auth_allowAnyone"); | |||
assertThat(auth_allowAnyone).isFalse(); | |||
List<Integer> userIds = doc.getField("auth_userIds"); | |||
assertThat(userIds).isEqualTo(underTest.getUserIds()); | |||
List<String> userUuids = doc.getField("auth_userIds"); | |||
assertThat(userUuids).isEqualTo(underTest.getUserUuids()); | |||
List<String> groupUuids = doc.getField("auth_groupIds"); | |||
assertThat(groupUuids).isEqualTo(underTest.getGroupUuids()); | |||
} | |||
@@ -139,7 +139,7 @@ public class AuthorizationDocTest { | |||
@Test | |||
public void fromDto_ignores_userIds_and_groupUuids_if_allowAnyone_is_true() { | |||
IndexPermissions underTest = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addUserId); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(String::valueOf).forEach(underTest::addUserUuid); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(underTest::addGroupUuid); | |||
underTest.allowAnyone(); | |||
@@ -166,11 +166,11 @@ public class AuthorizationDocTest { | |||
IndexPermissions allowAnyone = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
allowAnyone.allowAnyone(); | |||
IndexPermissions someUserIds = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someUserIds::addUserId); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(String::valueOf).forEach(someUserIds::addUserUuid); | |||
IndexPermissions someGroupUuids = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(someGroupUuids::addGroupUuid); | |||
IndexPermissions someGroupUuidAndUserIs = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someGroupUuidAndUserIs::addUserId); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(String::valueOf).forEach(someGroupUuidAndUserIs::addUserUuid); | |||
IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(someGroupUuidAndUserIs::addGroupUuid); | |||
return new Object[][] { | |||
{allowAnyone}, |
@@ -133,10 +133,9 @@ public class MemberUpdater { | |||
} | |||
private void removeMemberInDb(DbSession dbSession, OrganizationDto organization, UserDto user) { | |||
int userId = user.getId(); | |||
String userUuid = user.getUuid(); | |||
String organizationUuid = organization.getUuid(); | |||
dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId); | |||
dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userUuid); | |||
dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userUuid); | |||
dbClient.qProfileEditUsersDao().deleteByOrganizationAndUser(dbSession, organization, user); | |||
dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userUuid); |
@@ -498,13 +498,13 @@ public class MemberUpdaterTest { | |||
} | |||
private void assertOrgPermissionsOfUser(UserDto user, OrganizationDto organization, OrganizationPermission... permissions) { | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(db.getSession(), user.getId(), organization.getUuid()).stream() | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(db.getSession(), user.getUuid(), organization.getUuid()).stream() | |||
.map(OrganizationPermission::fromKey)) | |||
.containsOnly(permissions); | |||
} | |||
private void assertProjectPermissionsOfUser(UserDto user, ComponentDto project, String... permissions) { | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.uuid())).containsOnly(permissions); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getUuid(), project.uuid())).containsOnly(permissions); | |||
} | |||
private void insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid) { |
@@ -47,7 +47,7 @@ public class PermissionIndexerDao { | |||
private static final String SQL_TEMPLATE = "SELECT " + | |||
" project_authorization.kind as kind, " + | |||
" project_authorization.project as project, " + | |||
" project_authorization.user_id as user_id, " + | |||
" project_authorization.user_uuid as user_uuid, " + | |||
" project_authorization.group_uuid as group_uuid, " + | |||
" project_authorization.qualifier as qualifier " + | |||
"FROM ( " + | |||
@@ -57,7 +57,7 @@ public class PermissionIndexerDao { | |||
" SELECT '" + RowKind.USER + "' as kind," + | |||
" c.uuid AS project, " + | |||
" c.qualifier AS qualifier, " + | |||
" user_roles.user_id AS user_id, " + | |||
" user_roles.user_uuid AS user_uuid, " + | |||
" NULL AS group_uuid " + | |||
" FROM components c " + | |||
" INNER JOIN user_roles ON user_roles.component_uuid = c.uuid AND user_roles.role = 'user' " + | |||
@@ -74,7 +74,7 @@ public class PermissionIndexerDao { | |||
" SELECT '" + RowKind.GROUP + "' as kind," + | |||
" c.uuid AS project, " + | |||
" c.qualifier AS qualifier, " + | |||
" NULL AS user_id, " + | |||
" NULL AS user_uuid, " + | |||
" groups.uuid AS group_uuid " + | |||
" FROM components c " + | |||
" INNER JOIN group_roles ON group_roles.component_uuid = c.uuid AND group_roles.role = 'user' " + | |||
@@ -93,7 +93,7 @@ public class PermissionIndexerDao { | |||
" SELECT '" + RowKind.ANYONE + "' as kind," + | |||
" c.uuid AS project, " + | |||
" c.qualifier AS qualifier, " + | |||
" NULL AS user_id, " + | |||
" NULL AS user_uuid, " + | |||
" NULL AS group_uuid " + | |||
" FROM components c " + | |||
" WHERE " + | |||
@@ -109,7 +109,7 @@ public class PermissionIndexerDao { | |||
" SELECT '" + RowKind.NONE + "' as kind," + | |||
" c.uuid AS project, " + | |||
" c.qualifier AS qualifier, " + | |||
" NULL AS user_id, " + | |||
" NULL AS user_uuid, " + | |||
" NULL AS group_uuid " + | |||
" FROM components c " + | |||
" WHERE " + | |||
@@ -197,7 +197,7 @@ public class PermissionIndexerDao { | |||
case NONE: | |||
break; | |||
case USER: | |||
dto.addUserId(rs.getInt(3)); | |||
dto.addUserUuid(rs.getString(3)); | |||
break; | |||
case GROUP: | |||
dto.addGroupUuid(rs.getString(4)); |
@@ -53,16 +53,14 @@ public class WebAuthorizationTypeSupport { | |||
return QueryBuilders.matchAllQuery(); | |||
} | |||
Integer userId = userSession.getUserId(); | |||
BoolQueryBuilder filter = boolQuery(); | |||
// anyone | |||
filter.should(QueryBuilders.termQuery(FIELD_ALLOW_ANYONE, true)); | |||
// users | |||
Optional.ofNullable(userId) | |||
.map(Integer::longValue) | |||
.ifPresent(id -> filter.should(termQuery(FIELD_USER_IDS, id))); | |||
Optional.ofNullable(userSession.getUuid()) | |||
.ifPresent(uuid -> filter.should(termQuery(FIELD_USER_IDS, uuid))); | |||
// groups | |||
userSession.getGroups() |
@@ -1672,7 +1672,7 @@ public class ProjectMeasuresIndexTest { | |||
private void indexForUser(UserDto user, ProjectMeasuresDoc... docs) { | |||
es.putDocuments(TYPE_PROJECT_MEASURES, docs); | |||
authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addUserId(user.getId())).collect(toList())); | |||
authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addUserUuid(user.getUuid())).collect(toList())); | |||
} | |||
private void indexForGroup(GroupDto group, ProjectMeasuresDoc... docs) { |
@@ -109,13 +109,13 @@ public class PermissionIndexerDaoTest { | |||
IndexPermissions privateProject1Authorization = getByProjectUuid(privateProject1.uuid(), dtos); | |||
assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid()); | |||
assertThat(privateProject1Authorization.isAllowAnyone()).isFalse(); | |||
assertThat(privateProject1Authorization.getUserIds()).containsOnly(user1.getId(), user2.getId()); | |||
assertThat(privateProject1Authorization.getUserUuids()).containsOnly(user1.getUuid(), user2.getUuid()); | |||
assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT); | |||
IndexPermissions privateProject2Authorization = getByProjectUuid(privateProject2.uuid(), dtos); | |||
assertThat(privateProject2Authorization.getGroupUuids()).isEmpty(); | |||
assertThat(privateProject2Authorization.isAllowAnyone()).isFalse(); | |||
assertThat(privateProject2Authorization.getUserIds()).containsOnly(user1.getId()); | |||
assertThat(privateProject2Authorization.getUserUuids()).containsOnly(user1.getUuid()); | |||
assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT); | |||
IndexPermissions view2Authorization = getByProjectUuid(view2.uuid(), dtos); | |||
@@ -144,13 +144,13 @@ public class PermissionIndexerDaoTest { | |||
IndexPermissions privateProject1Authorization = dtos.get(privateProject1.uuid()); | |||
assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid()); | |||
assertThat(privateProject1Authorization.isAllowAnyone()).isFalse(); | |||
assertThat(privateProject1Authorization.getUserIds()).containsOnly(user1.getId(), user2.getId()); | |||
assertThat(privateProject1Authorization.getUserUuids()).containsOnly(user1.getUuid(), user2.getUuid()); | |||
assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT); | |||
IndexPermissions privateProject2Authorization = dtos.get(privateProject2.uuid()); | |||
assertThat(privateProject2Authorization.getGroupUuids()).isEmpty(); | |||
assertThat(privateProject2Authorization.isAllowAnyone()).isFalse(); | |||
assertThat(privateProject2Authorization.getUserIds()).containsOnly(user1.getId()); | |||
assertThat(privateProject2Authorization.getUserUuids()).containsOnly(user1.getUuid()); | |||
assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT); | |||
IndexPermissions view2Authorization = dtos.get(view2.uuid()); | |||
@@ -196,7 +196,7 @@ public class PermissionIndexerDaoTest { | |||
Assertions.assertThat(dtos).hasSize(1); | |||
IndexPermissions dto = dtos.get(0); | |||
assertThat(dto.getGroupUuids()).isEmpty(); | |||
assertThat(dto.getUserIds()).isEmpty(); | |||
assertThat(dto.getUserUuids()).isEmpty(); | |||
assertThat(dto.isAllowAnyone()).isFalse(); | |||
assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); | |||
assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier()); | |||
@@ -209,7 +209,7 @@ public class PermissionIndexerDaoTest { | |||
Assertions.assertThat(dtos).hasSize(1); | |||
IndexPermissions dto = dtos.get(0); | |||
assertThat(dto.getGroupUuids()).isEmpty(); | |||
assertThat(dto.getUserIds()).isEmpty(); | |||
assertThat(dto.getUserUuids()).isEmpty(); | |||
assertThat(dto.isAllowAnyone()).isTrue(); | |||
assertThat(dto.getProjectUuid()).isEqualTo(publicProject.uuid()); | |||
assertThat(dto.getQualifier()).isEqualTo(publicProject.qualifier()); | |||
@@ -223,7 +223,7 @@ public class PermissionIndexerDaoTest { | |||
Assertions.assertThat(dtos).hasSize(1); | |||
IndexPermissions dto = dtos.get(0); | |||
assertThat(dto.getGroupUuids()).isEmpty(); | |||
assertThat(dto.getUserIds()).containsOnly(user1.getId()); | |||
assertThat(dto.getUserUuids()).containsOnly(user1.getUuid()); | |||
assertThat(dto.isAllowAnyone()).isFalse(); | |||
assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); | |||
assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier()); | |||
@@ -238,7 +238,7 @@ public class PermissionIndexerDaoTest { | |||
Assertions.assertThat(dtos).hasSize(1); | |||
IndexPermissions dto = dtos.get(0); | |||
assertThat(dto.getGroupUuids()).containsOnly(group.getUuid()); | |||
assertThat(dto.getUserIds()).isEmpty(); | |||
assertThat(dto.getUserUuids()).isEmpty(); | |||
assertThat(dto.isAllowAnyone()).isFalse(); | |||
assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); | |||
assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier()); | |||
@@ -247,7 +247,7 @@ public class PermissionIndexerDaoTest { | |||
private void isPublic(IndexPermissions view1Authorization, String qualifier) { | |||
assertThat(view1Authorization.getGroupUuids()).isEmpty(); | |||
assertThat(view1Authorization.isAllowAnyone()).isTrue(); | |||
assertThat(view1Authorization.getUserIds()).isEmpty(); | |||
assertThat(view1Authorization.getUserUuids()).isEmpty(); | |||
assertThat(view1Authorization.getQualifier()).isEqualTo(qualifier); | |||
} | |||
@@ -379,7 +379,7 @@ public class PermissionIndexerTest { | |||
} | |||
private UserSessionRule logIn(UserDto u) { | |||
userSession.logIn(u.getLogin()).setUserId(u.getId()); | |||
userSession.logIn(u); | |||
return userSession; | |||
} | |||
@@ -26,6 +26,8 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.GroupTesting; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.db.user.UserTesting; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -54,100 +56,102 @@ public class WebAuthorizationTypeSupportTest { | |||
HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter(); | |||
assertJson(filter.toString()).isSimilarTo("{" + | |||
" \"has_parent\" : {" + | |||
" \"query\" : {" + | |||
" \"bool\" : {" + | |||
" \"filter\" : [{" + | |||
" \"bool\" : {" + | |||
" \"should\" : [{" + | |||
" \"term\" : {" + | |||
" \"auth_allowAnyone\" : {\"value\": true}" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\" : \"auth\"" + | |||
" }" + | |||
"}"); | |||
" \"has_parent\" : {" + | |||
" \"query\" : {" + | |||
" \"bool\" : {" + | |||
" \"filter\" : [{" + | |||
" \"bool\" : {" + | |||
" \"should\" : [{" + | |||
" \"term\" : {" + | |||
" \"auth_allowAnyone\" : {\"value\": true}" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\" : \"auth\"" + | |||
" }" + | |||
"}"); | |||
} | |||
@Test | |||
public void createQueryFilter_sets_filter_on_anyone_and_user_id_if_user_is_logged_in_but_has_no_groups() { | |||
userSession.logIn().setUserId(1234); | |||
UserDto userDto = UserTesting.newUserDto(); | |||
userSession.logIn(userDto); | |||
HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter(); | |||
assertJson(filter.toString()).isSimilarTo("{" + | |||
" \"has_parent\": {" + | |||
" \"query\": {" + | |||
" \"bool\": {" + | |||
" \"filter\": [{" + | |||
" \"bool\": {" + | |||
" \"should\": [" + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_allowAnyone\": {\"value\": true}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_userIds\": {\"value\": 1234}" + | |||
" }" + | |||
" }" + | |||
" ]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\": \"auth\"" + | |||
" }" + | |||
"}"); | |||
" \"has_parent\": {" + | |||
" \"query\": {" + | |||
" \"bool\": {" + | |||
" \"filter\": [{" + | |||
" \"bool\": {" + | |||
" \"should\": [" + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_allowAnyone\": {\"value\": true}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_userIds\": {\"value\": \"" + userDto.getUuid() + "\"}" + | |||
" }" + | |||
" }" + | |||
" ]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\": \"auth\"" + | |||
" }" + | |||
"}"); | |||
} | |||
@Test | |||
public void createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups() { | |||
GroupDto group1 = GroupTesting.newGroupDto().setUuid("10"); | |||
GroupDto group2 = GroupTesting.newGroupDto().setUuid("11"); | |||
userSession.logIn().setUserId(1234).setGroups(group1, group2); | |||
UserDto userDto = UserTesting.newUserDto(); | |||
userSession.logIn(userDto).setGroups(group1, group2); | |||
HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter(); | |||
assertJson(filter.toString()).isSimilarTo("{" + | |||
" \"has_parent\": {" + | |||
" \"query\": {" + | |||
" \"bool\": {" + | |||
" \"filter\": [{" + | |||
" \"bool\": {" + | |||
" \"should\": [" + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_allowAnyone\": {\"value\": true}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_userIds\": {\"value\": 1234}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_groupIds\": {\"value\": \"10\"}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_groupIds\": {\"value\": \"11\"}" + | |||
" }" + | |||
" }" + | |||
" ]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\": \"auth\"" + | |||
" }" + | |||
"}"); | |||
" \"has_parent\": {" + | |||
" \"query\": {" + | |||
" \"bool\": {" + | |||
" \"filter\": [{" + | |||
" \"bool\": {" + | |||
" \"should\": [" + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_allowAnyone\": {\"value\": true}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_userIds\": {\"value\": \"" + userDto.getUuid() + "\"}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_groupIds\": {\"value\": \"10\"}" + | |||
" }" + | |||
" }," + | |||
" {" + | |||
" \"term\": {" + | |||
" \"auth_groupIds\": {\"value\": \"11\"}" + | |||
" }" + | |||
" }" + | |||
" ]" + | |||
" }" + | |||
" }]" + | |||
" }" + | |||
" }," + | |||
" \"parent_type\": \"auth\"" + | |||
" }" + | |||
"}"); | |||
} | |||
} |
@@ -44,7 +44,7 @@ public class PermissionIndexerTester { | |||
public PermissionIndexerTester allowOnlyUser(ComponentDto project, UserDto user) { | |||
IndexPermissions dto = new IndexPermissions(project.uuid(), project.qualifier()) | |||
.addUserId(user.getId()); | |||
.addUserUuid(user.getUuid()); | |||
return allow(dto); | |||
} | |||
@@ -132,8 +132,8 @@ public class PermissionTemplateService { | |||
List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getUuid()); | |||
String organizationUuid = template.getOrganizationUuid(); | |||
Map<String, Integer> userDtoMap = dbClient.userDao().selectByUuids(dbSession, usersPermissions.stream().map(PermissionTemplateUserDto::getUserUuid).collect(Collectors.toSet())) | |||
.stream().collect(Collectors.toMap(UserDto::getUuid, UserDto::getId)); | |||
Map<String, String> userDtoMap = dbClient.userDao().selectByUuids(dbSession, usersPermissions.stream().map(PermissionTemplateUserDto::getUserUuid).collect(Collectors.toSet())) | |||
.stream().collect(Collectors.toMap(UserDto::getUuid, UserDto::getUuid)); | |||
usersPermissions | |||
.stream() | |||
.filter(up -> permissionValidForProject(project, up.getPermission())) | |||
@@ -170,7 +170,7 @@ public class PermissionTemplateService { | |||
.filter(up -> permissionValidForProject(project, up.getPermission())) | |||
.filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())) | |||
.forEach(c -> { | |||
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), organizationUuid, c.getPermission(), userDto.getId(), project.uuid()); | |||
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), organizationUuid, c.getPermission(), userDto.getUuid(), project.uuid()); | |||
dbClient.userPermissionDao().insert(dbSession, dto); | |||
}); | |||
} |
@@ -93,7 +93,8 @@ public class UserPermissionChanger { | |||
if (loadExistingPermissions(dbSession, change).contains(change.getPermission())) { | |||
return false; | |||
} | |||
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getProjectUuid()); | |||
UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), change.getOrganizationUuid(), change.getPermission(), change.getUserId().getUuid(), | |||
change.getProjectUuid()); | |||
dbClient.userPermissionDao().insert(dbSession, dto); | |||
return true; | |||
} | |||
@@ -105,9 +106,9 @@ public class UserPermissionChanger { | |||
checkOtherAdminsExist(dbSession, change); | |||
String projectUuid = change.getProjectUuid(); | |||
if (projectUuid != null) { | |||
dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getId(), change.getPermission(), projectUuid); | |||
dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getUuid(), change.getPermission(), projectUuid); | |||
} else { | |||
dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getId(), change.getPermission(), change.getOrganizationUuid()); | |||
dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getUuid(), change.getPermission(), change.getOrganizationUuid()); | |||
} | |||
return true; | |||
} | |||
@@ -115,10 +116,10 @@ public class UserPermissionChanger { | |||
private List<String> loadExistingPermissions(DbSession dbSession, UserPermissionChange change) { | |||
String projectUuid = change.getProjectUuid(); | |||
if (projectUuid != null) { | |||
return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, change.getUserId().getId(), projectUuid); | |||
return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, change.getUserId().getUuid(), projectUuid); | |||
} | |||
return dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, | |||
change.getUserId().getId(), | |||
change.getUserId().getUuid(), | |||
change.getOrganizationUuid()); | |||
} | |||
@@ -145,14 +145,14 @@ public class UsersAction implements PermissionsWsAction { | |||
} | |||
private UsersWsResponse buildResponse(List<UserDto> users, List<UserPermissionDto> userPermissions, Paging paging) { | |||
Multimap<Integer, String> permissionsByUserId = TreeMultimap.create(); | |||
userPermissions.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission())); | |||
Multimap<String, String> permissionsByUserUuid = TreeMultimap.create(); | |||
userPermissions.forEach(userPermission -> permissionsByUserUuid.put(userPermission.getUserUuid(), userPermission.getPermission())); | |||
UsersWsResponse.Builder response = UsersWsResponse.newBuilder(); | |||
users.forEach(user -> { | |||
Permissions.User.Builder userResponse = response.addUsersBuilder() | |||
.setLogin(user.getLogin()) | |||
.addAllPermissions(permissionsByUserId.get(user.getId())); | |||
.addAllPermissions(permissionsByUserUuid.get(user.getUuid())); | |||
ofNullable(user.getEmail()).ifPresent(userResponse::setEmail); | |||
ofNullable(emptyToNull(user.getEmail())).ifPresent(u -> userResponse.setAvatar(avatarResolver.create(user))); | |||
ofNullable(user.getName()).ifPresent(userResponse::setName); |
@@ -146,13 +146,13 @@ public class UpdateVisibilityAction implements ProjectsWsAction { | |||
PUBLIC_PERMISSIONS.forEach(permission -> { | |||
dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) | |||
.forEach(group -> insertProjectPermissionOnGroup(dbSession, component, permission, group)); | |||
dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) | |||
.forEach(userId -> insertProjectPermissionOnUser(dbSession, component, permission, userId)); | |||
dbClient.userPermissionDao().selectUserUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) | |||
.forEach(userUuid -> insertProjectPermissionOnUser(dbSession, component, permission, userUuid)); | |||
}); | |||
} | |||
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, Integer userId) { | |||
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), component.getOrganizationUuid(), permission, userId, component.uuid())); | |||
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, String userUuid) { | |||
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), component.getOrganizationUuid(), permission, userUuid, component.uuid())); | |||
} | |||
private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, String groupUuid) { |
@@ -97,13 +97,12 @@ public class DeactivateAction implements UsersWsAction { | |||
ensureNotLastAdministrator(dbSession, user); | |||
Integer userId = user.getId(); | |||
String userUuid = user.getUuid(); | |||
dbClient.userTokenDao().deleteByUser(dbSession, user); | |||
dbClient.propertiesDao().deleteByKeyAndValue(dbSession, DEFAULT_ISSUE_ASSIGNEE, user.getLogin()); | |||
dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserUuid(userUuid).build()); | |||
dbClient.userGroupDao().deleteByUserUuid(dbSession, userUuid); | |||
dbClient.userPermissionDao().deleteByUserId(dbSession, userId); | |||
dbClient.userPermissionDao().deleteByUserUuid(dbSession, userUuid); | |||
dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid); | |||
dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user); | |||
dbClient.organizationMemberDao().deleteByUserUuid(dbSession, userUuid); |
@@ -442,7 +442,7 @@ public class PermissionTemplateServiceTest { | |||
private List<String> selectProjectPermissionsOfUser(UserDto userDto, ComponentDto project) { | |||
return dbTester.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(session, | |||
userDto.getId(), project.uuid()); | |||
userDto.getUuid(), project.uuid()); | |||
} | |||
@Test |
@@ -471,11 +471,11 @@ public class UpdateVisibilityActionTest { | |||
.setParam(PARAM_VISIBILITY, PRIVATE) | |||
.execute(); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getId(), project.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2"); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getId(), project.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2"); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getId(), project.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getUuid(), project.uuid())) | |||
.isEmpty(); | |||
} | |||
@@ -520,7 +520,7 @@ public class UpdateVisibilityActionTest { | |||
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isTrue(); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); | |||
} | |||
@@ -545,7 +545,7 @@ public class UpdateVisibilityActionTest { | |||
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.ISSUE_ADMIN); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.ADMIN); | |||
} | |||
@@ -566,7 +566,7 @@ public class UpdateVisibilityActionTest { | |||
assertThat(dbClient.componentDao().selectByUuid(dbSession, application.uuid()).get().isPrivate()).isTrue(); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), application.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), application.uuid())) | |||
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); | |||
} | |||
@@ -591,7 +591,7 @@ public class UpdateVisibilityActionTest { | |||
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.ISSUE_ADMIN); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), portfolio.uuid())) | |||
.containsOnly(UserRole.ADMIN); | |||
} | |||
@@ -678,7 +678,7 @@ public class UpdateVisibilityActionTest { | |||
} | |||
private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) { | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), component.getOrganizationUuid(), permission, user.getId(), component.uuid()); | |||
UserPermissionDto dto = new UserPermissionDto(Uuids.create(), component.getOrganizationUuid(), permission, user.getUuid(), component.uuid()); | |||
dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto); | |||
dbTester.commit(); | |||
} | |||
@@ -688,13 +688,13 @@ public class UpdateVisibilityActionTest { | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getUuid(), component.getOrganizationUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) | |||
.isEmpty(); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid(), component.uuid())) | |||
.containsAll(permissionService.getAllProjectPermissions()); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), component.uuid())) | |||
.containsAll(permissionService.getAllProjectPermissions()); | |||
} | |||
@@ -703,7 +703,7 @@ public class UpdateVisibilityActionTest { | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getUuid(), component.getOrganizationUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) | |||
.doesNotContain(UserRole.USER) | |||
@@ -713,7 +713,7 @@ public class UpdateVisibilityActionTest { | |||
.doesNotContain(UserRole.USER) | |||
.doesNotContain(UserRole.CODEVIEWER) | |||
.containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), component.uuid())) | |||
.doesNotContain(UserRole.USER) | |||
.doesNotContain(UserRole.CODEVIEWER) | |||
.containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); | |||
@@ -724,13 +724,13 @@ public class UpdateVisibilityActionTest { | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) | |||
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getUuid(), component.getOrganizationUuid())) | |||
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) | |||
.containsAll(permissionService.getAllProjectPermissions()); | |||
assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid(), component.uuid())) | |||
.containsAll(permissionService.getAllProjectPermissions()); | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) | |||
assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), component.uuid())) | |||
.containsAll(permissionService.getAllProjectPermissions()); | |||
} | |||
@@ -163,8 +163,8 @@ public class DeactivateActionTest { | |||
deactivate(user.getLogin()); | |||
assertThat(db.getDbClient().userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), db.getDefaultOrganization().getUuid())).isEmpty(); | |||
assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).isEmpty(); | |||
assertThat(db.getDbClient().userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getUuid(), db.getDefaultOrganization().getUuid())).isEmpty(); | |||
assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getUuid(), project.uuid())).isEmpty(); | |||
} | |||
@Test |