zhongjiajie commented on a change in pull request #7111:
URL: https://github.com/apache/dolphinscheduler/pull/7111#discussion_r761602386



##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
##########
@@ -590,6 +590,58 @@ public Result queryUserList(User loginUser, String 
searchVal, Integer pageNo, In
         return result;
     }
 
+    /**
+     * grant project by code
+     *
+     * @param loginUser login user
+     * @param userId user id
+     * @param projectCodes project code array
+     * @return grant result code
+     */
+    @Override
+    public Map<String, Object> grantProjectByCode(final User loginUser, final 
int userId, final String projectCodes) {
+        Map<String, Object> result = new HashMap<>();
+        result.put(Constants.STATUS, false);
+
+        // 1. only admin can operate
+        if (this.check(result, !this.isAdmin(loginUser), 
Status.USER_NO_OPERATION_PERM)) {
+            return result;
+        }
+
+        // 2. check if user is existed
+        User tempUser = this.userMapper.selectById(userId);
+        if (tempUser == null) {
+            putMsg(result, Status.USER_NOT_EXIST, userId);
+            return result;
+        }
+
+        // 3. if the selected projectCodes are empty, delete all items 
associated with the user
+        if (this.check(result, StringUtils.isEmpty(projectCodes), 
Status.SUCCESS)) {
+            this.projectUserMapper.deleteProjectRelation(0, userId);
+            return result;
+        }
+
+        // 4. maintain the relationship between project and user
+        for (String projectCode : projectCodes.split(",")) {

Review comment:
       I recommend to use `Constants.COMMA` here
   
https://github.com/apache/dolphinscheduler/blob/0dcff1425a28da0ce0004fc3e594b97d080c5fd9/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java#L160




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to