--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
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;
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;
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;
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+<?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>
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');
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
+++ /dev/null
-<?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>
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;
--- /dev/null
+/*
+ * 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");
+ }
+}
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;
+++ /dev/null
-/*
- * 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");
- }
-}
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;
<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"/>
<!-- 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"/>
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<dataset></dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset></dataset>
\ No newline at end of file
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
<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"/>
<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"/>
<!-- 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"/>
<!-- 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"/>
<!-- 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"/>
<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
<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"/>
<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"/>
<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"/>
+++ /dev/null
-<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
+++ /dev/null
-<dataset>
- <permission_templates id="1" name="my template" description="my description"/>
- <perm_templates_users/>
- <perm_templates_groups/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<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
+++ /dev/null
-<dataset>
- <permission_templates id="1" name="my template" description="my description"/>
- <perm_templates_users/>
- <perm_templates_groups/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<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
+++ /dev/null
-<dataset>
- <permission_templates id="1" name="my template" description="my description"/>
- <perm_templates_users/>
- <perm_templates_groups/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <permission_templates id="1" name="my template" description="my description"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset></dataset>
\ No newline at end of file
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
+++ /dev/null
-<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
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;
import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
-
import java.util.List;
import java.util.Map;
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;
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;
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;
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;
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;
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;
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;
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
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;
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;
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;
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;
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;
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;
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;
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 {
*/
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;
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;