]> source.dussan.org Git - sonarqube.git/blob
9181c55b5252ee9cc16762a391437c6fa59e6e2c
[sonarqube.git] /
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
3
4 <mapper namespace="org.sonar.db.qualitygate.QualityGateUserPermissionsMapper">
5
6   <sql id="sqlColumns">
7     qup.uuid as "uuid",
8     qup.user_uuid as "userUuid",
9     qup.quality_gate_uuid as "qualityGateUuid"
10   </sql>
11
12   <select id="selectByQualityGateAndUser" parameterType="String" resultType="org.sonar.db.qualitygate.QualityGateUserPermissionsDto">
13     select
14     <include refid="sqlColumns"/>
15     from qgate_user_permissions qup
16     where
17     qup.user_uuid = #{userUuid}
18     and qup.quality_gate_uuid = #{qualityGateUuid}
19   </select>
20
21   <insert id="insert" useGeneratedKeys="false" parameterType="map">
22     insert into qgate_user_permissions(
23     uuid,
24     user_uuid,
25     quality_gate_uuid,
26     created_at
27     ) values (
28     #{dto.uuid, jdbcType=VARCHAR},
29     #{dto.userUuid, jdbcType=VARCHAR},
30     #{dto.qualityGateUuid, jdbcType=VARCHAR},
31     #{now, jdbcType=BIGINT}
32     )
33   </insert>
34
35   <select id="countByQuery" resultType="int">
36     select count(u.uuid)
37     <include refid="sqlSelectByQuery"/>
38   </select>
39
40   <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchUserMembershipDto">
41     SELECT u.uuid as userUuid, u.name as name, qup.uuid as uuid
42     <include refid="sqlSelectByQuery"/>
43     ORDER BY u.name ASC
44     offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
45   </select>
46
47   <sql id="sqlSelectByQuery">
48     FROM users u
49     LEFT JOIN qgate_user_permissions qup ON qup.user_uuid=u.uuid AND
50     qup.quality_gate_uuid=#{query.qualityGateUuid, jdbcType=VARCHAR}
51     <where>
52       <choose>
53         <when test="query.getMembership() == 'IN'">
54           AND qup.uuid IS NOT NULL
55         </when>
56         <when test="query.getMembership() == 'OUT'">
57           AND qup.uuid IS NULL
58         </when>
59       </choose>
60       <if test="query.getQuery() != null">
61         AND (
62         lower(u.name) like #{query.querySqlLowercase} ESCAPE '/'
63         or u.login like #{query.querySql} ESCAPE '/')
64       </if>
65       AND u.active=${_true}
66     </where>
67   </sql>
68
69   <delete id="delete">
70     delete from qgate_user_permissions
71     where quality_gate_uuid = #{qualityGateUuid}
72     and user_uuid = #{userUuid}
73   </delete>
74
75   <delete id="deleteByUser">
76     delete from qgate_user_permissions
77     where user_uuid = #{userUuid}
78   </delete>
79
80   <delete id="deleteByQualityGate">
81     delete from qgate_user_permissions
82     where quality_gate_uuid = #{qualityGateUuid, jdbcType=VARCHAR}
83   </delete>
84
85 </mapper>
86