You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2021/12/02 08:16:35 UTC
[GitHub] [dolphinscheduler] JinyLeeChina commented on a change in pull request #7111: [Feature-7110][dolphinscheduler-api] support grant project by code
JinyLeeChina commented on a change in pull request #7111:
URL: https://github.com/apache/dolphinscheduler/pull/7111#discussion_r760850269
##########
File path: dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
##########
@@ -590,6 +590,60 @@ 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
+ @Transactional(rollbackFor = RuntimeException.class)
+ 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
+ String[] projectCodeArr = projectCodes.split(",");
+ for (String projectCode : projectCodeArr) {
Review comment:
I think there should be elegant writing here
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org