Kaynağa Gözat

1.user sesuai role masuk bug dia sendiri
2.role hanya bisa masuk sesuai role nya
3.time dikeluarin
4.role lebih dari satu

athrainsky 11 ay önce
ebeveyn
işleme
37b6e10c01

+ 1 - 1
qc.txt

@@ -9,7 +9,7 @@ owner
 - owner dapat menambah dan menghapus comment
 - owner dapat menambah, mengubah dan menghapus bug
 
-developer
+programmer
 - dev dapat mengubah dev_status di bug
 - dev dapat menambah comment
 

+ 43 - 32
src/main/kotlin/com/swagger/rest/controllers/BugController.kt

@@ -100,8 +100,8 @@ class BugController(
                 val output = bugs.map {
                     BugOutput(
                         id = it.id,
-                        created = SimpleDateFormat("dd-MM-yyyy").format(it.created),
-                        description = it.description.trim(),
+                        created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
+                        description = it.description,
                         qc = it.qc!!.name,
                         dev = it.dev!!.name,
                         platform = it.platform!!.name,
@@ -136,8 +136,8 @@ class BugController(
         val output = bugData.map {
             BugOutput(
                 id = it.id,
-                created = SimpleDateFormat("dd-MM-yyyy").format(it.created),
-                description = it.description.trim(),
+                created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
+                description = it.description,
                 qc = it.qc!!.name,
                 dev = it.dev!!.name,
                 platform = it.platform!!.name,
@@ -166,18 +166,20 @@ class BugController(
             val found = bugRepository.count(specBug)
             val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
             val countPlat = platformRepository.findPlatform2(userId.id.toString(), bugInput.platform)
-            val countQc = userRepository.findById(bugInput.qc)
-            val countDev = userRepository.findById(bugInput.dev)
+            val countQc = memberRepository.validRoleByPlatform(bugInput.qc.toString(), bugInput.platform, 0.toString())
+            val countDev = memberRepository.validRoleByPlatform(bugInput.dev.toString(), bugInput.platform, 1.toString())
             if (!enumValues<Enum.Level>().any {
                     it.name == bugInput.level.uppercase()
                 } || !enumValues<Enum.Status>().any {
                     it.name == bugInput.status.uppercase()
                 } || !enumValues<Enum.Dev_Status>().any { it.name == bugInput.dev_status.uppercase() }) {
                 ResponseEntity(HttpStatus.BAD_REQUEST)
-            } else if (!regex(bugInput.goodday_url) || !regex(bugInput.image_url)) {
+            } else if (!regex(bugInput.goodday_url.trim()) || !regex(bugInput.image_url.trim())) {
                 ResponseEntity(HttpStatus.BAD_REQUEST)
-            } else if (countPlat == 0 || countQc.isEmpty || countDev.isEmpty) {
+            } else if (countPlat == 0) {
                 ResponseEntity(HttpStatus.NOT_FOUND)
+            } else if (countQc == 0 || countDev == 0) {
+                ResponseEntity(HttpStatus.FORBIDDEN)
             } else if (bugInput.description.isNotBlank()) {
                 val foundPlat = platformRepository.findPlatform(userId.id.toString(), bugInput.platform)
                 val qc = userRepository.findById(bugInput.qc).get()
@@ -202,8 +204,8 @@ class BugController(
                     if (listOf(save).isNotEmpty()) {
                         val output = BugOutput(
                             id = save.id,
-                            created = SimpleDateFormat("dd-MM-yyyy").format(save.created),
-                            description = save.description.trim(),
+                            created = SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(save.created),
+                            description = save.description,
                             qc = save.qc!!.name,
                             dev = save.dev!!.name,
                             platform = save.platform!!.name,
@@ -229,47 +231,56 @@ class BugController(
 
     private fun validColumn(id: Long, bugInput: BugInput): Boolean {
         val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
-        val role = memberRepository.getRole(userId.id.toString(), bugInput.platform)
-        val roleEnum =
-            if (Enum.Member.values().any { it.ordinal == role }) Enum.Member.values()[role] else Enum.Member.UNDEFINED
-        val valid = bugRepository.validOwnerAdmin(userId.id.toString())
+        val validQc = memberRepository.validRoleByPlatform(userId.id.toString(), bugInput.platform, 0.toString())
+        val validPro = memberRepository.validRoleByPlatform(userId.id.toString(), bugInput.platform, 1.toString())
+        val validAdmin = memberRepository.validRoleByPlatform(userId.id.toString(), bugInput.platform, 2.toString())
+        val validOwner = bugRepository.validOwnerAdmin(userId.id.toString(), id)
         val bugData: Bug = bugRepository.findById(id).get()
         var col = arrayOf<Number>()
-        if (bugInput.description.trim() !== bugData.description.trim()) { //col += "description,"
+        if (!Objects.equals(bugInput.description.trim(), bugData.description.trim())) { //col += "description,"
             col += 1
         }
-        if (userRepository.findById(bugInput.qc).get().name !== bugData.qc!!.name) {//col += "qc,"
+        if (userRepository.findById(bugInput.qc).get().name.trim() !== bugData.qc!!.name.trim()) {//col += "qc,"
             col += 2
         }
-        if (userRepository.findById(bugInput.dev).get().name !== bugData.dev!!.name) {//col += "dev,"
+        if (userRepository.findById(bugInput.dev).get().name.trim() !== bugData.dev!!.name.trim()) {//col += "dev,"
             col += 3
         }
-        if (bugInput.platform.trim() !== bugData.platform!!.name) {//col += "platform,"
+        if (!Objects.equals(bugInput.platform.trim(), bugData.platform!!.name.trim())) {//col += "platform,"
             col += 4
         }
-        if (bugInput.goodday_url.trim() !== bugData.goodday_url.trim()) {//col += "goodday_url,"
+        if (!Objects.equals(bugInput.goodday_url.trim(), bugData.goodday_url.trim())) {//col += "goodday_url,"
             col += 5
         }
-        if (bugInput.image_url.trim() !== bugData.image_url.trim()) {//col += "image_url,"
-            col += 6
-        }
-        if (Enum.Level.values()[bugData.level] !== Enum.Level.valueOf(bugInput.level.uppercase())) {//col += "level,"
+        if (!Objects.equals(bugInput.image_url.trim(), bugData.image_url.trim())) {//col += "image_url,"
             col += 6
         }
-        if (Enum.Status.values()[bugData.status] !== Enum.Status.valueOf(bugInput.status.uppercase())) {//col += "level,"
+        if (!Objects.equals(
+                Enum.Level.values()[bugData.level], Enum.Level.valueOf(bugInput.level.uppercase())
+            )
+        ) {//col += "level,"
             col += 7
         }
-        if (Enum.Dev_Status.values()[bugData.dev_status] !== Enum.Dev_Status.valueOf(bugInput.dev_status.uppercase())) {//col += "level,"
+        if (!Objects.equals(
+                Enum.Status.values()[bugData.status], Enum.Status.valueOf(bugInput.status.uppercase())
+            )
+        ) {//col += "level,"
             col += 8
         }
+        if (!Objects.equals(
+                Enum.Dev_Status.values()[bugData.dev_status], Enum.Dev_Status.valueOf(bugInput.dev_status.uppercase())
+            )
+        ) {//col += "level,"
+            col += 9
+        }
         var ret = false
-        if (roleEnum == Enum.Member.PROGRAMMER && col.contains(9)) {
+        if (col.isEmpty()) {
             ret = true
-        }
-        if (roleEnum == Enum.Member.QC && (col.contains(6) || col.contains(7) || col.contains(8))) {
+        } else if (validAdmin > 0 || validOwner > 0) {
             ret = true
-        }
-        if (roleEnum == Enum.Member.ADMIN || valid > 0) {
+        } else if (validQc > 0 && (col.contains(6) || col.contains(7) || col.contains(8))) {
+            ret = true
+        } else if (validPro > 0 && col.contains(9)) {
             ret = true
         }
         return ret
@@ -312,7 +323,7 @@ class BugController(
                             if (listOf(save).isNotEmpty()) {
                                 val output = BugOutput(
                                     id = save.id,
-                                    description = save.description.trim(),
+                                    description = save.description,
                                     qc = save.qc!!.name,
                                     dev = save.dev!!.name,
                                     platform = save.platform!!.name,
@@ -346,7 +357,7 @@ class BugController(
         val find = bugRepository.findById(id)
         val used = commentRepository.findByBug(id.toString())
         val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
-        val validOwnerAdmin = bugRepository.validOwnerAdmin(userId.id.toString())
+        val validOwnerAdmin = bugRepository.validOwnerAdmin(userId.id.toString(), id)
         return try {
             if (validOwnerAdmin > 0) {
                 if (used > 0) {//child used in transaction

+ 3 - 3
src/main/kotlin/com/swagger/rest/controllers/CommentController.kt

@@ -74,7 +74,7 @@ class CommentController(
                         id = it.id,
                         bug = it.bug!!.description,
                         creator = it.creator!!.username,
-                        created = SimpleDateFormat("dd-MM-yyyy").format(it.created),
+                        created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
                         content = it.content
                     )
                 }
@@ -104,7 +104,7 @@ class CommentController(
                 id = it.id,
                 bug = it.bug!!.description,
                 creator = it.creator!!.username,
-                created = SimpleDateFormat("dd-MM-yyyy").format(it.created),
+                created = SimpleDateFormat("dd-MMM-yy HH:mm:ss").format(it.created),
                 content = it.content
             )
         }
@@ -135,7 +135,7 @@ class CommentController(
                             id = save.id,
                             bug = save.bug!!.description,
                             creator = save.creator!!.username,
-                            created = SimpleDateFormat("dd-MM-yyyy").format(save.created),
+                            created = SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(save.created),
                             content = save.content
                         )
                         ResponseEntity(output, HttpStatus.CREATED)

+ 2 - 2
src/main/kotlin/com/swagger/rest/repositories/BugRepository.kt

@@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.Query
 
 interface BugRepository : JpaRepository<Bug, Long>, JpaSpecificationExecutor<Bug> {
 
-    @Query("SELECT COUNT(0) FROM bug WHERE platform IN (SELECT platform FROM platform WHERE project_id IN (SELECT project_id FROM project WHERE OWNER=?1 UNION SELECT project_id FROM project_member WHERE role=2 AND user_id=?1))", nativeQuery = true)
-    fun validOwnerAdmin(owner: String?): Int
+    @Query("SELECT COUNT(0) FROM bug WHERE bug_id=?2 AND platform IN (SELECT platform_id FROM platform WHERE project_id IN (SELECT project_id FROM project WHERE OWNER=?1 UNION SELECT project_id FROM project_member WHERE role=2 AND user_id=?1))", nativeQuery = true)
+    fun validOwnerAdmin(owner: String?, id: Long): Int
 
 }

+ 2 - 2
src/main/kotlin/com/swagger/rest/repositories/MemberRepository.kt

@@ -30,7 +30,7 @@ interface MemberRepository : JpaRepository<ProjectMember, Long>, JpaSpecificatio
     @Query("SELECT COUNT(0) FROM project_member WHERE project_id=?1 AND user_id=?2", nativeQuery = true)
     fun validMember(project: String?, user: String?): Int
 
-    @Query("SELECT IFNULL((SELECT role FROM project_member WHERE user_id=?1 AND project_id IN (SELECT project_id FROM platform WHERE NAME=?2)), 4) AS role", nativeQuery = true)
-    fun getRole(user: String, platform: String): Int
+    @Query("SELECT COUNT(0) FROM project_member WHERE project_id IN (SELECT project_id FROM platform WHERE NAME=?2) AND user_id=?1 AND role=?3", nativeQuery = true)
+    fun validRoleByPlatform(user: String, platform: String, role: String): Int
 
 }

+ 1 - 0
src/main/kotlin/com/swagger/rest/repositories/UserRepository.kt

@@ -12,4 +12,5 @@ interface UserRepository : JpaRepository<User, Long> {
 
     @Query("SELECT COUNT(0) FROM user where user_id=?1 AND username=?2", nativeQuery = true)
     fun countByUser(userId: String, username: String): Int
+
 }

+ 7 - 7
swagger3 project.yml

@@ -957,7 +957,7 @@ components:
               creator:
                 example: irma
               created:
-                example: 22-11-2023
+                example: 22-Nov-2023 11:23:22
               content:
                 example: qc error mobile done
     successAddComment:
@@ -973,7 +973,7 @@ components:
               creator:
                 example: arif
               created:
-                example: 4-06-2023
+                example: 04-Jul-2023 11:23:22
               content:
                 example: error web mulai dikerjakan
     getArrayComment:
@@ -997,7 +997,7 @@ components:
                         creator:
                           example: dama
                         created:
-                          example: 15-08-2023
+                          example: 15-Ags-2023 11:23:22
                         content:
                           example: web sudah done
     getSingleBug:
@@ -1009,7 +1009,7 @@ components:
               id: 
                 example: 1
               created:
-                example: 01-02-2023
+                example: 01-Feb-2023 11:23:22
               description:
                 example: error button
               qc:
@@ -1037,7 +1037,7 @@ components:
               id:
                 example: 2
               created:
-                example: 23-03-2023
+                example: 23-Mar-2023 11:23:22
               description:
                 example: bug browser
               qc:
@@ -1075,7 +1075,7 @@ components:
                           example: 1
                         created:
                           type: string
-                          example: 01-01-2023
+                          example: 01-Jan-2023 11:23:22
                         description:
                           example: error button
                         qc:
@@ -1363,7 +1363,7 @@ components:
                   type: string
                   example: TelMesengger
     ProjectMember:
-      description: project member object
+      description: project member object (QC, Programmer, Admin)
       required: true
       content:
         application/json: