aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-01-28 17:32:12 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-01 13:46:17 +0100
commit961911bf82fb9592fc6495b42a0dd3cbcfec2974 (patch)
tree94056c4580b68b2feac1679902f7df64d7c47b6d /sonar-db
parent9873d47828cb1e4c2142adcbd94583910a8055af (diff)
downloadsonarqube-961911bf82fb9592fc6495b42a0dd3cbcfec2974.tar.gz
sonarqube-961911bf82fb9592fc6495b42a0dd3cbcfec2974.zip
SONAR-7233 remove email / SCM accounts when deactivating a user
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DbClient.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/MyBatis.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java16
-rw-r--r--sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardMapper.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java14
-rw-r--r--sonar-db/src/main/java/org/sonar/db/issue/IssueFilterDao.java10
-rw-r--r--sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java8
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java14
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDao.java35
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDto.java65
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteMapper.java27
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterMapper.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/user/UserDto.java21
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/dashboard/ActiveDashboardMapper.xml13
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterFavouriteMapper.xml24
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml26
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml17
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/dashboard/ActiveDashboardDaoTest.java39
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java38
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java58
-rw-r--r--sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java188
-rw-r--r--sonar-db/src/test/java/org/sonar/db/user/UserTesting.java8
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user-result.xml45
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user.xml43
26 files changed, 588 insertions, 141 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DaoModule.java b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
index cc21f452c37..bedee4a4bb1 100644
--- a/sonar-db/src/main/java/org/sonar/db/DaoModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
@@ -47,6 +47,7 @@ import org.sonar.db.issue.IssueFilterFavouriteDao;
import org.sonar.db.loadedtemplate.LoadedTemplateDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.MeasureFilterDao;
+import org.sonar.db.measure.MeasureFilterFavouriteDao;
import org.sonar.db.measure.custom.CustomMeasureDao;
import org.sonar.db.metric.MetricDao;
import org.sonar.db.notification.NotificationQueueDao;
@@ -95,6 +96,7 @@ public class DaoModule extends Module {
LoadedTemplateDao.class,
MeasureDao.class,
MeasureFilterDao.class,
+ MeasureFilterFavouriteDao.class,
MetricDao.class,
NotificationQueueDao.class,
PermissionDao.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java
index 42cf7f6fc7a..be249d0e6be 100644
--- a/sonar-db/src/main/java/org/sonar/db/DbClient.java
+++ b/sonar-db/src/main/java/org/sonar/db/DbClient.java
@@ -47,6 +47,7 @@ import org.sonar.db.issue.IssueFilterFavouriteDao;
import org.sonar.db.loadedtemplate.LoadedTemplateDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.MeasureFilterDao;
+import org.sonar.db.measure.MeasureFilterFavouriteDao;
import org.sonar.db.measure.custom.CustomMeasureDao;
import org.sonar.db.metric.MetricDao;
import org.sonar.db.notification.NotificationQueueDao;
@@ -83,6 +84,7 @@ public class DbClient {
private final ResourceKeyUpdaterDao resourceKeyUpdaterDao;
private final MeasureDao measureDao;
private final MeasureFilterDao measureFilterDao;
+ private final MeasureFilterFavouriteDao measureFilterFavouriteDao;
private final ActivityDao activityDao;
private final AuthorizationDao authorizationDao;
private final UserDao userDao;
@@ -138,6 +140,7 @@ public class DbClient {
resourceKeyUpdaterDao = getDao(map, ResourceKeyUpdaterDao.class);
measureDao = getDao(map, MeasureDao.class);
measureFilterDao = getDao(map, MeasureFilterDao.class);
+ measureFilterFavouriteDao = getDao(map, MeasureFilterFavouriteDao.class);
activityDao = getDao(map, ActivityDao.class);
authorizationDao = getDao(map, AuthorizationDao.class);
userDao = getDao(map, UserDao.class);
@@ -250,6 +253,10 @@ public class DbClient {
return measureFilterDao;
}
+ public MeasureFilterFavouriteDao measureFilterFavouriteDao() {
+ return measureFilterFavouriteDao;
+ }
+
public ActivityDao activityDao() {
return activityDao;
}
diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
index 9cf94000504..5cf731bcd2f 100644
--- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java
+++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
@@ -80,6 +80,8 @@ import org.sonar.db.loadedtemplate.LoadedTemplateDto;
import org.sonar.db.loadedtemplate.LoadedTemplateMapper;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.MeasureFilterDto;
+import org.sonar.db.measure.MeasureFilterFavouriteDto;
+import org.sonar.db.measure.MeasureFilterFavouriteMapper;
import org.sonar.db.measure.MeasureFilterMapper;
import org.sonar.db.measure.MeasureMapper;
import org.sonar.db.measure.custom.CustomMeasureDto;
@@ -175,6 +177,7 @@ public class MyBatis {
confBuilder.loadAlias("GroupMembership", GroupMembershipDto.class);
confBuilder.loadAlias("LoadedTemplate", LoadedTemplateDto.class);
confBuilder.loadAlias("MeasureFilter", MeasureFilterDto.class);
+ confBuilder.loadAlias("MeasureFilterFavourite", MeasureFilterFavouriteDto.class);
confBuilder.loadAlias("NotificationQueue", NotificationQueueDto.class);
confBuilder.loadAlias("Property", PropertyDto.class);
confBuilder.loadAlias("PurgeableSnapshot", PurgeableSnapshotDto.class);
@@ -229,7 +232,7 @@ public class MyBatis {
DuplicationMapper.class,
IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
IsAliveMapper.class,
- LoadedTemplateMapper.class, MeasureFilterMapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
+ LoadedTemplateMapper.class, MeasureFilterMapper.class, MeasureFilterFavouriteMapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class,
SchemaMigrationMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
UserMapper.class, GroupMapper.class, UserGroupMapper.class, UserTokenMapper.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java
index 84274d52808..ed224870963 100644
--- a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java
@@ -20,9 +20,11 @@
package org.sonar.db.dashboard;
import java.util.List;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.ibatis.session.SqlSession;
import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
public class ActiveDashboardDao implements Dao {
@@ -33,16 +35,26 @@ public class ActiveDashboardDao implements Dao {
this.mybatis = mybatis;
}
+ public void insert(DbSession session, ActiveDashboardDto activeDashboardDto) {
+ mapper(session).insert(activeDashboardDto);
+ session.commit();
+ }
+
public void insert(ActiveDashboardDto activeDashboardDto) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
- mapper(session).insert(activeDashboardDto);
+ insert(session, activeDashboardDto);
session.commit();
} finally {
MyBatis.closeQuietly(session);
}
}
+ @CheckForNull
+ public ActiveDashboardDto selectById(DbSession session, long id){
+ return mapper(session).selectById(id);
+ }
+
public int selectMaxOrderIndexForNullUser() {
SqlSession session = mybatis.openSession(false);
try {
diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardMapper.java b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardMapper.java
index bb7e8eed792..d0f3d834ff5 100644
--- a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardMapper.java
@@ -28,6 +28,8 @@ public interface ActiveDashboardMapper {
void insert(ActiveDashboardDto activeDashboardDto);
+ ActiveDashboardDto selectById(long id);
+
@CheckForNull
Integer selectMaxOrderIndexForNullUser();
diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java
index bd32032f6c1..fd283b3d181 100644
--- a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java
@@ -44,12 +44,10 @@ public class DashboardDao implements Dao {
}
}
- public void insert(DashboardDto dashboardDto) {
- SqlSession session = mybatis.openSession(false);
+ public void insert(DbSession session, DashboardDto dashboardDto) {
DashboardMapper dashboardMapper = session.getMapper(DashboardMapper.class);
WidgetMapper widgetMapper = session.getMapper(WidgetMapper.class);
WidgetPropertyMapper widgetPropertyMapper = session.getMapper(WidgetPropertyMapper.class);
- try {
dashboardMapper.insert(dashboardDto);
for (WidgetDto widgetDto : dashboardDto.getWidgets()) {
widgetDto.setDashboardId(dashboardDto.getId());
@@ -59,6 +57,12 @@ public class DashboardDao implements Dao {
widgetPropertyMapper.insert(widgetPropertyDto);
}
}
+ }
+
+ public void insert(DashboardDto dashboardDto) {
+ DbSession session = mybatis.openSession(false);
+ try {
+ insert(session, dashboardDto);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -66,8 +70,8 @@ public class DashboardDao implements Dao {
}
@CheckForNull
- public DashboardDto selectByKey(DbSession session, Long key) {
- return mapper(session).selectById(key);
+ public DashboardDto selectById(DbSession session, long id) {
+ return mapper(session).selectById(id);
}
/**
diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterDao.java
index d672c9cbc52..fe8b4a08937 100644
--- a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterDao.java
@@ -35,11 +35,15 @@ public class IssueFilterDao implements Dao {
}
@CheckForNull
+ public IssueFilterDto selectById(DbSession session, long id) {
+ return mapper(session).selectById(id);
+ }
+
+ @CheckForNull
public IssueFilterDto selectById(long id) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
- session.getMapper(IssueFilterMapper.class);
- return mapper(session).selectById(id);
+ return selectById(session, id);
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java
index 4e7e84b2964..dcb92192a14 100644
--- a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java
@@ -33,10 +33,14 @@ public class IssueFilterFavouriteDao implements Dao {
this.mybatis = mybatis;
}
+ public IssueFilterFavouriteDto selectById(DbSession session, long id) {
+ return mapper(session).selectById(id);
+ }
+
public IssueFilterFavouriteDto selectById(long id) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
- return mapper(session).selectById(id);
+ return selectById(session, id);
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java
index 2744eb82931..6dbaaf1a45b 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java
@@ -21,6 +21,7 @@ package org.sonar.db.measure;
import org.apache.ibatis.session.SqlSession;
import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
public class MeasureFilterDao implements Dao {
@@ -40,11 +41,18 @@ public class MeasureFilterDao implements Dao {
}
}
+ public MeasureFilterDto selectById(DbSession session, long id){
+ return session.getMapper(MeasureFilterMapper.class).selectById(id);
+ }
+
+ public void insert(DbSession session, MeasureFilterDto filter) {
+ session.getMapper(MeasureFilterMapper.class).insert(filter);
+ }
+
public void insert(MeasureFilterDto filter) {
- SqlSession session = mybatis.openSession(false);
- MeasureFilterMapper mapper = session.getMapper(MeasureFilterMapper.class);
+ DbSession session = mybatis.openSession(false);
try {
- mapper.insert(filter);
+ insert(session, filter);
session.commit();
} finally {
MyBatis.closeQuietly(session);
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDao.java
new file mode 100644
index 00000000000..50f15b91878
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDao.java
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.measure;
+
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class MeasureFilterFavouriteDao implements Dao {
+
+ public MeasureFilterFavouriteDto selectById(DbSession session, long id) {
+ return session.getMapper(MeasureFilterFavouriteMapper.class).selectById(id);
+ }
+
+ public void insert(DbSession session, MeasureFilterFavouriteDto filter) {
+ session.getMapper(MeasureFilterFavouriteMapper.class).insert(filter);
+ }
+
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDto.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDto.java
new file mode 100644
index 00000000000..d7f0f8671cd
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteDto.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.measure;
+
+import java.util.Date;
+
+public class MeasureFilterFavouriteDto {
+ private Long id;
+ private Long userId;
+ private Long measureFilterId;
+ private Date createdAt;
+
+ public Long getId() {
+ return id;
+ }
+
+ public MeasureFilterFavouriteDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public MeasureFilterFavouriteDto setUserId(Long userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ public Long getMeasureFilterId() {
+ return measureFilterId;
+ }
+
+ public MeasureFilterFavouriteDto setMeasureFilterId(Long measureFilterId) {
+ this.measureFilterId = measureFilterId;
+ return this;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public MeasureFilterFavouriteDto setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteMapper.java
new file mode 100644
index 00000000000..2e00f07d8ea
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterFavouriteMapper.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.measure;
+
+public interface MeasureFilterFavouriteMapper {
+
+ MeasureFilterFavouriteDto selectById(long id);
+
+ void insert(MeasureFilterFavouriteDto filter);
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterMapper.java
index 062505e3eb5..ec5b5748c6d 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterMapper.java
@@ -25,5 +25,7 @@ package org.sonar.db.measure;
public interface MeasureFilterMapper {
MeasureFilterDto findSystemFilterByName(String name);
+ MeasureFilterDto selectById(long id);
+
void insert(MeasureFilterDto filter);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java
index a6983bf1638..3ab6379620c 100644
--- a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java
@@ -22,6 +22,7 @@ package org.sonar.db.user;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -44,6 +45,8 @@ public class UserDto {
private String externalIdentityProvider;
private String cryptedPassword;
private String salt;
+ private String rememberToken;
+ private Date rememberTokenExpiresAt;
private Long createdAt;
private Long updatedAt;
@@ -167,6 +170,24 @@ public class UserDto {
return this;
}
+ public String getRememberToken() {
+ return rememberToken;
+ }
+
+ public UserDto setRememberToken(String rememberToken) {
+ this.rememberToken = rememberToken;
+ return this;
+ }
+
+ public Date getRememberTokenExpiresAt() {
+ return rememberTokenExpiresAt;
+ }
+
+ public UserDto setRememberTokenExpiresAt(Date rememberTokenExpiresAt) {
+ this.rememberTokenExpiresAt = rememberTokenExpiresAt;
+ return this;
+ }
+
public Long getCreatedAt() {
return createdAt;
}
diff --git a/sonar-db/src/main/resources/org/sonar/db/dashboard/ActiveDashboardMapper.xml b/sonar-db/src/main/resources/org/sonar/db/dashboard/ActiveDashboardMapper.xml
index 6c88317e890..9261c1bbd18 100644
--- a/sonar-db/src/main/resources/org/sonar/db/dashboard/ActiveDashboardMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/dashboard/ActiveDashboardMapper.xml
@@ -3,11 +3,24 @@
<mapper namespace="org.sonar.db.dashboard.ActiveDashboardMapper">
+ <sql id="activeDashboardColumns">
+ ad.id,
+ ad.user_id as "userId",
+ ad.dashboard_id as "dashboardId",
+ ad.order_index as "orderIndex"
+ </sql>
+
<insert id="insert" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO active_dashboards (dashboard_id, user_id, order_index)
VALUES (#{dashboardId}, #{userId}, #{orderIndex})
</insert>
+ <select id="selectById" resultType="ActiveDashboard">
+ SELECT <include refid="activeDashboardColumns"/>
+ FROM active_dashboards ad
+ WHERE ad.id=#{id}
+ </select>
+
<select id="selectMaxOrderIndexForNullUser" resultType="Integer">
SELECT MAX(order_index)
FROM active_dashboards
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterFavouriteMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterFavouriteMapper.xml
new file mode 100644
index 00000000000..8e9a4a5f86f
--- /dev/null
+++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterFavouriteMapper.xml
@@ -0,0 +1,24 @@
+<?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.db.measure.MeasureFilterFavouriteMapper">
+
+ <sql id="measureFilterFavouriteColumns">
+ mff.id,
+ mff.user_id as "userId",
+ mff.measure_filter_id as "measureFilterId",
+ mff.created_at as "createdAt"
+ </sql>
+
+ <select id="selectById" parameterType="long" resultType="MeasureFilterFavourite">
+ SELECT <include refid="measureFilterFavouriteColumns"/>
+ FROM measure_filter_favourites mff
+ WHERE mff.id=#{id}
+ </select>
+
+ <insert id="insert" parameterType="MeasureFilterFavourite" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO measure_filter_favourites (user_id, measure_filter_id, created_at)
+ VALUES (#{userId,jdbcType=BIGINT}, #{measureFilterId,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP})
+ </insert>
+
+</mapper>
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml
index 85e85b3fa4e..63c9be3a27a 100644
--- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml
@@ -3,15 +3,33 @@
<mapper namespace="org.sonar.db.measure.MeasureFilterMapper">
+ <sql id="measureFilterColumns">
+ mf.id,
+ mf.name,
+ mf.user_id as "userId",
+ mf.shared,
+ mf.description,
+ mf.data,
+ mf.created_at as "createdAt",
+ mf.updated_at as "updatedAt"
+ </sql>
+
<select id="findSystemFilterByName" parameterType="string" resultType="MeasureFilter">
- select id, name, user_id as "userId", shared, description, data, created_at as "createdAt", updated_at as
- "updatedAt"
- from measure_filters WHERE user_id is null and name=#{id}
+ SELECT <include refid="measureFilterColumns"/>
+ FROM measure_filters mf
+ WHERE mf.user_id is null and mf.name=#{id}
+ </select>
+
+ <select id="selectById" parameterType="long" resultType="MeasureFilter">
+ SELECT <include refid="measureFilterColumns"/>
+ FROM measure_filters mf
+ WHERE mf.id=#{id}
</select>
<insert id="insert" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at)
- VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+ VALUES (#{name,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, #{shared,jdbcType=BOOLEAN}, #{description,jdbcType=VARCHAR}, #{data,jdbcType=VARCHAR},
+ #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP})
</insert>
</mapper>
diff --git a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml
index e60becc00e2..1e3eb253d42 100644
--- a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml
@@ -14,6 +14,8 @@
u.crypted_password as "cryptedPassword",
u.external_identity as "externalIdentity",
u.external_identity_provider as "externalIdentityProvider",
+ u.remember_token as "rememberToken",
+ u.remember_token_expires_at as "rememberTokenExpiresAt",
u.created_at as "createdAt",
u.updated_at as "updatedAt"
</sql>
@@ -137,21 +139,28 @@
</delete>
<update id="deactivateUser" parameterType="long">
- UPDATE users SET active=${_false}, updated_at=#{now,jdbcType=BIGINT} WHERE id=#{id}
+ UPDATE users SET active=${_false}, email=null, scm_accounts=null,
+ external_identity=null, external_identity_provider=null,
+ salt=null, crypted_password=null,
+ remember_token=null, remember_token_expires_at=null,
+ updated_at=#{now,jdbcType=BIGINT} WHERE id=#{id}
</update>
<insert id="insert" parameterType="User" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO users (login, name, email, active, scm_accounts, external_identity, external_identity_provider, salt, crypted_password, created_at, updated_at)
+ INSERT INTO users (login, name, email, active, scm_accounts, external_identity, external_identity_provider, salt, crypted_password,
+ remember_token, remember_token_expires_at, created_at, updated_at)
VALUES (#{login,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{active,jdbcType=BOOLEAN},
#{scmAccounts,jdbcType=VARCHAR}, #{externalIdentity,jdbcType=VARCHAR}, #{externalIdentityProvider,jdbcType=VARCHAR},
- #{salt,jdbcType=VARCHAR}, #{cryptedPassword,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT},
- #{updatedAt,jdbcType=BIGINT})
+ #{salt,jdbcType=VARCHAR}, #{cryptedPassword,jdbcType=VARCHAR},
+ #{rememberToken,jdbcType=VARCHAR}, #{rememberTokenExpiresAt,jdbcType=TIMESTAMP},
+ #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT})
</insert>
<insert id="update" parameterType="User" useGeneratedKeys="false">
UPDATE users set name=#{name,jdbcType=VARCHAR}, email=#{email,jdbcType=VARCHAR}, active=#{active,jdbcType=BOOLEAN},
scm_accounts=#{scmAccounts,jdbcType=VARCHAR}, external_identity=#{externalIdentity,jdbcType=VARCHAR}, external_identity_provider=#{externalIdentityProvider,jdbcType=VARCHAR},
salt=#{salt,jdbcType=VARCHAR}, crypted_password=#{cryptedPassword,jdbcType=BIGINT},
+ remember_token=#{rememberToken,jdbcType=VARCHAR}, remember_token_expires_at=#{rememberTokenExpiresAt,jdbcType=TIMESTAMP},
updated_at=#{updatedAt,jdbcType=BIGINT}
WHERE login = #{login}
</insert>
diff --git a/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java b/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java
index 61215aa8b3a..7e5f79e1d22 100644
--- a/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/DaoModuleTest.java
@@ -29,6 +29,6 @@ public class DaoModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new DaoModule().configure(container);
- assertThat(container.size()).isEqualTo(48);
+ assertThat(container.size()).isEqualTo(49);
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/dashboard/ActiveDashboardDaoTest.java b/sonar-db/src/test/java/org/sonar/db/dashboard/ActiveDashboardDaoTest.java
index 654cbf549e0..38d0d20bff9 100644
--- a/sonar-db/src/test/java/org/sonar/db/dashboard/ActiveDashboardDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/dashboard/ActiveDashboardDaoTest.java
@@ -23,6 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.test.DbTests;
@@ -34,7 +35,9 @@ public class ActiveDashboardDaoTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- ActiveDashboardDao dao = dbTester.getDbClient().activeDashboardDao();
+ DbSession session = dbTester.getSession();
+
+ ActiveDashboardDao underTest = dbTester.getDbClient().activeDashboardDao();
@Test
public void shouldInsert() {
@@ -44,7 +47,7 @@ public class ActiveDashboardDaoTest {
dashboard.setDashboardId(2L);
dashboard.setUserId(3L);
dashboard.setOrderIndex(4);
- dao.insert(dashboard);
+ underTest.insert(dashboard);
dbTester.assertDbUnit(getClass(), "shouldInsert-result.xml", "active_dashboards");
}
@@ -56,7 +59,7 @@ public class ActiveDashboardDaoTest {
ActiveDashboardDto dashboard = new ActiveDashboardDto();
dashboard.setDashboardId(2L);
dashboard.setOrderIndex(4);
- dao.insert(dashboard);
+ underTest.insert(dashboard);
dbTester.assertDbUnit(getClass(), "shouldInsertWithNoUser-result.xml", "active_dashboards");
}
@@ -65,7 +68,7 @@ public class ActiveDashboardDaoTest {
public void shouldGetMaxOrderIndexForNullUser() {
dbTester.prepareDbUnit(getClass(), "shouldGetMaxOrderIndexForNullUser.xml");
- int index = dao.selectMaxOrderIndexForNullUser();
+ int index = underTest.selectMaxOrderIndexForNullUser();
assertThat(index).isEqualTo(15);
}
@@ -74,7 +77,7 @@ public class ActiveDashboardDaoTest {
public void shouldGetZeroMaxOrderIndex() {
dbTester.prepareDbUnit(getClass(), "empty.xml");
- int index = dao.selectMaxOrderIndexForNullUser();
+ int index = underTest.selectMaxOrderIndexForNullUser();
assertThat(index).isZero();
}
@@ -83,27 +86,45 @@ public class ActiveDashboardDaoTest {
public void should_get_dashboards_for_anonymous() {
dbTester.prepareDbUnit(getClass(), "shouldSelectDashboardsForAnonymous.xml");
- assertThat(dao.selectGlobalDashboardsForUserLogin(null)).hasSize(2).extracting("id").containsExactly(2L, 1L);
+ assertThat(underTest.selectGlobalDashboardsForUserLogin(null)).hasSize(2).extracting("id").containsExactly(2L, 1L);
}
@Test
public void should_get_dashboards_for_user() {
dbTester.prepareDbUnit(getClass(), "shouldSelectDashboardsForUser.xml");
- assertThat(dao.selectGlobalDashboardsForUserLogin("obiwan")).hasSize(2).extracting("id").containsExactly(2L, 1L);
+ assertThat(underTest.selectGlobalDashboardsForUserLogin("obiwan")).hasSize(2).extracting("id").containsExactly(2L, 1L);
}
@Test
public void should_get_project_dashboards_for_anonymous() {
dbTester.prepareDbUnit(getClass(), "shouldSelectProjectDashboardsForAnonymous.xml");
- assertThat(dao.selectProjectDashboardsForUserLogin(null)).hasSize(2).extracting("id").containsExactly(2L, 1L);
+ assertThat(underTest.selectProjectDashboardsForUserLogin(null)).hasSize(2).extracting("id").containsExactly(2L, 1L);
}
@Test
public void should_get_project_dashboards_for_user() {
dbTester.prepareDbUnit(getClass(), "shouldSelectProjectDashboardsForUser.xml");
- assertThat(dao.selectProjectDashboardsForUserLogin("obiwan")).hasSize(2).extracting("id").containsExactly(2L, 1L);
+ assertThat(underTest.selectProjectDashboardsForUserLogin("obiwan")).hasSize(2).extracting("id").containsExactly(2L, 1L);
+ }
+
+ @Test
+ public void select_by_id() throws Exception {
+ ActiveDashboardDto dto = new ActiveDashboardDto()
+ .setDashboardId(10L)
+ .setOrderIndex(2)
+ .setUserId(5L);
+ underTest.insert(session, dto);
+ session.commit();
+
+ ActiveDashboardDto dtoReloaded = underTest.selectById(session, dto.getId());
+ assertThat(dtoReloaded).isNotNull();
+ assertThat(dtoReloaded.getDashboardId()).isEqualTo(10L);
+ assertThat(dtoReloaded.getUserId()).isEqualTo(5L);
+ assertThat(dtoReloaded.getOrderIndex()).isEqualTo(2);
+
+ assertThat(underTest.selectById(session, 123L)).isNull();
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java
index ebdc403bc38..f9bfd12ba0c 100644
--- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterDaoTest.java
@@ -19,9 +19,11 @@
*/
package org.sonar.db.measure;
+import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static org.assertj.core.api.Assertions.assertThat;
@@ -31,13 +33,15 @@ public class MeasureFilterDaoTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- MeasureFilterDao dao = db.getDbClient().measureFilterDao();
+ DbSession session = db.getSession();
+
+ MeasureFilterDao underTest = db.getDbClient().measureFilterDao();
@Test
public void should_find_filter() {
db.prepareDbUnit(getClass(), "shared.xml");
- MeasureFilterDto filter = dao.selectSystemFilterByName("Projects");
+ MeasureFilterDto filter = underTest.selectSystemFilterByName("Projects");
assertThat(filter.getId()).isEqualTo(1L);
assertThat(filter.getName()).isEqualTo("Projects");
@@ -47,7 +51,33 @@ public class MeasureFilterDaoTest {
public void should_not_find_filter() {
db.prepareDbUnit(getClass(), "shared.xml");
- assertThat(dao.selectSystemFilterByName("Unknown")).isNull();
+ assertThat(underTest.selectSystemFilterByName("Unknown")).isNull();
+ }
+
+ @Test
+ public void select_by_id() throws Exception {
+ MeasureFilterDto dto = new MeasureFilterDto()
+ .setUserId(10L)
+ .setName("name")
+ .setDescription("description")
+ .setData("data")
+ .setShared(true)
+ .setCreatedAt(new Date(1000L))
+ .setUpdatedAt(new Date(2000L));
+ underTest.insert(session, dto);
+ session.commit();
+
+ MeasureFilterDto dtoReloded = underTest.selectById(session, dto.getId());
+ assertThat(dtoReloded).isNotNull();
+ assertThat(dtoReloded.getUserId()).isEqualTo(10L);
+ assertThat(dtoReloded.getName()).isEqualTo("name");
+ assertThat(dtoReloded.getDescription()).isEqualTo("description");
+ assertThat(dtoReloded.getData()).isEqualTo("data");
+ assertThat(dtoReloded.isShared()).isTrue();
+ assertThat(dtoReloded.getCreatedAt()).isEqualTo(new Date(1000L));
+ assertThat(dtoReloded.getUpdatedAt()).isEqualTo(new Date(2000L));
+
+ assertThat(underTest.selectById(session, 123L)).isNull();
}
@Test
@@ -61,7 +91,7 @@ public class MeasureFilterDaoTest {
filterDto.setDescription("Treemap of projects");
filterDto.setData("qualifiers=TRK|display=treemap");
- dao.insert(filterDto);
+ underTest.insert(filterDto);
db.assertDbUnit(getClass(), "shouldInsert-result.xml", new String[]{"created_at", "updated_at"}, "measure_filters");
}
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java
new file mode 100644
index 00000000000..41402810c3a
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureFilterFavouriteDaoTest.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.measure;
+
+import java.util.Date;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MeasureFilterFavouriteDaoTest {
+
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+
+ DbSession session = db.getSession();
+
+ MeasureFilterFavouriteDao underTest = db.getDbClient().measureFilterFavouriteDao();
+
+ @Test
+ public void insert_and_select_by_id() throws Exception {
+ MeasureFilterFavouriteDto dto = new MeasureFilterFavouriteDto()
+ .setMeasureFilterId(5L)
+ .setUserId(10L)
+ .setCreatedAt(new Date(1000L));
+ underTest.insert(session, dto);
+ session.commit();
+
+ MeasureFilterFavouriteDto dtoReloaded = underTest.selectById(session, dto.getId());
+ assertThat(dtoReloaded).isNotNull();
+ assertThat(dtoReloaded.getMeasureFilterId()).isEqualTo(5L);
+ assertThat(dtoReloaded.getUserId()).isEqualTo(10L);
+ assertThat(dtoReloaded.getCreatedAt()).isEqualTo(new Date(1000L));
+
+ assertThat(underTest.selectById(session, 123L)).isNull();
+ }
+
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java
index a61b3b960e5..68181403823 100644
--- a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java
@@ -21,7 +21,9 @@ package org.sonar.db.user;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -29,16 +31,28 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.user.UserQuery;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
+import org.sonar.db.dashboard.ActiveDashboardDto;
+import org.sonar.db.dashboard.DashboardDto;
+import org.sonar.db.issue.IssueFilterDto;
+import org.sonar.db.issue.IssueFilterFavouriteDto;
+import org.sonar.db.measure.MeasureFilterDto;
+import org.sonar.db.measure.MeasureFilterFavouriteDto;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.db.property.PropertyQuery;
import org.sonar.test.DbTests;
import static java.util.Arrays.asList;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.db.user.GroupMembershipQuery.IN;
+import static org.sonar.db.user.GroupMembershipQuery.builder;
@Category(DbTests.class)
public class UserDaoTest {
@@ -51,9 +65,18 @@ public class UserDaoTest {
@Rule
public DbTester db = DbTester.create(system2);
+ static final long NOW = 1500000000000L;
+
+ DbClient dbClient = db.getDbClient();
+
UserDao underTest = db.getDbClient().userDao();
DbSession session = db.getSession();
+ @Before
+ public void setUp() throws Exception {
+ when(system2.now()).thenReturn(NOW);
+ }
+
@Test
public void selectUserByLogin_ignore_inactive() {
db.prepareDbUnit(getClass(), "selectActiveUserByLogin.xml");
@@ -166,6 +189,8 @@ public class UserDaoTest {
.setCryptedPassword("abcd")
.setExternalIdentity("johngithub")
.setExternalIdentityProvider("github")
+ .setRememberToken("1234")
+ .setRememberTokenExpiresAt(new Date())
.setCreatedAt(date)
.setUpdatedAt(date);
underTest.insert(db.getSession(), userDto);
@@ -183,6 +208,8 @@ public class UserDaoTest {
assertThat(user.getCryptedPassword()).isEqualTo("abcd");
assertThat(user.getExternalIdentity()).isEqualTo("johngithub");
assertThat(user.getExternalIdentityProvider()).isEqualTo("github");
+ assertThat(user.getRememberToken()).isEqualTo("1234");
+ assertThat(user.getRememberTokenExpiresAt()).isNotNull();
assertThat(user.getCreatedAt()).isEqualTo(date);
assertThat(user.getUpdatedAt()).isEqualTo(date);
}
@@ -225,31 +252,100 @@ public class UserDaoTest {
}
@Test
- public void deactivate_user() {
- db.prepareDbUnit(getClass(), "deactivate_user.xml");
+ public void deactivate_user() throws Exception {
+ UserDto user = newActiveUser();
+ DashboardDto dashboard = newDashboard(user, false);
+ ActiveDashboardDto activeDashboard = newActiveDashboard(dashboard, user);
+ IssueFilterDto issueFilter = newIssueFilter(user, false);
+ IssueFilterFavouriteDto issueFilterFavourite = newIssueFilterFavourite(issueFilter, user);
+ MeasureFilterDto measureFilter = newMeasureFilter(user, false);
+ MeasureFilterFavouriteDto measureFilterFavourite = newMeasureFilterFavourite(measureFilter, user);
+ PropertyDto property = newProperty(user);
+ newUserRole(user);
+ newUserGroup(user);
+
+ UserDto otherUser = newActiveUser();
+
+ session.commit();
+
+ boolean deactivated = underTest.deactivateUserByLogin(session, user.getLogin());
+ assertThat(deactivated).isTrue();
- when(system2.now()).thenReturn(1500000000000L);
+ UserDto userReloaded = underTest.selectUserById(session, user.getId());
+ assertThat(userReloaded.isActive()).isFalse();
+ assertThat(userReloaded.getEmail()).isNull();
+ assertThat(userReloaded.getScmAccounts()).isNull();
+ assertThat(userReloaded.getSalt()).isNull();
+ assertThat(userReloaded.getCryptedPassword()).isNull();
+ assertThat(userReloaded.getExternalIdentity()).isNull();
+ assertThat(userReloaded.getExternalIdentityProvider()).isNull();
+ assertThat(userReloaded.getRememberToken()).isNull();
+ assertThat(userReloaded.getRememberTokenExpiresAt()).isNull();
+ assertThat(userReloaded.getUpdatedAt()).isEqualTo(NOW);
+
+ assertThat(underTest.selectUserById(session, otherUser.getId())).isNotNull();
+
+ assertThat(dbClient.dashboardDao().selectById(session, dashboard.getId())).isNull();
+ assertThat(dbClient.activeDashboardDao().selectById(session, activeDashboard.getId())).isNull();
+ assertThat(dbClient.issueFilterDao().selectById(session, issueFilter.getId())).isNull();
+ assertThat(dbClient.issueFilterFavouriteDao().selectById(session, issueFilterFavourite.getId())).isNull();
+ assertThat(dbClient.measureFilterDao().selectById(session, measureFilter.getId())).isNull();
+ assertThat(dbClient.measureFilterFavouriteDao().selectById(session, measureFilterFavourite.getId())).isNull();
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(property.getKey()).build(), session)).isEmpty();
+ assertThat(dbClient.roleDao().selectUserPermissions(session, user.getLogin(), null)).isEmpty();
+ assertThat(dbClient.groupMembershipDao().countGroups(session, builder().login(user.getLogin()).membership(IN).build(), user.getId())).isZero();
+ }
- String login = "marius";
- boolean deactivated = underTest.deactivateUserByLogin(session, login);
+ @Test
+ public void deactivate_user_does_not_remove_shared_dashboard() throws Exception {
+ UserDto user = newActiveUser();
+ DashboardDto notSharedDashboard = newDashboard(user, false);
+ DashboardDto sharedDashboard = newDashboard(user, true);
+ session.commit();
+
+ boolean deactivated = underTest.deactivateUserByLogin(session, user.getLogin());
assertThat(deactivated).isTrue();
- assertThat(underTest.selectActiveUserByLogin(login)).isNull();
+ assertThat(dbClient.dashboardDao().selectById(session, notSharedDashboard.getId())).isNull();
+ DashboardDto sharedDashboardReloaded = dbClient.dashboardDao().selectById(session, sharedDashboard.getId());
+ assertThat(sharedDashboardReloaded).isNotNull();
+ assertThat(sharedDashboardReloaded.getUserId()).isEqualTo(user.getId());
+ }
- UserDto userDto = underTest.selectUserById(100);
- assertThat(userDto.isActive()).isFalse();
- assertThat(userDto.getUpdatedAt()).isEqualTo(1500000000000L);
+ @Test
+ public void deactivate_user_does_not_remove_shared_issue_filter() throws Exception {
+ UserDto user = newActiveUser();
+ IssueFilterDto notSharedFilter = newIssueFilter(user, false);
+ IssueFilterDto sharedFilter = newIssueFilter(user, true);
+ session.commit();
+
+ boolean deactivated = underTest.deactivateUserByLogin(session, user.getLogin());
+ assertThat(deactivated).isTrue();
- db.assertDbUnit(getClass(), "deactivate_user-result.xml",
- "dashboards", "active_dashboards", "groups_users", "issue_filters",
- "issue_filter_favourites", "measure_filters", "measure_filter_favourites",
- "properties", "user_roles");
+ assertThat(dbClient.issueFilterDao().selectById(session, notSharedFilter.getId())).isNull();
+ IssueFilterDto sharedFilterReloaded = dbClient.issueFilterDao().selectById(session, sharedFilter.getId());
+ assertThat(sharedFilterReloaded).isNotNull();
+ assertThat(sharedFilterReloaded.getUserLogin()).isEqualTo(user.getLogin());
}
@Test
- public void deactivate_missing_user() {
- db.prepareDbUnit(getClass(), "deactivate_user.xml");
+ public void deactivate_user_does_not_remove_shared_measure_filter() throws Exception {
+ UserDto user = newActiveUser();
+ MeasureFilterDto notSharedFilter = newMeasureFilter(user, false);
+ MeasureFilterDto sharedFilter = newMeasureFilter(user, true);
+ session.commit();
+
+ boolean deactivated = underTest.deactivateUserByLogin(session, user.getLogin());
+ assertThat(deactivated).isTrue();
+
+ assertThat(dbClient.measureFilterDao().selectById(session, notSharedFilter.getId())).isNull();
+ MeasureFilterDto sharedFilterReloaded = dbClient.measureFilterDao().selectById(session, sharedFilter.getId());
+ assertThat(sharedFilterReloaded).isNotNull();
+ assertThat(sharedFilterReloaded.getUserId()).isEqualTo(user.getId());
+ }
+ @Test
+ public void deactivate_missing_user() {
String login = "does_not_exist";
boolean deactivated = underTest.deactivateUserByLogin(session, login);
assertThat(deactivated).isFalse();
@@ -336,4 +432,66 @@ public class UserDaoTest {
assertThat(underTest.doesEmailExist(session, "unknown")).isFalse();
}
+ private UserDto newActiveUser(){
+ UserDto dto = UserTesting.newUserDto().setActive(true);
+ underTest.insert(session, dto);
+ return dto;
+ }
+
+ private DashboardDto newDashboard(UserDto user, boolean shared){
+ DashboardDto dto = new DashboardDto().setUserId(user.getId()).setShared(shared);
+ dbClient.dashboardDao().insert(session, dto);
+ return dto;
+ }
+
+ private ActiveDashboardDto newActiveDashboard(DashboardDto dashboard, UserDto user){
+ ActiveDashboardDto dto = new ActiveDashboardDto().setDashboardId(dashboard.getId()).setUserId(user.getId());
+ dbClient.activeDashboardDao().insert(session, dto);
+ return dto;
+ }
+
+ private IssueFilterDto newIssueFilter(UserDto user, boolean shared){
+ IssueFilterDto dto = new IssueFilterDto().setUserLogin(user.getLogin()).setName(randomAlphanumeric(100)).setShared(shared);
+ dbClient.issueFilterDao().insert(session, dto);
+ return dto;
+ }
+
+ private IssueFilterFavouriteDto newIssueFilterFavourite(IssueFilterDto filter, UserDto user){
+ IssueFilterFavouriteDto dto = new IssueFilterFavouriteDto().setUserLogin(user.getLogin()).setIssueFilterId(filter.getId());
+ dbClient.issueFilterFavouriteDao().insert(session, dto);
+ return dto;
+ }
+
+ private MeasureFilterDto newMeasureFilter(UserDto user, boolean shared){
+ MeasureFilterDto dto = new MeasureFilterDto().setUserId(user.getId()).setName(randomAlphanumeric(100)).setShared(shared);
+ dbClient.measureFilterDao().insert(session, dto);
+ return dto;
+ }
+
+ private MeasureFilterFavouriteDto newMeasureFilterFavourite(MeasureFilterDto measureFilter, UserDto user){
+ MeasureFilterFavouriteDto dto = new MeasureFilterFavouriteDto().setUserId(user.getId()).setMeasureFilterId(measureFilter.getId());
+ dbClient.measureFilterFavouriteDao().insert(session, dto);
+ return dto;
+ }
+
+ private PropertyDto newProperty(UserDto user){
+ PropertyDto dto = new PropertyDto().setKey(randomAlphanumeric(100)).setUserId(user.getId());
+ dbClient.propertiesDao().insertProperty(session, dto);
+ return dto;
+ }
+
+ private UserRoleDto newUserRole(UserDto user){
+ UserRoleDto dto = new UserRoleDto().setUserId(user.getId()).setRole(randomAlphanumeric(64));
+ dbClient.roleDao().insertUserRole(session, dto);
+ return dto;
+ }
+
+ private UserGroupDto newUserGroup(UserDto user){
+ GroupDto group = new GroupDto().setName(randomAlphanumeric(30));
+ dbClient.groupDao().insert(session, group);
+
+ UserGroupDto dto = new UserGroupDto().setUserId(user.getId()).setGroupId(group.getId());
+ dbClient.userGroupDao().insert(session, dto);
+ return dto;
+ }
}
diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java
index 034e623e756..5ac74c42025 100644
--- a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java
@@ -19,7 +19,10 @@
*/
package org.sonar.db.user;
+import java.util.Date;
+
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.apache.commons.lang.math.RandomUtils.nextLong;
public class UserTesting {
@@ -34,8 +37,13 @@ public class UserTesting {
.setName(name)
.setEmail(email)
.setLogin(login)
+ .setScmAccounts(randomAlphanumeric(40))
.setExternalIdentity(login)
.setExternalIdentityProvider("sonarqube")
+ .setRememberToken(randomAlphanumeric(500))
+ .setRememberTokenExpiresAt(new Date((long)nextInt()))
+ .setSalt(randomAlphanumeric(40))
+ .setCryptedPassword(randomAlphanumeric(40))
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
}
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user-result.xml
deleted file mode 100644
index 60e55e6494f..00000000000
--- a/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user-result.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<dataset>
- <!-- deactivated -->
- <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482"
- updated_at="1500000000000" active="[false]"/>
-
- <!-- deleted
- <dashboards id="1" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
- <active_dashboards id="1" user_id="100" dashboard_id="1" ORDER_INDEX="[null]"/>
- <issue_filters id="1" user_login="marius" name="My issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
- <issue_filter_favourites id="1" user_login="marius" issue_filter_id="1" CREATED_AT="[null]"/>
- <measure_filters id="1" user_id="100" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
- <measure_filter_favourites id="1" user_id="100" measure_filter_id="1" CREATED_AT="[null]"/>
- <properties id="1" user_id="100" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]" />
- <groups_users user_id="100" group_id="200"/>
- <user_roles id="1" user_id="100" role="admin" RESOURCE_ID="[null]"/>
- -->
-
- <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482"
- updated_at="1418215735485" active="[true]"/>
- <dashboards id="2" user_id="101" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]"
- IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
- <active_dashboards id="2" user_id="101" dashboard_id="2" ORDER_INDEX="[null]"/>
- <active_dashboards id="4" user_id="101" dashboard_id="3" ORDER_INDEX="[null]"/>
- <issue_filters id="2" user_login="jcdus" name="My issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <issue_filter_favourites id="2" user_login="jcdus" issue_filter_id="2" CREATED_AT="[null]"/>
- <issue_filter_favourites id="4" user_login="jcdus" issue_filter_id="3" CREATED_AT="[null]"/>
- <measure_filters id="2" user_id="101" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <measure_filter_favourites id="2" user_id="101" measure_filter_id="2" CREATED_AT="[null]"/>
- <measure_filter_favourites id="4" user_id="101" measure_filter_id="3" CREATED_AT="[null]"/>
- <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
- <groups_users user_id="101" group_id="200"/>
- <user_roles id="2" user_id="101" role="admin" RESOURCE_ID="[null]"/>
-
- <!-- Not deleted because shared -->
- <dashboards id="3" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]"
- IS_GLOBAL="[false]" SHARED="[true]" UPDATED_AT="[null]"/>
- <issue_filters id="3" user_login="marius" name="My shared issues" CREATED_AT="[null]" DATA="[null]"
- DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
- <measure_filters id="3" user_id="100" name="My shared measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[true]" UPDATED_AT="[null]"/>
-
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user.xml
deleted file mode 100644
index 804838dfa2a..00000000000
--- a/sonar-db/src/test/resources/org/sonar/db/user/UserDaoTest/deactivate_user.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<dataset>
- <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482"
- updated_at="1418215735485" active="[true]"/>
- <dashboards id="1" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]"
- IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
- <dashboards id="3" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]"
- IS_GLOBAL="[false]" SHARED="[true]" UPDATED_AT="[null]"/>
- <active_dashboards id="1" user_id="100" dashboard_id="1" ORDER_INDEX="[null]"/>
- <active_dashboards id="3" user_id="100" dashboard_id="3" ORDER_INDEX="[null]"/>
- <issue_filters id="1" user_login="marius" name="My issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <issue_filters id="3" user_login="marius" name="My shared issues" CREATED_AT="[null]" DATA="[null]"
- DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
- <issue_filter_favourites id="1" user_login="marius" issue_filter_id="1" CREATED_AT="[null]"/>
- <issue_filter_favourites id="3" user_login="marius" issue_filter_id="3" CREATED_AT="[null]"/>
- <measure_filters id="1" user_id="100" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <measure_filters id="3" user_id="100" name="My shared measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[true]" UPDATED_AT="[null]"/>
- <measure_filter_favourites id="1" user_id="100" measure_filter_id="1" CREATED_AT="[null]"/>
- <measure_filter_favourites id="3" user_id="100" measure_filter_id="3" CREATED_AT="[null]"/>
- <properties id="1" user_id="100" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
- <groups_users user_id="100" group_id="200"/>
- <user_roles id="1" user_id="100" role="admin" RESOURCE_ID="[null]"/>
-
- <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482"
- updated_at="1418215735485" active="[true]"/>
- <dashboards id="2" user_id="101" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]"
- IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
- <active_dashboards id="2" user_id="101" dashboard_id="2" ORDER_INDEX="[null]"/>
- <active_dashboards id="4" user_id="101" dashboard_id="3" ORDER_INDEX="[null]"/>
- <issue_filters id="2" user_login="jcdus" name="My issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <issue_filter_favourites id="2" user_login="jcdus" issue_filter_id="2" CREATED_AT="[null]"/>
- <issue_filter_favourites id="4" user_login="jcdus" issue_filter_id="3" CREATED_AT="[null]"/>
- <measure_filters id="2" user_id="101" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]"
- SHARED="[false]" UPDATED_AT="[null]"/>
- <measure_filter_favourites id="2" user_id="101" measure_filter_id="2" CREATED_AT="[null]"/>
- <measure_filter_favourites id="4" user_id="101" measure_filter_id="3" CREATED_AT="[null]"/>
- <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
- <groups_users user_id="101" group_id="200"/>
- <user_roles id="2" user_id="101" role="admin" RESOURCE_ID="[null]"/>
-</dataset>