]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor UserPermissionDto
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 5 Jul 2016 13:33:17 +0000 (15:33 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 12 Jul 2016 08:16:53 +0000 (10:16 +0200)
22 files changed:
server/sonar-server/src/test/java/org/sonar/server/permission/ws/OldUsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
sonar-db/src/main/java/org/sonar/db/MyBatis.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
sonar-db/src/main/java/org/sonar/db/user/RoleDao.java
sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java
sonar-db/src/main/java/org/sonar/db/user/UserPermissionDto.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/user/UserRoleDto.java [deleted file]
sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml
sonar-db/src/test/java/org/sonar/db/permission/PermissionDbTester.java
sonar-db/src/test/java/org/sonar/db/permission/UserWithPermissionDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleMapperTest.java
sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java

index 25059e6fdfc2ed69cc763e08af8fcc6f86b8d027..e31df437d104cd7ee085710b90cf2b031c768dea 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.DbTester;
 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;
@@ -85,8 +85,8 @@ public class OldUsersActionTest {
   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();
@@ -107,7 +107,7 @@ public class OldUsersActionTest {
     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");
 
@@ -201,8 +201,8 @@ public class OldUsersActionTest {
     return user;
   }
 
-  private void insertUserRole(UserRoleDto userRoleDto) {
-    dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
+  private void insertUserRole(UserPermissionDto userPermissionDto) {
+    dbClient.roleDao().insertUserRole(dbSession, userPermissionDto);
     dbSession.commit();
   }
 
@@ -210,9 +210,9 @@ public class OldUsersActionTest {
     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();
   }
 }
index 9040870156ed4e3ca5a644c746c67a3501561cd8..230766114fc082f3c1941cbbcc12b51b7f5abefd 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.db.DbTester;
 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;
@@ -140,7 +140,7 @@ public class SearchGlobalPermissionsActionTest {
     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);
   }
 
@@ -169,9 +169,9 @@ public class SearchGlobalPermissionsActionTest {
     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);
   }
 }
index d2b05d5525d1ae039462aa1061d4c8287b79c17f..66d8b8b02d3d4a79d7da70dc8611dec780445d95 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.component.ResourceTypesRule;
 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;
