import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
public void search_for_users_with_response_example() {
UserDto user1 = insertUser(new UserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
UserDto user2 = insertUser(new UserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user2.getId()));
dbSession.commit();
String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, "project-uuid");
UserDto user = insertUser(newUserDto().setLogin("project-user-login").setName("project-user-name"));
- insertUserRole(new UserRoleDto().setRole(ISSUE_ADMIN).setUserId(user.getId()).setResourceId(project.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(ISSUE_ADMIN).setUserId(user.getId()).setComponentId(project.getId()));
dbSession.commit();
userSession.login().addProjectUuidPermissions(SYSTEM_ADMIN, "project-uuid");
return user;
}
- private void insertUserRole(UserRoleDto userRoleDto) {
- dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
+ private void insertUserRole(UserPermissionDto userPermissionDto) {
+ dbClient.roleDao().insertUserRole(dbSession, userPermissionDto);
dbSession.commit();
}
UserDto user1 = insertUser(new UserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
UserDto user2 = insertUser(new UserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(new UserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
- insertUserRole(new UserRoleDto().setRole(SYSTEM_ADMIN).setUserId(user3.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user2.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SYSTEM_ADMIN).setUserId(user3.getId()));
dbSession.commit();
}
}
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.i18n.I18nRule;
return db.getDbClient().userDao().insert(db.getSession(), user);
}
- private void insertUserRole(UserRoleDto userRole) {
+ private void insertUserRole(UserPermissionDto userRole) {
db.getDbClient().roleDao().insertUserRole(db.getSession(), userRole);
}
return groupRole;
}
- private static UserRoleDto newUserRoleDto(String role, long userId) {
- return new UserRoleDto()
- .setRole(role)
+ private static UserPermissionDto newUserRoleDto(String role, long userId) {
+ return new UserPermissionDto()
+ .setPermission(role)
.setUserId(userId);
}
}
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
}
private void insertUserRole(String permission, long userId, @Nullable Long resourceId) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(resourceId));
+ .setComponentId(resourceId));
}
private GroupDto insertGroup(GroupDto group) {
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
public void search_for_users_with_response_example() {
UserDto user1 = insertUser(new UserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
UserDto user2 = insertUser(new UserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user2.getId()));
dbSession.commit();
String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, "project-uuid");
UserDto user = insertUser(newUserDto().setLogin("project-user-login").setName("project-user-name"));
- insertUserRole(new UserRoleDto().setRole(ISSUE_ADMIN).setUserId(user.getId()).setResourceId(project.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(ISSUE_ADMIN).setUserId(user.getId()).setComponentId(project.getId()));
dbSession.commit();
userSession.login().addProjectUuidPermissions(SYSTEM_ADMIN, "project-uuid");
return user;
}
- private void insertUserRole(UserRoleDto userRoleDto) {
- dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
+ private void insertUserRole(UserPermissionDto userPermissionDto) {
+ dbClient.roleDao().insertUserRole(dbSession, userPermissionDto);
dbSession.commit();
}
UserDto user1 = insertUser(new UserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
UserDto user2 = insertUser(new UserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(new UserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
- insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
- insertUserRole(new UserRoleDto().setRole(SYSTEM_ADMIN).setUserId(user3.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SCAN_EXECUTION).setUserId(user2.getId()));
+ insertUserRole(new UserPermissionDto().setPermission(SYSTEM_ADMIN).setUserId(user3.getId()));
dbSession.commit();
}
}
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
}
private void addUserPermissionToProject(UserDto user, ComponentDto project, String permission) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(user.getId())
- .setResourceId(project.getId()));
+ .setComponentId(project.getId()));
}
private void addGroupPermissionToProject(GroupDto group, ComponentDto project, String permission) {
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDbTester;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
}
private void addUserPermissionToProject(UserDto user, ComponentDto project, String permission) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(user.getId())
- .setResourceId(project.getId()));
+ .setComponentId(project.getId()));
}
private void addGroupPermissionToProject(GroupDto group, ComponentDto project, String permission) {
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDbTester;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.tester.UserSessionRule;
}
private void insertUserPermission(String permission, long userId, long componentId) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(componentId));
+ .setComponentId(componentId));
db.commit();
}
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualitygate.QgateProjectFinder.Association;
import org.sonar.server.tester.UserSessionRule;
componentDbTester.insertComponent(newProjectDto());
// User can only see project 1
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto().setUserId(userDto.getId()).setResourceId(project1.getId()).setRole(UserRole.USER));
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto().setUserId(userDto.getId()).setComponentId(project1.getId()).setPermission(UserRole.USER));
dbTester.commit();
Association result = underTest.find(
import org.sonar.db.user.RoleDao;
import org.sonar.db.user.UserDao;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.tester.UserSessionRule;
dbClient.componentDao().insert(session, project1, project2);
// user only sees project1
- roleDao.insertUserRole(session, new UserRoleDto().setUserId(userId).setResourceId(project1.getId()).setRole(UserRole.USER));
+ roleDao.insertUserRole(session, new UserPermissionDto().setUserId(userId).setComponentId(project1.getId()).setPermission(UserRole.USER));
associateProjectsWithProfile(session, xooP1, project1, project2);
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.user.GroupRoleDto;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.server.exceptions.ForbiddenException;
public class ServerUserSessionTest {
private void addPermissions( @Nullable ComponentDto component, String... permissions) {
for (String permission : permissions) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
- .setResourceId(component == null ? null : component.getId())
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
+ .setComponentId(component == null ? null : component.getId())
.setUserId(userDto.getId()));
}
dbSession.commit();
import org.sonar.db.user.UserGroupDto;
import org.sonar.db.user.UserGroupMapper;
import org.sonar.db.user.UserMapper;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import org.sonar.db.user.UserTokenCount;
import org.sonar.db.user.UserTokenDto;
import org.sonar.db.user.UserTokenMapper;
confBuilder.loadAlias("Snapshot", SnapshotDto.class);
confBuilder.loadAlias("SchemaMigration", SchemaMigrationDto.class);
confBuilder.loadAlias("User", UserDto.class);
- confBuilder.loadAlias("UserRole", UserRoleDto.class);
+ confBuilder.loadAlias("UserRole", UserPermissionDto.class);
confBuilder.loadAlias("UserGroup", UserGroupDto.class);
confBuilder.loadAlias("Widget", WidgetDto.class);
confBuilder.loadAlias("WidgetProperty", WidgetPropertyDto.class);
import org.sonar.db.permission.template.PermissionTemplateUserDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupRoleDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
/**
* This facade wraps db operations related to permissions
* @param updateProjectAuthorizationDate is false when doing bulk action in order to not update the same project multiple times for nothing
*/
private void insertUserPermission(@Nullable Long resourceId, Long userId, String permission, boolean updateProjectAuthorizationDate, DbSession session) {
- UserRoleDto userRoleDto = new UserRoleDto()
- .setRole(permission)
+ UserPermissionDto userPermissionDto = new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(resourceId);
+ .setComponentId(resourceId);
if (updateProjectAuthorizationDate) {
updateProjectAuthorizationDate(session, resourceId);
}
- dbClient.roleDao().insertUserRole(session, userRoleDto);
+ dbClient.roleDao().insertUserRole(session, userPermissionDto);
}
public void insertUserPermission(@Nullable Long resourceId, Long userId, String permission, DbSession session) {
}
public void deleteUserPermission(@Nullable Long resourceId, Long userId, String permission, DbSession session) {
- UserRoleDto userRoleDto = new UserRoleDto()
- .setRole(permission)
+ UserPermissionDto userPermissionDto = new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(resourceId);
+ .setComponentId(resourceId);
updateProjectAuthorizationDate(session, resourceId);
- dbClient.roleDao().deleteUserRole(userRoleDto, session);
+ dbClient.roleDao().deleteUserRole(userPermissionDto, session);
}
/**
mapper(session).insertGroupRole(groupRole);
}
- public void insertUserRole(DbSession session, UserRoleDto userRole) {
+ public void insertUserRole(DbSession session, UserPermissionDto userRole) {
mapper(session).insertUserRole(userRole);
}
- public void deleteUserRole(UserRoleDto userRole, SqlSession session) {
+ public void deleteUserRole(UserPermissionDto userRole, SqlSession session) {
mapper(session).deleteUserRole(userRole);
}
void insertGroupRole(GroupRoleDto groupRole);
- void insertUserRole(UserRoleDto userRole);
+ void insertUserRole(UserPermissionDto userRole);
- void deleteUserRole(UserRoleDto userRole);
+ void deleteUserRole(UserPermissionDto userRole);
void deleteGroupRole(GroupRoleDto groupRole);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.user;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class UserPermissionDto {
+ private Long userId;
+ private Long componentId;
+ private String permission;
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public UserPermissionDto setUserId(Long userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ @CheckForNull
+ public Long getComponentId() {
+ return componentId;
+ }
+
+ public UserPermissionDto setComponentId(@Nullable Long componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public UserPermissionDto setPermission(String permission) {
+ this.permission = permission;
+ return this;
+ }
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.user;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-/**
- * @since 3.2
- */
-public class UserRoleDto {
- private Long id;
- private Long userId;
- private Long resourceId;
- private String role;
-
- public Long getId() {
- return id;
- }
-
- public UserRoleDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public Long getUserId() {
- return userId;
- }
-
- public UserRoleDto setUserId(Long userId) {
- this.userId = userId;
- return this;
- }
-
- @CheckForNull
- public Long getResourceId() {
- return resourceId;
- }
-
- public UserRoleDto setResourceId(@Nullable Long resourceId) {
- this.resourceId = resourceId;
- return this;
- }
-
- public String getRole() {
- return role;
- }
-
- public UserRoleDto setRole(String role) {
- this.role = role;
- return this;
- }
-}
<insert id="insertUserRole" parameterType="UserRole" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_roles (user_id, resource_id, role)
- VALUES (#{userId}, #{resourceId}, #{role})
+ VALUES (#{userId}, #{componentId}, #{permission})
</insert>
<delete id="deleteGroupRole" parameterType="map">
<delete id="deleteUserRole" parameterType="map">
DELETE FROM user_roles
WHERE user_id=#{userId}
- AND role=#{role}
+ AND role=#{permission}
AND
<choose>
- <when test="resourceId != null">
- resource_id=#{resourceId}
+ <when test="componentId != null">
+ resource_id=#{componentId}
</when>
<otherwise>
resource_id IS NULL
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
public class PermissionDbTester {
private final DbTester db;
}
public void addProjectPermissionToUser(String permission, long userId, long componentId) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(componentId));
+ .setComponentId(componentId));
db.commit();
}
public void addGlobalPermissionToUser(String permission, long userId) {
- dbClient.roleDao().insertUserRole(dbSession, new UserRoleDto()
- .setRole(permission)
+ dbClient.roleDao().insertUserRole(dbSession, new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId));
db.commit();
}
import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.UserDbTester;
import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserRoleDto;
+import org.sonar.db.user.UserPermissionDto;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
}
private void addPermissionToUser(String permission, long userId, long resourceId) {
- dbTester.getDbClient().roleDao().insertUserRole(dbTester.getSession(), new UserRoleDto()
- .setRole(permission)
+ dbTester.getDbClient().roleDao().insertUserRole(dbTester.getSession(), new UserPermissionDto()
+ .setPermission(permission)
.setUserId(userId)
- .setResourceId(resourceId));
+ .setComponentId(resourceId));
dbTester.commit();
}
@Test
public void select_user_permissions_by_permission_and_user_id() {
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(UserRole.ADMIN).setUserId(1L).setResourceId(2L));
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(UserRole.ADMIN).setUserId(1L).setResourceId(3L));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(UserRole.ADMIN).setUserId(1L).setComponentId(2L));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(UserRole.ADMIN).setUserId(1L).setComponentId(3L));
// global permission - not returned
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(UserRole.ADMIN).setUserId(1L).setResourceId(null));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(UserRole.ADMIN).setUserId(1L).setComponentId(null));
// project permission on another user id - not returned
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(UserRole.ADMIN).setUserId(42L).setResourceId(2L));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(UserRole.ADMIN).setUserId(42L).setComponentId(2L));
// project permission on another permission - not returned
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(GlobalPermissions.SCAN_EXECUTION).setUserId(1L).setResourceId(2L));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(GlobalPermissions.SCAN_EXECUTION).setUserId(1L).setComponentId(2L));
db.commit();
List<Long> result = underTest.selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, 1L);
underTest.insertGroupRole(dbSession, new GroupRoleDto().setRole(UserRole.USER).setGroupId(5L).setResourceId(5L));
groupDb.addUserToGroup(userId, 5L);
// duplicates on resource id - should be returned once
- underTest.insertUserRole(dbSession, new UserRoleDto().setRole(UserRole.ADMIN).setUserId(userId).setResourceId(2L));
+ underTest.insertUserRole(dbSession, new UserPermissionDto().setPermission(UserRole.ADMIN).setUserId(userId).setComponentId(2L));
underTest.insertGroupRole(dbSession, new GroupRoleDto().setRole(UserRole.ADMIN).setGroupId(3L).setResourceId(3L));
db.commit();
public void delete_global_user_permission() {
db.prepareDbUnit(getClass(), "globalUserPermissions.xml");
- UserRoleDto userRoleToDelete = new UserRoleDto().setUserId(200L).setRole(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ UserPermissionDto userRoleToDelete = new UserPermissionDto().setUserId(200L).setPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
underTest.deleteUserRole(userRoleToDelete, db.getSession());
db.getSession().commit();
public void delete_resource_user_permission() {
db.prepareDbUnit(getClass(), "resourceUserPermissions.xml");
- UserRoleDto userRoleToDelete = new UserRoleDto().setUserId(200L).setRole(UserRole.USER).setResourceId(1L);
+ UserPermissionDto userRoleToDelete = new UserPermissionDto().setUserId(200L).setPermission(UserRole.USER).setComponentId(1L);
underTest.deleteUserRole(userRoleToDelete, db.getSession());
db.getSession().commit();
public void count_users_with_one_specific_permission() {
DbClient dbClient = db.getDbClient();
UserDto user = dbClient.userDao().insert(db.getSession(), new UserDto().setActive(true));
- dbClient.roleDao().insertUserRole(db.getSession(), new UserRoleDto()
+ dbClient.roleDao().insertUserRole(db.getSession(), new UserPermissionDto()
.setUserId(user.getId())
- .setResourceId(123L)
- .setRole(GlobalPermissions.SYSTEM_ADMIN));
- dbClient.roleDao().insertUserRole(db.getSession(), new UserRoleDto()
+ .setComponentId(123L)
+ .setPermission(GlobalPermissions.SYSTEM_ADMIN));
+ dbClient.roleDao().insertUserRole(db.getSession(), new UserPermissionDto()
.setUserId(user.getId())
- .setRole(GlobalPermissions.SYSTEM_ADMIN));
- dbClient.roleDao().insertUserRole(db.getSession(), new UserRoleDto()
+ .setPermission(GlobalPermissions.SYSTEM_ADMIN));
+ dbClient.roleDao().insertUserRole(db.getSession(), new UserPermissionDto()
.setUserId(user.getId())
- .setRole(GlobalPermissions.SCAN_EXECUTION));
+ .setPermission(GlobalPermissions.SCAN_EXECUTION));
int result = underTest.countUserPermissions(db.getSession(), GlobalPermissions.SYSTEM_ADMIN, null);
dbClient.roleDao().insertGroupRole(db.getSession(), new GroupRoleDto()
.setGroupId(group.getId())
.setRole(GlobalPermissions.SYSTEM_ADMIN));
- dbClient.roleDao().insertUserRole(db.getSession(), new UserRoleDto()
+ dbClient.roleDao().insertUserRole(db.getSession(), new UserPermissionDto()
.setUserId(user.getId())
- .setRole(GlobalPermissions.SYSTEM_ADMIN));
+ .setPermission(GlobalPermissions.SYSTEM_ADMIN));
int result = underTest.countUserPermissions(db.getSession(), GlobalPermissions.SYSTEM_ADMIN, null);
RoleMapper mapper = dbTester.getSession().getMapper(RoleMapper.class);
mapper.insertGroupRole(new GroupRoleDto().setRole("admin").setGroupId(100L).setResourceId(123L));
mapper.insertGroupRole(new GroupRoleDto().setRole("user").setResourceId(123L));// Anyone
- mapper.insertUserRole(new UserRoleDto().setRole("codeviewer").setUserId(200L).setResourceId(123L));// Anyone
+ mapper.insertUserRole(new UserPermissionDto().setPermission("codeviewer").setUserId(200L).setComponentId(123L));// Anyone
dbTester.getSession().commit();
dbTester.assertDbUnit(getClass(), "insertRoles-result.xml", "group_roles", "user_roles");
return dto;
}
- private UserRoleDto insertUserRole(UserDto user) {
- UserRoleDto dto = new UserRoleDto().setUserId(user.getId()).setRole(randomAlphanumeric(64));
+ private UserPermissionDto insertUserRole(UserDto user) {
+ UserPermissionDto dto = new UserPermissionDto().setUserId(user.getId()).setPermission(randomAlphanumeric(64));
dbClient.roleDao().insertUserRole(session, dto);
return dto;
}