]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4453 Added a logical key in the permission_templates table and rearranged permi...
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Fri, 12 Jul 2013 16:01:48 +0000 (18:01 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Fri, 12 Jul 2013 16:01:48 +0000 (18:01 +0200)
98 files changed:
sonar-core/src/main/java/org/sonar/core/date/DateProvider.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/Permission.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java
sonar-core/src/main/java/org/sonar/core/user/Permission.java [deleted file]
sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java [deleted file]
sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java [deleted file]
sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml [deleted file]
sonar-core/src/test/java/org/sonar/core/permission/ComponentPermissionFacadeTest.java
sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java
sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java
sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template-result.xml
sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template.xml
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_copy_permission_templates.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles-result.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRolesProject.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group-result.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users-result.xml
sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users.xml
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java
sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
sonar-server/src/main/java/org/sonar/server/permission/PermissionChangeQuery.java
sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java
sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java
sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java
sonar-server/src/main/java/org/sonar/server/user/UserSession.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/415_create_permission_templates.rb
sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java
sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java
sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeQueryTest.java
sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java
sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java
sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java
sonar-server/src/test/java/org/sonar/server/user/MockUserSession.java
sonar-server/src/test/java/org/sonar/server/user/UserSessionTest.java

diff --git a/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java
new file mode 100644 (file)
index 0000000..f6fd58f
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.date;
+
+import java.util.Date;
+
+/**
+ * @since 3.7
+ */
+public interface DateProvider {
+
+  Date now();
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java
new file mode 100644 (file)
index 0000000..eb716b2
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.date;
+
+import java.util.Date;
+
+public class DefaultDateProvider implements DateProvider {
+
+  @Override
+  public Date now() {
+    return new Date();
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/Permission.java b/sonar-core/src/main/java/org/sonar/core/permission/Permission.java
new file mode 100644 (file)
index 0000000..bf8fd3d
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ *
+ * Holds the constants representing the various global permissions that can be assigned to users & groups
+ *
+ * @since 3.7
+ */
+public class Permission {
+
+  public static final Permission SYSTEM_ADMIN = new Permission("admin");
+  public static final Permission QUALITY_PROFILE_ADMIN = new Permission("profileadmin");
+  public static final Permission DASHBOARD_SHARING = new Permission("shareDashboard");
+  public static final Permission SCAN_EXECUTION = new Permission("scan");
+  public static final Permission DRY_RUN_EXECUTION = new Permission("dryRunScan");
+
+  private final String key;
+  // Use linked hash map to preserve order
+  private static Map<String, Permission> allGlobal = new LinkedHashMap<String, Permission>();
+
+  static {
+    allGlobal.put(SYSTEM_ADMIN.key, SYSTEM_ADMIN);
+    allGlobal.put(QUALITY_PROFILE_ADMIN.key, QUALITY_PROFILE_ADMIN);
+    allGlobal.put(DASHBOARD_SHARING.key, DASHBOARD_SHARING);
+    allGlobal.put(SCAN_EXECUTION.key, SCAN_EXECUTION);
+    allGlobal.put(DRY_RUN_EXECUTION.key, DRY_RUN_EXECUTION);
+  }
+
+  private Permission(String key) {
+    this.key = key;
+  }
+
+  public String key() {
+    return key;
+  }
+
+  public static Map<String, Permission> allGlobal() {
+    return allGlobal;
+  }
+
+  public static boolean isValid(String permission) {
+    return allGlobal.containsKey(permission);
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java
new file mode 100644 (file)
index 0000000..4355599
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.task.TaskComponent;
+import org.sonar.core.date.DateProvider;
+import org.sonar.core.date.DefaultDateProvider;
+import org.sonar.core.persistence.MyBatis;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import java.text.Normalizer;
+import java.util.Date;
+import java.util.List;
+
+public class PermissionDao implements TaskComponent, ServerComponent {
+
+  private final MyBatis myBatis;
+  private final DateProvider dateProvider;
+
+  public PermissionDao(MyBatis myBatis, DateProvider dateProvider) {
+    this.myBatis = myBatis;
+    this.dateProvider = dateProvider;
+  }
+
+  public PermissionDao(MyBatis myBatis) {
+    this(myBatis, new DefaultDateProvider());
+  }
+
+  @CheckForNull
+  public PermissionTemplateDto selectTemplateByName(String templateName) {
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      return mapper.selectByName(templateName);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @CheckForNull
+  public PermissionTemplateDto selectTemplateById(Long templateId) {
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      return mapper.selectById(templateId);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @CheckForNull
+  public PermissionTemplateDto selectPermissionTemplate(String templateName) {
+    PermissionTemplateDto permissionTemplate = null;
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      permissionTemplate = mapper.selectByName(templateName);
+      PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName);
+      if(templateUsersPermissions != null) {
+        permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions());
+      }
+      PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName);
+      if(templateGroupsPermissions != null) {
+        permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions());
+      }
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+    return permissionTemplate;
+  }
+
+  @CheckForNull
+  public List<PermissionTemplateDto> selectAllPermissionTemplates() {
+    SqlSession session = myBatis.openSession();
+    try {
+      return session.selectList("selectAllPermissionTemplates");
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description) {
+    Date creationDate = now();
+    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
+      .setName(templateName)
+      .setKee(generateTemplateKee(templateName, creationDate))
+      .setDescription(description)
+      .setCreatedAt(creationDate)
+      .setUpdatedAt(creationDate);
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.insert(permissionTemplate);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+    return permissionTemplate;
+  }
+
+  public void deletePermissionTemplate(Long templateId) {
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.deleteUsersPermissions(templateId);
+      mapper.deleteGroupsPermissions(templateId);
+      mapper.delete(templateId);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) {
+    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
+      .setId(templateId)
+      .setName(templateName)
+      .setDescription(description)
+      .setUpdatedAt(now());
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.update(permissionTemplate);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void addUserPermission(Long templateId, Long userId, String permission) {
+    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
+      .setTemplateId(templateId)
+      .setUserId(userId)
+      .setPermission(permission)
+      .setCreatedAt(now())
+      .setUpdatedAt(now());
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.insertUserPermission(permissionTemplateUser);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void removeUserPermission(Long templateId, Long userId, String permission) {
+    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setUserId(userId);
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.deleteUserPermission(permissionTemplateUser);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void addGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
+    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setGroupId(groupId)
+      .setCreatedAt(now())
+      .setUpdatedAt(now());
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.insertGroupPermission(permissionTemplateGroup);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void removeGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
+    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setGroupId(groupId);
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.deleteGroupPermission(permissionTemplateGroup);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  private String generateTemplateKee(String name, Date timeStamp) {
+    String normalizedName = Normalizer.normalize(name, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").replace(" ", "_");
+    return normalizedName.toLowerCase() + "_" + DateFormatUtils.format(timeStamp, "yyyyMMdd_HHmmss");
+  }
+
+  private Date now() {
+    return dateProvider.now();
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java
new file mode 100644 (file)
index 0000000..6eead5a
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import java.util.Date;
+import java.util.List;
+
+public class PermissionTemplateDto {
+
+  private Long id;
+  private String name;
+  private String kee;
+  private String description;
+  private List<PermissionTemplateUserDto> usersPermissions;
+  private List<PermissionTemplateGroupDto> groupsPermissions;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public PermissionTemplateDto setName(String name) {
+    this.name = name;
+    return this;
+  }
+
+  public String getKee() {
+    return kee;
+  }
+
+  public PermissionTemplateDto setKee(String kee) {
+    this.kee = kee;
+    return this;
+  }
+
+  @CheckForNull
+  public String getDescription() {
+    return description;
+  }
+
+  public PermissionTemplateDto setDescription(@Nullable String description) {
+    this.description = description;
+    return this;
+  }
+
+  @CheckForNull
+  public List<PermissionTemplateUserDto> getUsersPermissions() {
+    return usersPermissions;
+  }
+
+  public PermissionTemplateDto setUsersPermissions(@Nullable List<PermissionTemplateUserDto> usersPermissions) {
+    this.usersPermissions = usersPermissions;
+    return this;
+  }
+
+  @CheckForNull
+  public List<PermissionTemplateGroupDto> getGroupsPermissions() {
+    return groupsPermissions;
+  }
+
+  public PermissionTemplateDto setGroupsByPermission(@Nullable List<PermissionTemplateGroupDto> groupsPermissions) {
+    this.groupsPermissions = groupsPermissions;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java
new file mode 100644 (file)
index 0000000..a2818d1
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import javax.annotation.Nullable;
+import java.util.Date;
+
+public class PermissionTemplateGroupDto {
+
+  private Long id;
+  private Long templateId;
+  private Long groupId;
+  private String permission;
+  private String groupName;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateGroupDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public Long getTemplateId() {
+    return templateId;
+  }
+
+  public PermissionTemplateGroupDto setTemplateId(Long templateId) {
+    this.templateId = templateId;
+    return this;
+  }
+
+  public Long getGroupId() {
+    return groupId;
+  }
+
+  public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) {
+    this.groupId = groupId;
+    return this;
+  }
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public PermissionTemplateGroupDto setPermission(String permission) {
+    this.permission = permission;
+    return this;
+  }
+
+  public String getGroupName() {
+    return groupName;
+  }
+
+  public PermissionTemplateGroupDto setGroupName(String groupName) {
+    this.groupName = groupName;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateGroupDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
new file mode 100644 (file)
index 0000000..f14df16
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+/**
+ * @since 3.7
+ */
+public interface PermissionTemplateMapper {
+
+  void insert(PermissionTemplateDto permissionTemplate);
+
+  void update(PermissionTemplateDto permissionTemplate);
+
+  void delete(Long templateId);
+
+  void deleteUsersPermissions(Long templateId);
+
+  void deleteGroupsPermissions(Long templateId);
+
+  PermissionTemplateDto selectByName(String templateName);
+
+  PermissionTemplateDto selectById(Long templateId);
+
+  PermissionTemplateDto selectTemplateUsersPermissions(String templateName);
+
+  PermissionTemplateDto selectTemplateGroupsPermissions(String templateName);
+
+  void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+
+  void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+
+  void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+
+  void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java
new file mode 100644 (file)
index 0000000..6201445
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import java.util.Date;
+
+public class PermissionTemplateUserDto {
+
+  private Long id;
+  private Long templateId;
+  private Long userId;
+  private String permission;
+  private String userName;
+  private String userLogin;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateUserDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public Long getTemplateId() {
+    return templateId;
+  }
+
+  public PermissionTemplateUserDto setTemplateId(Long templateId) {
+    this.templateId = templateId;
+    return this;
+  }
+
+  public Long getUserId() {
+    return userId;
+  }
+
+  public PermissionTemplateUserDto setUserId(Long userId) {
+    this.userId = userId;
+    return this;
+  }
+
+  public String getUserName() {
+    return userName;
+  }
+
+  public PermissionTemplateUserDto setUserName(String userName) {
+    this.userName = userName;
+    return this;
+  }
+
+  public String getUserLogin() {
+    return userLogin;
+  }
+
+  public PermissionTemplateUserDto setUserLogin(String userLogin) {
+    this.userLogin = userLogin;
+    return this;
+  }
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public PermissionTemplateUserDto setPermission(String permission) {
+    this.permission = permission;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateUserDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
index 1798e89e92003abd5145cd30d687bb30d47264c9..3027aada8fa9a3c8862e435c1c3eacd367667de6 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.core.duplication.DuplicationDao;
 import org.sonar.core.graph.jdbc.GraphDao;
 import org.sonar.core.issue.db.*;
 import org.sonar.core.measure.MeasureFilterDao;
+import org.sonar.core.permission.PermissionDao;
 import org.sonar.core.properties.PropertiesDao;
 import org.sonar.core.purge.PurgeDao;
 import org.sonar.core.resource.ResourceDao;
@@ -34,7 +35,10 @@ import org.sonar.core.resource.ResourceKeyUpdaterDao;
 import org.sonar.core.rule.RuleDao;
 import org.sonar.core.source.jdbc.SnapshotDataDao;
 import org.sonar.core.template.LoadedTemplateDao;
-import org.sonar.core.user.*;
+import org.sonar.core.user.AuthorDao;
+import org.sonar.core.user.AuthorizationDao;
+import org.sonar.core.user.RoleDao;
+import org.sonar.core.user.UserDao;
 
 import java.util.List;
 
index e5e4c015a9c8cd8ed7ae8d33019c341d6ea8e7fd..19a9ecbbf57d317e04210fcc3526e262b429e381 100644 (file)
@@ -47,6 +47,10 @@ import org.sonar.core.graph.jdbc.GraphDtoMapper;
 import org.sonar.core.issue.db.*;
 import org.sonar.core.measure.MeasureFilterDto;
 import org.sonar.core.measure.MeasureFilterMapper;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionTemplateGroupDto;
+import org.sonar.core.permission.PermissionTemplateMapper;
+import org.sonar.core.permission.PermissionTemplateUserDto;
 import org.sonar.core.properties.PropertiesMapper;
 import org.sonar.core.properties.PropertyDto;
 import org.sonar.core.purge.PurgeMapper;
index eeec2bbebefc24eed9d7da7f746460e7d0521463..d5dcbc4fe03035d967168c36b3eaca2092e943cb 100644 (file)
@@ -27,10 +27,10 @@ import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.security.ResourcePermissions;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.permission.ComponentPermissionFacade;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionTemplateGroupDto;
+import org.sonar.core.permission.PermissionTemplateUserDto;
 import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.user.PermissionTemplateDto;
-import org.sonar.core.user.PermissionTemplateGroupDto;
-import org.sonar.core.user.PermissionTemplateUserDto;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/sonar-core/src/main/java/org/sonar/core/user/Permission.java b/sonar-core/src/main/java/org/sonar/core/user/Permission.java
deleted file mode 100644 (file)
index 98bb977..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- *
- * Holds the constants representing the various global permissions that can be assigned to users & groups
- *
- * @since 3.7
- */
-public class Permission {
-
-  public static final Permission SYSTEM_ADMIN = new Permission("admin");
-  public static final Permission QUALITY_PROFILE_ADMIN = new Permission("profileadmin");
-  public static final Permission DASHBOARD_SHARING = new Permission("shareDashboard");
-  public static final Permission SCAN_EXECUTION = new Permission("scan");
-  public static final Permission DRY_RUN_EXECUTION = new Permission("dryRunScan");
-
-  private final String key;
-  // Use linked hash map to preserve order
-  private static Map<String, Permission> allGlobal = new LinkedHashMap<String, Permission>();
-
-  static {
-    allGlobal.put(SYSTEM_ADMIN.key, SYSTEM_ADMIN);
-    allGlobal.put(QUALITY_PROFILE_ADMIN.key, QUALITY_PROFILE_ADMIN);
-    allGlobal.put(DASHBOARD_SHARING.key, DASHBOARD_SHARING);
-    allGlobal.put(SCAN_EXECUTION.key, SCAN_EXECUTION);
-    allGlobal.put(DRY_RUN_EXECUTION.key, DRY_RUN_EXECUTION);
-  }
-
-  private Permission(String key) {
-    this.key = key;
-  }
-
-  public String key() {
-    return key;
-  }
-
-  public static Map<String, Permission> allGlobal() {
-    return allGlobal;
-  }
-
-  public static boolean isValid(String permission) {
-    return allGlobal.containsKey(permission);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java
deleted file mode 100644 (file)
index bad927a..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.task.TaskComponent;
-import org.sonar.core.persistence.MyBatis;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Date;
-import java.util.List;
-
-public class PermissionDao implements TaskComponent, ServerComponent {
-
-  private final MyBatis myBatis;
-
-  public PermissionDao(MyBatis myBatis) {
-    this.myBatis = myBatis;
-  }
-
-  @CheckForNull
-  public PermissionTemplateDto selectTemplateByName(String templateName) {
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      return mapper.selectByName(templateName);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  @CheckForNull
-  public PermissionTemplateDto selectTemplateById(Long templateId) {
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      return mapper.selectById(templateId);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  @CheckForNull
-  public PermissionTemplateDto selectPermissionTemplate(String templateName) {
-    PermissionTemplateDto permissionTemplate = null;
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      permissionTemplate = mapper.selectByName(templateName);
-      PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName);
-      if(templateUsersPermissions != null) {
-        permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions());
-      }
-      PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName);
-      if(templateGroupsPermissions != null) {
-        permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions());
-      }
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-    return permissionTemplate;
-  }
-
-  @CheckForNull
-  public List<PermissionTemplateDto> selectAllPermissionTemplates() {
-    SqlSession session = myBatis.openSession();
-    try {
-      return session.selectList("selectAllPermissionTemplates");
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description) {
-    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
-      .setName(templateName)
-      .setDescription(description)
-      .setCreatedAt(now())
-      .setUpdatedAt(now());
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.insert(permissionTemplate);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-    return permissionTemplate;
-  }
-
-  public void deletePermissionTemplate(Long templateId) {
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.deleteUsersPermissions(templateId);
-      mapper.deleteGroupsPermissions(templateId);
-      mapper.delete(templateId);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) {
-    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
-      .setId(templateId)
-      .setName(templateName)
-      .setDescription(description)
-      .setUpdatedAt(now());
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.update(permissionTemplate);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void addUserPermission(Long templateId, Long userId, String permission) {
-    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
-      .setTemplateId(templateId)
-      .setUserId(userId)
-      .setPermission(permission)
-      .setCreatedAt(now())
-      .setUpdatedAt(now());
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.insertUserPermission(permissionTemplateUser);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void removeUserPermission(Long templateId, Long userId, String permission) {
-    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setUserId(userId);
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.deleteUserPermission(permissionTemplateUser);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void addGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
-    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setGroupId(groupId)
-      .setCreatedAt(now())
-      .setUpdatedAt(now());
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.insertGroupPermission(permissionTemplateGroup);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void removeGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
-    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setGroupId(groupId);
-    SqlSession session = myBatis.openSession();
-    try {
-      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
-      mapper.deleteGroupPermission(permissionTemplateGroup);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  private Date now() {
-    return new Date();
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java
deleted file mode 100644 (file)
index 93db152..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import java.util.Date;
-import java.util.List;
-
-public class PermissionTemplateDto {
-
-  private Long id;
-  private String name;
-  private String description;
-  private List<PermissionTemplateUserDto> usersPermissions;
-  private List<PermissionTemplateGroupDto> groupsPermissions;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public PermissionTemplateDto setName(String name) {
-    this.name = name;
-    return this;
-  }
-
-  @CheckForNull
-  public String getDescription() {
-    return description;
-  }
-
-  public PermissionTemplateDto setDescription(@Nullable String description) {
-    this.description = description;
-    return this;
-  }
-
-  @CheckForNull
-  public List<PermissionTemplateUserDto> getUsersPermissions() {
-    return usersPermissions;
-  }
-
-  public PermissionTemplateDto setUsersPermissions(@Nullable List<PermissionTemplateUserDto> usersPermissions) {
-    this.usersPermissions = usersPermissions;
-    return this;
-  }
-
-  @CheckForNull
-  public List<PermissionTemplateGroupDto> getGroupsPermissions() {
-    return groupsPermissions;
-  }
-
-  public PermissionTemplateDto setGroupsByPermission(@Nullable List<PermissionTemplateGroupDto> groupsPermissions) {
-    this.groupsPermissions = groupsPermissions;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java
deleted file mode 100644 (file)
index 157c6f7..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import javax.annotation.Nullable;
-import java.util.Date;
-
-public class PermissionTemplateGroupDto {
-
-  private Long id;
-  private Long templateId;
-  private Long groupId;
-  private String permission;
-  private String groupName;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateGroupDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getTemplateId() {
-    return templateId;
-  }
-
-  public PermissionTemplateGroupDto setTemplateId(Long templateId) {
-    this.templateId = templateId;
-    return this;
-  }
-
-  public Long getGroupId() {
-    return groupId;
-  }
-
-  public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) {
-    this.groupId = groupId;
-    return this;
-  }
-
-  public String getPermission() {
-    return permission;
-  }
-
-  public PermissionTemplateGroupDto setPermission(String permission) {
-    this.permission = permission;
-    return this;
-  }
-
-  public String getGroupName() {
-    return groupName;
-  }
-
-  public PermissionTemplateGroupDto setGroupName(String groupName) {
-    this.groupName = groupName;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateGroupDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java
deleted file mode 100644 (file)
index 8f00c50..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-/**
- * @since 3.7
- */
-public interface PermissionTemplateMapper {
-
-  void insert(PermissionTemplateDto permissionTemplate);
-
-  void update(PermissionTemplateDto permissionTemplate);
-
-  void delete(Long templateId);
-
-  void deleteUsersPermissions(Long templateId);
-
-  void deleteGroupsPermissions(Long templateId);
-
-  PermissionTemplateDto selectByName(String templateName);
-
-  PermissionTemplateDto selectById(Long templateId);
-
-  PermissionTemplateDto selectTemplateUsersPermissions(String templateName);
-
-  PermissionTemplateDto selectTemplateGroupsPermissions(String templateName);
-
-  void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
-
-  void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
-
-  void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
-
-  void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java
deleted file mode 100644 (file)
index b0fa21a..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import java.util.Date;
-
-public class PermissionTemplateUserDto {
-
-  private Long id;
-  private Long templateId;
-  private Long userId;
-  private String permission;
-  private String userName;
-  private String userLogin;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateUserDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getTemplateId() {
-    return templateId;
-  }
-
-  public PermissionTemplateUserDto setTemplateId(Long templateId) {
-    this.templateId = templateId;
-    return this;
-  }
-
-  public Long getUserId() {
-    return userId;
-  }
-
-  public PermissionTemplateUserDto setUserId(Long userId) {
-    this.userId = userId;
-    return this;
-  }
-
-  public String getUserName() {
-    return userName;
-  }
-
-  public PermissionTemplateUserDto setUserName(String userName) {
-    this.userName = userName;
-    return this;
-  }
-
-  public String getUserLogin() {
-    return userLogin;
-  }
-
-  public PermissionTemplateUserDto setUserLogin(String userLogin) {
-    this.userLogin = userLogin;
-    return this;
-  }
-
-  public String getPermission() {
-    return permission;
-  }
-
-  public PermissionTemplateUserDto setPermission(String permission) {
-    this.permission = permission;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateUserDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
new file mode 100644 (file)
index 0000000..525f2c8
--- /dev/null
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.permission.PermissionTemplateMapper">
+
+  <insert id="insert" parameterType="PermissionTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+    INSERT INTO permission_templates (name, kee, description, created_at, updated_at)
+    VALUES (#{name}, #{kee}, #{description}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <update id="update" parameterType="PermissionTemplate">
+    UPDATE permission_templates
+    SET name = #{name}, description = #{description}, updated_at = #{updatedAt}
+    WHERE id = #{id}
+  </update>
+
+  <delete id="delete" parameterType="Long">
+    DELETE FROM permission_templates
+    WHERE id = #{templateId}
+  </delete>
+
+  <delete id="deleteUsersPermissions" parameterType="Long">
+    DELETE FROM perm_templates_users
+    WHERE template_id = #{templateId}
+  </delete>
+
+  <delete id="deleteGroupsPermissions" parameterType="Long">
+    DELETE FROM perm_templates_groups
+    WHERE template_id = #{templateId}
+  </delete>
+
+  <insert id="insertUserPermission" parameterType="PermissionTemplateUser">
+    INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at)
+    VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <delete id="deleteUserPermission" parameterType="PermissionTemplateUser">
+    DELETE FROM perm_templates_users
+    WHERE template_id = #{templateId}
+    AND user_id = #{userId}
+    AND permission_reference = #{permission}
+  </delete>
+
+  <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup">
+    INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at)
+    VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <delete id="deleteGroupPermission" parameterType="PermissionTemplateGroup">
+    DELETE FROM perm_templates_groups
+    WHERE template_id = #{templateId}
+    AND permission_reference = #{permission}
+    AND
+    <choose>
+      <when test="groupId != null">
+        group_id = #{groupId}
+      </when>
+      <otherwise>
+        group_id IS NULL
+      </otherwise>
+    </choose>
+  </delete>
+
+  <select id="selectById" parameterType="Long" resultType="PermissionTemplate">
+    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+    FROM permission_templates
+    WHERE id = #{templateId}
+  </select>
+
+  <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
+    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+    FROM permission_templates
+    WHERE name = #{templateName}
+  </select>
+
+  <select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
+    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+    FROM permission_templates
+  </select>
+
+  <select id="selectTemplateUsersPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
+    SELECT  pt.id AS template_id,
+            pt.name AS template_name,
+            pt.description AS template_description,
+            pt.created_at AS template_created_at,
+            pt.updated_at AS template_updated_at,
+            ptu.id AS permission_template_user_id,
+            ptu.permission_reference AS user_permission,
+            ptu.user_id AS user_id,
+            u.name AS user_name,
+            u.login AS user_login
+    FROM permission_templates pt
+    INNER JOIN perm_templates_users ptu ON ptu.template_id = pt.id
+    INNER JOIN users u ON u.id = ptu.user_id
+    WHERE pt.name = #{templateName}
+  </select>
+
+  <select id="selectTemplateGroupsPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
+    SELECT  pt.id AS template_id,
+            pt.name AS template_name,
+            pt.description AS template_description,
+            pt.created_at AS template_created_at,
+            pt.updated_at AS template_updated_at,
+            ptg.id AS permission_template_group_id,
+            ptg.permission_reference AS group_permission,
+            ptg.group_id AS group_id,
+            g.name AS group_name
+    FROM permission_templates pt
+    INNER JOIN perm_templates_groups ptg ON ptg.template_id = pt.id
+    LEFT OUTER JOIN groups g ON g.id = ptg.group_id
+    WHERE pt.name = #{templateName}
+    AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
+  </select>
+
+  <resultMap id="fullPermissionsTemplateResult" type="PermissionTemplate">
+    <id property="id" column="template_id"/>
+    <result property="name" column="template_name"/>
+    <result property="description" column="template_description"/>
+    <result property="createdAt" column="template_created_at"/>
+    <result property="updatedAt" column="template_updated_at"/>
+    <collection property="usersPermissions" ofType="PermissionTemplateUser">
+      <id property="id" column="permission_template_user_id"/>
+      <result property="userId" column="user_id"/>
+      <result property="permission" column="user_permission"/>
+      <result property="userName" column="user_name"/>
+      <result property="userLogin" column="user_login"/>
+    </collection>
+    <collection property="groupsPermissions" ofType="PermissionTemplateGroup">
+      <id property="id" column="permission_template_group_id"/>
+      <result property="groupId" column="group_id"/>
+      <result property="permission" column="group_permission"/>
+      <result property="groupName" column="group_name"/>
+    </collection>
+  </resultMap>
+
+</mapper>
index e55347bdf3bb2d3ab4b261066b4b890ed5c973bb..92f82950400054f571567d66f38dd800a750c247 100644 (file)
@@ -15,7 +15,7 @@ INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1);
 INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2);
 
 -- Default permissions - Replaces the previous role-based properties such as 'sonar.role.admin.TRK.defaultGroups' (see migration 418)
-INSERT INTO PERMISSION_TEMPLATES(ID, name, description) VALUES (1, 'Default template', 'This permission template will be used as default when no other permission configuration is available');
+INSERT INTO PERMISSION_TEMPLATES(ID, name, kee, description) VALUES (1, 'Default template', 'default_template', 'This permission template will be used as default when no other permission configuration is available');
 ALTER TABLE PERMISSION_TEMPLATES ALTER COLUMN ID RESTART WITH 2;
 
 INSERT INTO PERM_TEMPLATES_GROUPS(ID, template_id, group_id, permission_reference) VALUES (1, 1, 1, 'admin');
index 2624837ac89fdb999c8d6e3a3c3a308414e96484..b450b85b8342693089c623da6beed905db58333d 100644 (file)
@@ -535,6 +535,7 @@ CREATE TABLE "SNAPSHOT_DATA" (
 CREATE TABLE "PERMISSION_TEMPLATES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
+  "KEE" VARCHAR(100) NOT NULL,
   "DESCRIPTION" VARCHAR(4000),
   "CREATED_AT" TIMESTAMP,
   "UPDATED_AT" TIMESTAMP
diff --git a/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml
deleted file mode 100644 (file)
index 4e9dc2d..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.user.PermissionTemplateMapper">
-
-  <insert id="insert" parameterType="PermissionTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO permission_templates (name, description, created_at, updated_at)
-    VALUES (#{name}, #{description}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <update id="update" parameterType="PermissionTemplate">
-    UPDATE permission_templates
-    SET name = #{name}, description = #{description}, updated_at = #{updatedAt}
-    WHERE id = #{id}
-  </update>
-
-  <delete id="delete" parameterType="Long">
-    DELETE FROM permission_templates
-    WHERE id = #{templateId}
-  </delete>
-
-  <delete id="deleteUsersPermissions" parameterType="Long">
-    DELETE FROM perm_templates_users
-    WHERE template_id = #{templateId}
-  </delete>
-
-  <delete id="deleteGroupsPermissions" parameterType="Long">
-    DELETE FROM perm_templates_groups
-    WHERE template_id = #{templateId}
-  </delete>
-
-  <insert id="insertUserPermission" parameterType="PermissionTemplateUser">
-    INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at)
-    VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <delete id="deleteUserPermission" parameterType="PermissionTemplateUser">
-    DELETE FROM perm_templates_users
-    WHERE template_id = #{templateId}
-    AND user_id = #{userId}
-    AND permission_reference = #{permission}
-  </delete>
-
-  <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup">
-    INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at)
-    VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <delete id="deleteGroupPermission" parameterType="PermissionTemplateGroup">
-    DELETE FROM perm_templates_groups
-    WHERE template_id = #{templateId}
-    AND permission_reference = #{permission}
-    AND
-    <choose>
-      <when test="groupId != null">
-        group_id = #{groupId}
-      </when>
-      <otherwise>
-        group_id IS NULL
-      </otherwise>
-    </choose>
-  </delete>
-
-  <select id="selectById" parameterType="Long" resultType="PermissionTemplate">
-    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
-    FROM permission_templates
-    WHERE id = #{templateId}
-  </select>
-
-  <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
-    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
-    FROM permission_templates
-    WHERE name = #{templateName}
-  </select>
-
-  <select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
-    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
-    FROM permission_templates
-  </select>
-
-  <select id="selectTemplateUsersPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
-    SELECT  pt.id AS template_id,
-            pt.name AS template_name,
-            pt.description AS template_description,
-            pt.created_at AS template_created_at,
-            pt.updated_at AS template_updated_at,
-            ptu.id AS permission_template_user_id,
-            ptu.permission_reference AS user_permission,
-            ptu.user_id AS user_id,
-            u.name AS user_name,
-            u.login AS user_login
-    FROM permission_templates pt
-    INNER JOIN perm_templates_users ptu ON ptu.template_id = pt.id
-    INNER JOIN users u ON u.id = ptu.user_id
-    WHERE pt.name = #{templateName}
-  </select>
-
-  <select id="selectTemplateGroupsPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
-    SELECT  pt.id AS template_id,
-            pt.name AS template_name,
-            pt.description AS template_description,
-            pt.created_at AS template_created_at,
-            pt.updated_at AS template_updated_at,
-            ptg.id AS permission_template_group_id,
-            ptg.permission_reference AS group_permission,
-            ptg.group_id AS group_id,
-            g.name AS group_name
-    FROM permission_templates pt
-    INNER JOIN perm_templates_groups ptg ON ptg.template_id = pt.id
-    LEFT OUTER JOIN groups g ON g.id = ptg.group_id
-    WHERE pt.name = #{templateName}
-    AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
-  </select>
-
-  <resultMap id="fullPermissionsTemplateResult" type="PermissionTemplate">
-    <id property="id" column="template_id"/>
-    <result property="name" column="template_name"/>
-    <result property="description" column="template_description"/>
-    <result property="createdAt" column="template_created_at"/>
-    <result property="updatedAt" column="template_updated_at"/>
-    <collection property="usersPermissions" ofType="PermissionTemplateUser">
-      <id property="id" column="permission_template_user_id"/>
-      <result property="userId" column="user_id"/>
-      <result property="permission" column="user_permission"/>
-      <result property="userName" column="user_name"/>
-      <result property="userLogin" column="user_login"/>
-    </collection>
-    <collection property="groupsPermissions" ofType="PermissionTemplateGroup">
-      <id property="id" column="permission_template_group_id"/>
-      <result property="groupId" column="group_id"/>
-      <result property="permission" column="group_permission"/>
-      <result property="groupName" column="group_name"/>
-    </collection>
-  </resultMap>
-
-</mapper>
index 6760a01ee15ca2dac39db885c73046f9e72c3a09..7259c8b7ff23539d8e93c1cec98e26d51ad4389a 100644 (file)
@@ -23,7 +23,6 @@ package org.sonar.core.permission;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.user.PermissionDao;
 import org.sonar.core.user.RoleDao;
 import org.sonar.core.user.UserDao;
 
diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java
new file mode 100644 (file)
index 0000000..9cf31e2
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.permission;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.core.date.DateProvider;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import java.util.Date;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+
+public class PermissionDaoTest extends AbstractDaoTestCase {
+
+  private final Date now = DateUtils.parseDateTime("2013-01-02T03:04:05+0100");
+
+  private PermissionDao permissionDao;
+  private DateProvider dateProvider;
+
+  @Before
+  public void setUpDao() {
+    dateProvider = mock(DateProvider.class);
+    stub(dateProvider.now()).toReturn(now);
+    permissionDao = new PermissionDao(getMyBatis(), dateProvider);
+  }
+
+  @Test
+  public void should_create_permission_template() throws Exception {
+    setupData("createPermissionTemplate");
+    PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("my template", "my description");
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+    checkTable("createPermissionTemplate", "permission_templates", "id", "name", "kee", "description");
+  }
+
+  @Test
+  public void should_normalize_kee_on_template_creation() throws Exception {
+    setupData("createNonAsciiPermissionTemplate");
+    PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("Môü Gnô Gnèçàß", "my description");
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+    checkTable("createNonAsciiPermissionTemplate", "permission_templates", "id", "name", "kee", "description");
+  }
+
+  @Test
+  public void should_select_permission_template() throws Exception {
+    setupData("selectPermissionTemplate");
+    PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template");
+
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
+    assertThat(permissionTemplate.getUsersPermissions()).hasSize(3);
+    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L);
+    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userLogin").containsOnly("login1", "login2", "login2");
+    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userName").containsOnly("user1", "user2", "user2");
+    assertThat(permissionTemplate.getUsersPermissions()).onProperty("permission").containsOnly("user_permission1", "user_permission1", "user_permission2");
+    assertThat(permissionTemplate.getGroupsPermissions()).hasSize(3);
+    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupId").containsOnly(1L, 2L, null);
+    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupName").containsOnly("group1", "group2", null);
+    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("permission").containsOnly("group_permission1", "group_permission1", "group_permission2");
+  }
+
+  @Test
+  public void should_select_empty_permission_template() throws Exception {
+    setupData("selectEmptyPermissionTemplate");
+    PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template");
+
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
+    assertThat(permissionTemplate.getUsersPermissions()).isNull();
+    assertThat(permissionTemplate.getGroupsPermissions()).isNull();
+  }
+
+  @Test
+  public void should_select_permission_template_by_name() throws Exception {
+    setupData("selectPermissionTemplate");
+
+    PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template");
+
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+    assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
+  }
+
+  @Test
+  public void should_select_permission_template_by_id() throws Exception {
+    setupData("selectPermissionTemplate");
+
+    PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateById(1L);
+
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+    assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
+  }
+
+  @Test
+  public void should_select_all_permission_templates() throws Exception {
+    setupData("selectAllPermissionTemplates");
+
+    List<PermissionTemplateDto> permissionTemplates = permissionDao.selectAllPermissionTemplates();
+
+    assertThat(permissionTemplates).hasSize(3);
+    assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L);
+    assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3");
+    assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3");
+  }
+
+  @Test
+  public void should_update_permission_template() throws Exception {
+    setupData("updatePermissionTemplate");
+
+    permissionDao.updatePermissionTemplate(1L, "new_name", "new_description");
+
+    checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "kee", "description");
+  }
+
+  @Test
+  public void should_delete_permission_template() throws Exception {
+    setupData("deletePermissionTemplate");
+
+    permissionDao.deletePermissionTemplate(1L);
+
+    checkTable("deletePermissionTemplate", "permission_templates", "id", "name", "description");
+    checkTable("deletePermissionTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("deletePermissionTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_add_user_permission_to_template() throws Exception {
+    setupData("addUserPermissionToTemplate");
+    permissionDao.addUserPermission(1L, 1L, "new_permission");
+
+    checkTable("addUserPermissionToTemplate", "permission_templates", "id", "name", "description");
+    checkTable("addUserPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("addUserPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_remove_user_permission_from_template() throws Exception {
+    setupData("removeUserPermissionFromTemplate");
+    permissionDao.removeUserPermission(1L, 2L, "permission_to_remove");
+
+    checkTable("removeUserPermissionFromTemplate", "permission_templates", "id", "name", "description");
+    checkTable("removeUserPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("removeUserPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_add_group_permission_to_template() throws Exception {
+    setupData("addGroupPermissionToTemplate");
+    permissionDao.addGroupPermission(1L, 1L, "new_permission");
+
+    checkTable("addGroupPermissionToTemplate", "permission_templates", "id", "name", "description");
+    checkTable("addGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("addGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_remove_group_permission_from_template() throws Exception {
+    setupData("removeGroupPermissionFromTemplate");
+    permissionDao.removeGroupPermission(1L, 2L, "permission_to_remove");
+
+    checkTable("removeGroupPermissionFromTemplate", "permission_templates", "id", "name", "description");
+    checkTable("removeGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("removeGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_add_group_permission_with_null_name() throws Exception {
+    setupData("addNullGroupPermissionToTemplate");
+    permissionDao.addGroupPermission(1L, null, "new_permission");
+
+    checkTable("addNullGroupPermissionToTemplate", "permission_templates", "id", "name", "description");
+    checkTable("addNullGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("addNullGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+  @Test
+  public void should_remove_group_permission_with_null_name() throws Exception {
+    setupData("removeNullGroupPermissionFromTemplate");
+    permissionDao.removeGroupPermission(1L, null, "permission_to_remove");
+
+    checkTable("removeNullGroupPermissionFromTemplate", "permission_templates", "id", "name", "description");
+    checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+}
index 5a6fc165002f616b50e446606d0e14070ecfad2a..c39e89527c151952fc89397eb641901824b64f84 100644 (file)
@@ -28,8 +28,8 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.core.permission.ComponentPermissionFacade;
+import org.sonar.core.permission.PermissionDao;
 import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.user.PermissionDao;
 import org.sonar.core.user.RoleDao;
 import org.sonar.core.user.UserDao;
 
diff --git a/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java
deleted file mode 100644 (file)
index bfce78a..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.user;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PermissionDaoTest extends AbstractDaoTestCase {
-
-  private PermissionDao permissionDao;
-
-  @Before
-  public void setUpDao() {
-    permissionDao = new PermissionDao(getMyBatis());
-  }
-
-  @Test
-  public void should_create_permission_template() throws Exception {
-    setupData("createPermissionTemplate");
-    PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("my template", "my description");
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getId()).isEqualTo(1L);
-    checkTable("createPermissionTemplate", "permission_templates", "id", "name", "description");
-  }
-
-  @Test
-  public void should_select_permission_template() throws Exception {
-    setupData("selectPermissionTemplate");
-    PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template");
-
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getName()).isEqualTo("my template");
-    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
-    assertThat(permissionTemplate.getUsersPermissions()).hasSize(3);
-    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L);
-    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userLogin").containsOnly("login1", "login2", "login2");
-    assertThat(permissionTemplate.getUsersPermissions()).onProperty("userName").containsOnly("user1", "user2", "user2");
-    assertThat(permissionTemplate.getUsersPermissions()).onProperty("permission").containsOnly("user_permission1", "user_permission1", "user_permission2");
-    assertThat(permissionTemplate.getGroupsPermissions()).hasSize(3);
-    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupId").containsOnly(1L, 2L, null);
-    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupName").containsOnly("group1", "group2", null);
-    assertThat(permissionTemplate.getGroupsPermissions()).onProperty("permission").containsOnly("group_permission1", "group_permission1", "group_permission2");
-  }
-
-  @Test
-  public void should_select_empty_permission_template() throws Exception {
-    setupData("selectEmptyPermissionTemplate");
-    PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template");
-
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getName()).isEqualTo("my template");
-    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
-    assertThat(permissionTemplate.getUsersPermissions()).isNull();
-    assertThat(permissionTemplate.getGroupsPermissions()).isNull();
-  }
-
-  @Test
-  public void should_select_permission_template_by_name() throws Exception {
-    setupData("selectPermissionTemplate");
-
-    PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template");
-
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getId()).isEqualTo(1L);
-    assertThat(permissionTemplate.getName()).isEqualTo("my template");
-    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
-  }
-
-  @Test
-  public void should_select_permission_template_by_id() throws Exception {
-    setupData("selectPermissionTemplate");
-
-    PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateById(1L);
-
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getId()).isEqualTo(1L);
-    assertThat(permissionTemplate.getName()).isEqualTo("my template");
-    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
-  }
-
-  @Test
-  public void should_select_all_permission_templates() throws Exception {
-    setupData("selectAllPermissionTemplates");
-
-    List<PermissionTemplateDto> permissionTemplates = permissionDao.selectAllPermissionTemplates();
-
-    assertThat(permissionTemplates).hasSize(3);
-    assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L);
-    assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3");
-    assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3");
-  }
-
-  @Test
-  public void should_update_permission_template() throws Exception {
-    setupData("updatePermissionTemplate");
-
-    permissionDao.updatePermissionTemplate(1L, "new_name", "new_description");
-
-    checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "description");
-  }
-
-  @Test
-  public void should_delete_permission_template() throws Exception {
-    setupData("deletePermissionTemplate");
-
-    permissionDao.deletePermissionTemplate(1L);
-
-    checkTable("deletePermissionTemplate", "permission_templates", "id", "name", "description");
-    checkTable("deletePermissionTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("deletePermissionTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_add_user_permission_to_template() throws Exception {
-    setupData("addUserPermissionToTemplate");
-    permissionDao.addUserPermission(1L, 1L, "new_permission");
-
-    checkTable("addUserPermissionToTemplate", "permission_templates", "id", "name", "description");
-    checkTable("addUserPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("addUserPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_remove_user_permission_from_template() throws Exception {
-    setupData("removeUserPermissionFromTemplate");
-    permissionDao.removeUserPermission(1L, 2L, "permission_to_remove");
-
-    checkTable("removeUserPermissionFromTemplate", "permission_templates", "id", "name", "description");
-    checkTable("removeUserPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("removeUserPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_add_group_permission_to_template() throws Exception {
-    setupData("addGroupPermissionToTemplate");
-    permissionDao.addGroupPermission(1L, 1L, "new_permission");
-
-    checkTable("addGroupPermissionToTemplate", "permission_templates", "id", "name", "description");
-    checkTable("addGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("addGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_remove_group_permission_from_template() throws Exception {
-    setupData("removeGroupPermissionFromTemplate");
-    permissionDao.removeGroupPermission(1L, 2L, "permission_to_remove");
-
-    checkTable("removeGroupPermissionFromTemplate", "permission_templates", "id", "name", "description");
-    checkTable("removeGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("removeGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_add_group_permission_with_null_name() throws Exception {
-    setupData("addNullGroupPermissionToTemplate");
-    permissionDao.addGroupPermission(1L, null, "new_permission");
-
-    checkTable("addNullGroupPermissionToTemplate", "permission_templates", "id", "name", "description");
-    checkTable("addNullGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("addNullGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-  @Test
-  public void should_remove_group_permission_with_null_name() throws Exception {
-    setupData("removeNullGroupPermissionFromTemplate");
-    permissionDao.removeGroupPermission(1L, null, "permission_to_remove");
-
-    checkTable("removeNullGroupPermissionFromTemplate", "permission_templates", "id", "name", "description");
-    checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-}
index 582616cc5a619ebdb23aaab1b01127cf0a8d9c30..6d0c9b0830e4d6e1e1d720a99bfe02247041df85 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.core.user;
 
 import org.junit.Test;
 import org.sonar.api.security.DefaultGroups;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 
 import static org.fest.assertions.Assertions.assertThat;
index ab25beb9f0787bef94ebd0040754a6f80b1836ba..c512d7e3a61db18037d2494345e64a619dc16d07 100644 (file)
@@ -21,7 +21,7 @@
   <user_roles id="2" user_id="200" resource_id="123" role="admin"/>
 
   <!-- default permission template for all qualifiers -->
-  <permission_templates id="1" name="default"/>
+  <permission_templates id="1" name="default" kee="default_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="101" permission_reference="user"/>
index f962b008ca8b1e73a22f73926a6a650359ee12db..2c9dd6309fd2bd165b2f9507444da26229e85ba0 100644 (file)
@@ -12,7 +12,7 @@
 
 
   <!-- default permission template for all qualifiers -->
-  <permission_templates id="1" name="default"/>
+  <permission_templates id="1" name="default" kee="default_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="101" permission_reference="user"/>
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..c802167
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="new_permission"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..7d42701
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="[null]" permission_reference="new_permission"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..40bf5d4
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="new_permission"/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..962c1d6
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_030405" description="my description"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..5ed00ba
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..0fbf652
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..5ed00ba
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..06f6413
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description" created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users/>
+
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml
new file mode 100644 (file)
index 0000000..b5a8064
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description" created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
+
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..140738d
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..3258dcc
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
+  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..cc62050
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..3e32895
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="2" template_id="1" group_id="[null]" permission_reference="permission_to_remove"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..8998378
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
+
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..779bd77
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="permission_to_remove"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
+
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml
new file mode 100644 (file)
index 0000000..1fa43be
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="template1" kee="my_template_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="my_template_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="3" name="template3" kee="my_template_20130102_030405" description="description3" created_at="[null]" updated_at="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..e8360e4
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description" created_at="[null]" updated_at="[null]"/>
+
+  <users id="1" login="user1" name="user1" />
+  <users id="2" login="user2" name="user2" />
+
+  <groups id="1" name="group1"/>
+  <groups id="2" name="group2"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..8cfb960
--- /dev/null
@@ -0,0 +1,20 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description" created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
+
+  <users id="1" login="login1" name="user1" />
+  <users id="2" login="login2" name="user2" />
+
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
+  <!-- Anyone group -->
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
+  <!-- Unmatched group -->
+  <perm_templates_groups id="4" template_id="1" group_id="999999" permission_reference="group_permission2"/>
+
+  <groups id="1" name="group1"/>
+  <groups id="2" name="group2"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..6f25f75
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="new_name" kee="template1_20130102_030405" description="new_description" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml
new file mode 100644 (file)
index 0000000..2c056af
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
+</dataset>
\ No newline at end of file
index 623ed1fd453bc7e4dad17a78a1d1d49a02d1e188..6bead9e07e123e7767013e8064922746fe261e75 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <permission_templates id="1" name="my template" description="my description"/>
+  <permission_templates id="1" name="my template" kee="my_template_20130101_010203" description="my description"/>
 
   <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="codeviewer"/>
 
index 88a68afdb6becdfe157720077435d5436a30147a..8dd0f01000304c351c5641db512cd0819cfff594 100644 (file)
@@ -18,7 +18,7 @@
   <group_roles id="7" group_id="[null]" resource_id="123" role="codeviewer"/>
 
   <!-- default permission template for all qualifiers -->
-  <permission_templates id="1" name="default"/>
+  <permission_templates id="1" name="default" kee="default_template_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="101" permission_reference="user"/>
index fea38a879d875fe640492b83431b18c7738988f6..ad5e93d9eeb7664313a2e9b401e2b7ac8e8849c2 100644 (file)
@@ -10,7 +10,7 @@
 
 
   <!-- default permission template for all qualifiers -->
-  <permission_templates id="1" name="default"/>
+  <permission_templates id="1" name="default" kee="default_template_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="101" permission_reference="user"/>
index 3ef5580c464d9612afd6549de3fca87714aa2ba2..dac9bf9092981ef87f0541f1e3da43a4aa88dded 100644 (file)
@@ -10,7 +10,7 @@
 
 
   <!-- default permission template for all qualifiers -->
-  <permission_templates id="1" name="default"/>
+  <permission_templates id="1" name="default" kee="default_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="101" permission_reference="user"/>
@@ -20,7 +20,7 @@
 
 
   <!-- default permission template for TRK -->
-  <permission_templates id="2" name="default_for_TRK"/>
+  <permission_templates id="2" name="default_for_TRK" kee="default_for_trk_20130101_010203"/>
 
   <perm_templates_groups id="6" template_id="2" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="7" template_id="2" group_id="101" permission_reference="admin"/>
index 8158b9405356c2c986c9f00ea2512d405e89f4d4..1aa42985eab1b758df11e4ec57662d7ee1c27bba 100644 (file)
@@ -12,7 +12,7 @@
   <group_roles id="3" group_id="100" resource_id="123" role="admin"/>
 
   <!-- default permission template -->
-  <permission_templates id="1" name="default_template"/>
+  <permission_templates id="1" name="default_template" kee="default_template_20130101_010203"/>
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
 
 </dataset>
\ No newline at end of file
index 0c4dfd1ab47214fdee317d56e8fe677a2de5d691..bcf1ee02a0ea928c9de881aad6f8afa3a3b2d7db 100644 (file)
@@ -9,7 +9,7 @@
   <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
 
   <!-- default permission template for TRK -->
-  <permission_templates id="1" name="default_template"/>
+  <permission_templates id="1" name="default_template" kee="default_template_20130101_010203"/>
 
   <perm_templates_groups id="1" template_id="1" group_id="100" permission_reference="admin"/>
   <perm_templates_groups id="2" template_id="1" group_id="999" permission_reference="admin"/>
index 75c11a9834cb929331fbae2e6c7f4f619077b9e6..ca14596bafe84f01983442d17adbaba496b343af 100644 (file)
@@ -13,7 +13,7 @@
   <user_roles id="2" user_id="200" resource_id="123" role="admin"/>
 
   <!-- default permission template for TRK -->
-  <permission_templates id="1" name="default_for_TRK"/>
+  <permission_templates id="1" name="default_for_TRK" kee="default_for_trk_20130101_010203"/>
 
   <perm_templates_users id="1" template_id="1" user_id="200" permission_reference="admin"/>
   <perm_templates_users id="2" template_id="1" user_id="201" permission_reference="admin"/>
index 3f492a445121576eb0a0e02728340502913156cf..bef56d94ebe3d46ccef0e9041bb8ec02be758607 100644 (file)
@@ -10,7 +10,7 @@
   <user_roles id="1" user_id="200" resource_id="1" role="admin"/>
 
   <!-- default permission template for TRK -->
-  <permission_templates id="1" name="default_for_TRK"/>
+  <permission_templates id="1" name="default_for_TRK" kee="default_for_trk_20130101_010203"/>
 
   <perm_templates_users id="1" template_id="1" user_id="200" permission_reference="admin"/>
   <perm_templates_users id="2" template_id="1" user_id="201" permission_reference="admin"/>
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index ae1db0b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="new_permission"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml
deleted file mode 100644 (file)
index 34ffb7f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index 4fe3b43..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="[null]" permission_reference="new_permission"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml
deleted file mode 100644 (file)
index 34ffb7f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index 8676d56..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="new_permission"/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml
deleted file mode 100644 (file)
index 34ffb7f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml
deleted file mode 100644 (file)
index 4602891..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml
deleted file mode 100644 (file)
index 5ed00ba..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml
deleted file mode 100644 (file)
index df9b962..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="2" name="other template" description="other description" created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users/>
-
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml
deleted file mode 100644 (file)
index 61c4043..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="other template" description="other description" created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
-
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index 33773a8..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml
deleted file mode 100644 (file)
index 9df53ee..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
-  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index 52fd267..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml
deleted file mode 100644 (file)
index 3e3f933..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="2" template_id="1" group_id="[null]" permission_reference="permission_to_remove"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index 925a1b2..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
-
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml
deleted file mode 100644 (file)
index c160e4e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="permission_to_remove"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
-
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml
deleted file mode 100644 (file)
index fc6e8c1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="template1" description="description1" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" description="description2" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="3" name="template3" description="description3" created_at="[null]" updated_at="[null]"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml
deleted file mode 100644 (file)
index 1bc1f39..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description" created_at="[null]" updated_at="[null]"/>
-
-  <users id="1" login="user1" name="user1" />
-  <users id="2" login="user2" name="user2" />
-
-  <groups id="1" name="group1"/>
-  <groups id="2" name="group2"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml
deleted file mode 100644 (file)
index f869265..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" description="my description" created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
-
-  <users id="1" login="login1" name="user1" />
-  <users id="2" login="login2" name="user2" />
-
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
-  <!-- Anyone group -->
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
-  <!-- Unmatched group -->
-  <perm_templates_groups id="4" template_id="1" group_id="999999" permission_reference="group_permission2"/>
-
-  <groups id="1" name="group1"/>
-  <groups id="2" name="group2"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml
deleted file mode 100644 (file)
index c29fef8..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="new_name" description="new_description" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" description="description2" created_at="[null]" updated_at="[null]"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml
deleted file mode 100644 (file)
index ef9d2a2..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="template1" description="description1" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" description="description2" created_at="[null]" updated_at="[null]"/>
-</dataset>
\ No newline at end of file
index 51ba1b246ac01c431f5db7adbd194330b4ebde49..e46717848cb2c60746827392b94cce3cc847bc0b 100644 (file)
@@ -34,8 +34,8 @@ import org.sonar.core.issue.db.IssueFilterDao;
 import org.sonar.core.issue.db.IssueFilterDto;
 import org.sonar.core.issue.db.IssueFilterFavouriteDao;
 import org.sonar.core.issue.db.IssueFilterFavouriteDto;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.AuthorizationDao;
-import org.sonar.core.user.Permission;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -43,7 +43,6 @@ import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.user.UserSession;
 
 import javax.annotation.CheckForNull;
-
 import java.util.List;
 import java.util.Map;
 
index 825e4d66cd4af83499f7b924c8dddcb65a4316f8..162bd1111e0ac60d751555f08ef31f8f3cdd683c 100644 (file)
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.core.permission.ComponentPermissionFacade;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.*;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.user.UserSession;
index 306771b55ee94342ae4c337b418c270e5491bf7f..dee18cc0d7c7487a6a9cb2e3693553cb45f11eba 100644 (file)
@@ -25,8 +25,8 @@ import org.h2.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
-import org.sonar.core.user.PermissionDao;
-import org.sonar.core.user.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionDao;
+import org.sonar.core.permission.PermissionTemplateDto;
 import org.sonar.core.user.UserDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ServerErrorException;
index 02197715c7ae4cc851a56217169234e6596d10ee..92bee097d590af7b2e7e86b2d6ea4588551fa9ab 100644 (file)
@@ -21,7 +21,7 @@
 package org.sonar.server.permission;
 
 import org.apache.commons.lang.StringUtils;
-import org.sonar.core.user.Permission;
+import org.sonar.core.permission.Permission;
 import org.sonar.server.exceptions.BadRequestException;
 
 import java.util.Map;
index 20cd6888bcbceff5eafedc42f6433234880f30ab..a88bf35d11f71e4ff6cb63a74338e5e9145e907c 100644 (file)
@@ -23,9 +23,9 @@ package org.sonar.server.permission;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
-import org.sonar.core.user.PermissionTemplateDto;
-import org.sonar.core.user.PermissionTemplateGroupDto;
-import org.sonar.core.user.PermissionTemplateUserDto;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionTemplateGroupDto;
+import org.sonar.core.permission.PermissionTemplateUserDto;
 
 import javax.annotation.Nullable;
 import java.util.List;
index ace626614b17b741c30f68320676a46776c345a5..ff0716f1ab263bde9bdfc9ebbd1ff88ac11b8fae 100644 (file)
@@ -23,7 +23,12 @@ package org.sonar.server.permission;
 import com.google.common.collect.Lists;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.user.*;
+import org.sonar.core.permission.Permission;
+import org.sonar.core.permission.PermissionDao;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.user.GroupDto;
+import org.sonar.core.user.UserDao;
+import org.sonar.core.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.user.UserSession;
 
index b807e92952ff026c972f07bcbdb0a826bfde6a1a..799cf3f2b486bfc1512c5155f7b9fe4a8114dbdd 100644 (file)
@@ -25,13 +25,12 @@ import org.sonar.api.user.RubyUserService;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
 import org.sonar.api.user.UserQuery;
-import org.sonar.core.user.Permission;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.UserDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.util.RubyUtils;
 
 import javax.annotation.CheckForNull;
-
 import java.util.List;
 import java.util.Map;
 
index b51f71b0b47bc3bdf527a44b72f9e10420017caf..6f153d7c302a57cb4428b726f979b9663d647e7d 100644 (file)
@@ -23,15 +23,14 @@ import com.google.common.base.Objects;
 import com.google.common.base.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.AuthorizationDao;
-import org.sonar.core.user.Permission;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.platform.Platform;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
index 58ace28ff963fc9b406046e2667d6711b2b15015..cde3e9303068f84dc86671f1e64ecf6b608b0f2f 100644 (file)
@@ -26,6 +26,7 @@ class CreatePermissionTemplates < ActiveRecord::Migration
   def self.up
     create_table :permission_templates do |t|
       t.column :name,        :string,  :null => false,   :limit => 100
+      t.column :kee,         :string,  :null => false,   :limit => 100
       t.column :description, :string,  :null => true,    :limit => 4000
       t.column :created_at,  :datetime,  :null => true
       t.column :updated_at,  :datetime,  :null => true
index 0bac5e1a74b97339bae8ca415b8eba0a56670bdc..eab2f15d8dc90561f846747ded69d85c7c8471a7 100644 (file)
@@ -36,8 +36,8 @@ import org.sonar.core.issue.db.IssueFilterDao;
 import org.sonar.core.issue.db.IssueFilterDto;
 import org.sonar.core.issue.db.IssueFilterFavouriteDao;
 import org.sonar.core.issue.db.IssueFilterFavouriteDto;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.AuthorizationDao;
-import org.sonar.core.user.Permission;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
index 5112fe239cdc778893e371788b7020204d0a48b2..0f5d9a7af33c48e1e04498ddb82e6dcaa476661b 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.core.permission.ComponentPermissionFacade;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.*;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
index 49d9e10a76d8c29afb83274f184e3bc31ba7e715..9ddc5e31f095457a901751c2cb715ac864ade16b 100644 (file)
@@ -26,7 +26,10 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.user.*;
+import org.sonar.core.permission.*;
+import org.sonar.core.user.GroupDto;
+import org.sonar.core.user.UserDao;
+import org.sonar.core.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.user.MockUserSession;
 
index 148147b1408ee8404cef81a6389142d03969cfa1..02f98978fc48e16a7d44f2a7036d353b449049b1 100644 (file)
@@ -24,7 +24,7 @@ import com.google.common.collect.Maps;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.core.user.Permission;
+import org.sonar.core.permission.Permission;
 import org.sonar.server.exceptions.BadRequestException;
 
 import java.util.Map;
index db52030e3ccec8b2ad8b730797758b544307be65..69a11a8a2ca3136308f669f923c2e93dbe4be21b 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.server.permission;
 
 import com.google.common.collect.Lists;
 import org.junit.Test;
-import org.sonar.core.user.PermissionTemplateDto;
-import org.sonar.core.user.PermissionTemplateGroupDto;
-import org.sonar.core.user.PermissionTemplateUserDto;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionTemplateGroupDto;
+import org.sonar.core.permission.PermissionTemplateUserDto;
 
 import static org.fest.assertions.Assertions.assertThat;
 
index e2eda87c9327890e91a094677c5416f3f06e58a5..8a70b2f8c27bc78dffd41474948115ef860b9459 100644 (file)
@@ -25,7 +25,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.user.*;
+import org.sonar.core.permission.Permission;
+import org.sonar.core.permission.PermissionDao;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.user.GroupDto;
+import org.sonar.core.user.UserDao;
+import org.sonar.core.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
index 194de2234918b8aa8046a325f2b33373bd0fe319..df0e60b63cd9b6d4d048baeeaf70147f1158fe0b 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentMatcher;
 import org.sonar.api.user.UserFinder;
 import org.sonar.api.user.UserQuery;
-import org.sonar.core.user.Permission;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.UserDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -35,11 +35,7 @@ import org.sonar.server.exceptions.ForbiddenException;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.*;
 
 public class DefaultUserServiceTest {
 
index d7dd2de8cbdc174d49cac9eb3d746ca4e1557460..7e38dfe808c18b571ca448461e916af0f744a216 100644 (file)
  */
 package org.sonar.server.user;
 
-import org.sonar.core.user.Permission;
+import org.sonar.core.permission.Permission;
 
 import javax.annotation.Nullable;
-
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Locale;
index a5890d3d7e15d469007908555c271fb5197521ee..dcbfe23735a80ad265901c86a3490a514253bdd1 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.user;
 
 import org.junit.Test;
+import org.sonar.core.permission.Permission;
 import org.sonar.core.user.AuthorizationDao;
-import org.sonar.core.user.Permission;
 import org.sonar.server.exceptions.ForbiddenException;
 
 import java.util.Arrays;