aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-20 17:54:57 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-24 10:09:53 +0200
commitbb85616bc47bdc6ea6e067c61adc6d99c55cf5af (patch)
treed03052f2567c67725d05f8285e90b44f54951c67 /sonar-db
parent3973b44730a0420b9c3094dd52478ac18057eb02 (diff)
downloadsonarqube-bb85616bc47bdc6ea6e067c61adc6d99c55cf5af.tar.gz
sonarqube-bb85616bc47bdc6ea6e067c61adc6d99c55cf5af.zip
SONAR-6500 WS permissions/add_user_to_template add a user to a permission template
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java23
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java37
2 files changed, 53 insertions, 7 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
index 8a23ed1562f..eb084a0de38 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
@@ -218,20 +218,29 @@ public class PermissionTemplateDao implements Dao {
}
}
+ /**
+ * @deprecated since 5.2 use the method with dbSession instead
+ */
+ @Deprecated
public void insertUserPermission(Long templateId, Long userId, String permission) {
+ DbSession session = myBatis.openSession(false);
+ try {
+ insertUserPermission(session, templateId, userId, permission);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insertUserPermission(DbSession session, Long templateId, Long userId, String permission) {
PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
.setTemplateId(templateId)
.setUserId(userId)
.setPermission(permission)
.setCreatedAt(now())
.setUpdatedAt(now());
- SqlSession session = myBatis.openSession(false);
- try {
- mapper(session).insertUserPermission(permissionTemplateUser);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
+
+ mapper(session).insertUserPermission(permissionTemplateUser);
+ session.commit();
}
public void deleteUserPermission(Long templateId, Long userId, String permission) {
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java
new file mode 100644
index 00000000000..412537ded13
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.db.permission;
+
+import java.util.Date;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.RandomStringUtils.randomAscii;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
+
+public class PermissionTemplateTesting {
+ public static PermissionTemplateDto newPermissionTemplateDto() {
+ return new PermissionTemplateDto()
+ .setName(randomAlphanumeric(60))
+ .setDescription(randomAscii(500))
+ .setCreatedAt(new Date(nextLong()))
+ .setUpdatedAt(new Date(nextLong()));
+ }
+}