@@ -324,10 +324,10 @@ public class SearchProjectPermissionsActionTest {
   }
 
   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) {
index 532946d022765c014f456a161c6e5e52a611a4c2..64856ffb8be79ea4bdb0ba492ef3f7da4ba62185 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.DbTester;
 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;
@@ -85,8 +85,8 @@ public class UsersActionTest {
   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();
@@ -107,7 +107,7 @@ public class UsersActionTest {
     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");
 
@@ -201,8 +201,8 @@ public class UsersActionTest {
     return user;
   }
 
-  private void insertUserRole(UserRoleDto userRoleDto) {
-    dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
+  private void insertUserRole(UserPermissionDto userPermissionDto) {
+    dbClient.roleDao().insertUserRole(dbSession, userPermissionDto);
     dbSession.commit();
   }
 
@@ -210,9 +210,9 @@ public class UsersActionTest {
     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();
   }
 }
index 5017a9b621dd1c10dc71275209b81970bf139c1e..9b13fd4486e3412fcd6da9365e01f7bc81f91df2 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.db.permission.UserWithPermissionDto;
 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;
@@ -274,10 +274,10 @@ public class ApplyTemplateActionTest {
   }
 
   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) {
index 7a52c5b02755bc9656ff9955bfe98cc2893ee3cf..e430cf624f2dddf3ee77a202e4d466ebdf154175 100644 (file)
@@ -63,7 +63,7 @@ import org.sonar.db.user.GroupDto;
 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;
@@ -245,10 +245,10 @@ public class BulkApplyTemplateActionTest {
   }
 
   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) {
index a57147b7ba794bc0f27271eb635ba01963e49633..763f66217141a4c75f769918b0596226128c46fd 100644 (file)
@@ -46,7 +46,7 @@ import org.sonar.db.user.GroupDto;
 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;
@@ -324,10 +324,10 @@ public class SearchMyProjectsActionTest {
   }
 
   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();
   }
 
index 04db472f3bbcd07450ab5b9f042eadeb641c45e1..663603147281e8f2ca74d4b34605e48e55eef8ec 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.db.qualitygate.ProjectQgateAssociation;
 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;
@@ -157,7 +157,7 @@ public class QgateProjectFinderTest {
     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(
index f974161f493d1b7f5d2cb5881c7990a818ed2e80..0fb8e20c6b8b98398180073d1c43331449b9a48d 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.user.GroupRoleDto;
 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;
@@ -114,7 +114,7 @@ public class ProjectsActionTest {
     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);
 
index 111d9c5460ce753ee27e71e9aeb0e5493e5db63a..59428c8fb8aadf86d28366c57244fcd898cfa9c8 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.db.component.ComponentDto;
 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 {
@@ -282,9 +282,9 @@ 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();
index 0a0b670ed225fea12af3b636448acf916de2c1db..4bd7fe55fd1a236b74256c4a4db8dca81b231333 100644 (file)
@@ -122,7 +122,7 @@ import org.sonar.db.user.UserDto;
 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;
@@ -184,7 +184,7 @@ public class MyBatis {
     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);
index 7b13dfeb6618ccbc9567bd3d7acae2162d17831a..bbf20b323ceec5edcb51e487524e5ead89c92e30 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.permission.template.PermissionTemplateGroupDto;
 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
@@ -62,14 +62,14 @@ public class PermissionRepository {
    * @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) {
@@ -77,12 +77,12 @@ public class PermissionRepository {
   }
 
   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);
   }
 
   /**
index afc44a501885740c20407be1329cdd2699f0ec55..0be63eac29f2aa85cee5f14feb4ad7dda5564fb4 100644 (file)
@@ -44,11 +44,11 @@ public class RoleDao implements Dao {
     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);
   }
 
index fd5f56f8f5f3d824e4f58413c0096e0a4c85170a..42a1159a91391057e6acbe0cb44d14c9d19940ff 100644 (file)
@@ -42,9 +42,9 @@ public interface RoleMapper {
 
   void insertGroupRole(GroupRoleDto groupRole);
 
-  void insertUserRole(UserRoleDto userRole);
+  void insertUserRole(UserPermissionDto userRole);
 
-  void deleteUserRole(UserRoleDto userRole);
+  void deleteUserRole(UserPermissionDto userRole);
 
   void deleteGroupRole(GroupRoleDto groupRole);
 
diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserPermissionDto.java
new file mode 100644 (file)
index 0000000..1eeb8ba
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserRoleDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserRoleDto.java
deleted file mode 100644 (file)
index 9d6f147..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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;
-  }
-}
index f90c493b30434bb7b0ddcf063f3e20d493aa6664..b39d25a580a4b4f907be1f66e3708e39820fce74 100644 (file)
@@ -73,7 +73,7 @@
 
   <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
index c3f1ef21fd746a490167b399c04edfc2f3d054a8..e2c390cb7a83e27b0496a91f345d8f29944e4c08 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.db.permission;
 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;
@@ -37,16 +37,16 @@ public class PermissionDbTester {
   }
 
   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();
   }
index 77b63a0adbe892cbeb7a3460922c40c197e6dabd..093ed971150d3fdc36a260bbc6afd2e22a7a2ab1 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.component.ComponentDbTester;
 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;
@@ -359,10 +359,10 @@ public class UserWithPermissionDaoTest {
   }
 
   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();
   }
 
index 7bf8c40784a11ee2d4ceb2bddc8ec491d60fd2d3..50b59dbb9b4e072f01977ae3d322a3deb4d3e02e 100644 (file)
@@ -59,14 +59,14 @@ public class RoleDaoTest {
 
   @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);
@@ -92,7 +92,7 @@ public class RoleDaoTest {
     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();
 
@@ -127,7 +127,7 @@ public class RoleDaoTest {
   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();
@@ -139,7 +139,7 @@ public class RoleDaoTest {
   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();
@@ -211,16 +211,16 @@ public class RoleDaoTest {
   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);
 
@@ -259,9 +259,9 @@ public class RoleDaoTest {
     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);
 
index 83826c130fe99c8f18cd6c7a43bc727be2838240..d13449aef7b49dcf8d9b37ee58a57be691d3884b 100644 (file)
@@ -60,7 +60,7 @@ public class RoleMapperTest {
     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");
index 4d0ff4faaf522df0718fd75697a3003dec3cbb27..aa2458da8aa9be561b54dbd4f74dec0dc380f620 100644 (file)
@@ -535,8 +535,8 @@ public class UserDaoTest {
     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;
   }