fix #2598::allow to update resource suffix,but if it is authorized to other users,it is not allowed (#2732)
* fix #2598:allow to update resource suffix,but if it is authorized to other users,it is not allowed. * add RESOURCE_IS_AUTHORIZED status * verify whether the suffix is empty * remove extra variables * fix code smelldev-1.3.0
parent
63ce143be5
commit
60f8eb25fa
|
|
@ -191,7 +191,7 @@ public enum Status {
|
|||
RESOURCE_IS_USED(20014, "resource file is used by process definition","资源文件被上线的流程定义使用了"),
|
||||
PARENT_RESOURCE_NOT_EXIST(20015, "parent resource not exist","父资源文件不存在"),
|
||||
RESOURCE_NOT_EXIST_OR_NO_PERMISSION(20016, "resource not exist or no permission,please view the task node and remove error resource","请检查任务节点并移除无权限或者已删除的资源"),
|
||||
|
||||
RESOURCE_IS_AUTHORIZED(20017, "resource is authorized to user {0},suffix not allowed to be modified", "资源文件已授权其他用户[{0}],后缀不允许修改"),
|
||||
|
||||
USER_NO_OPERATION_PERM(30001, "user has no operation privilege", "当前用户没有操作权限"),
|
||||
USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]项目的操作权限"),
|
||||
|
|
|
|||
|
|
@ -32,10 +32,7 @@ import org.apache.dolphinscheduler.api.utils.Result;
|
|||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ResourceType;
|
||||
import org.apache.dolphinscheduler.common.utils.*;
|
||||
import org.apache.dolphinscheduler.dao.entity.Resource;
|
||||
import org.apache.dolphinscheduler.dao.entity.Tenant;
|
||||
import org.apache.dolphinscheduler.dao.entity.UdfFunc;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.entity.*;
|
||||
import org.apache.dolphinscheduler.dao.mapper.*;
|
||||
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -352,24 +349,40 @@ public class ResourcesService extends BaseService {
|
|||
throw new ServiceException(Status.HDFS_OPERATION_ERROR);
|
||||
}
|
||||
|
||||
String nameWithSuffix = name;
|
||||
|
||||
if (!resource.isDirectory()) {
|
||||
//get the file suffix
|
||||
String suffix = originResourceName.substring(originResourceName.lastIndexOf("."));
|
||||
//get the origin file suffix
|
||||
String originSuffix = FileUtils.suffix(originFullName);
|
||||
String suffix = FileUtils.suffix(fullName);
|
||||
boolean suffixIsChanged = false;
|
||||
if (StringUtils.isBlank(suffix) && StringUtils.isNotBlank(originSuffix)) {
|
||||
suffixIsChanged = true;
|
||||
}
|
||||
if (StringUtils.isNotBlank(suffix) && !suffix.equals(originSuffix)) {
|
||||
suffixIsChanged = true;
|
||||
}
|
||||
//verify whether suffix is changed
|
||||
if (suffixIsChanged) {
|
||||
//need verify whether this resource is authorized to other users
|
||||
Map<String, Object> columnMap = new HashMap<>();
|
||||
columnMap.put("resources_id", resourceId);
|
||||
|
||||
//if the name without suffix then add it ,else use the origin name
|
||||
if(!name.endsWith(suffix)){
|
||||
nameWithSuffix = nameWithSuffix + suffix;
|
||||
List<ResourcesUser> resourcesUsers = resourceUserMapper.selectByMap(columnMap);
|
||||
if (CollectionUtils.isNotEmpty(resourcesUsers)) {
|
||||
List<Integer> userIds = resourcesUsers.stream().map(ResourcesUser::getId).collect(Collectors.toList());
|
||||
List<User> users = userMapper.selectBatchIds(userIds);
|
||||
String userNames = users.stream().map(User::getUserName).collect(Collectors.toList()).toString();
|
||||
logger.error("resource is authorized to user {},suffix not allowed to be modified", userNames);
|
||||
putMsg(result,Status.RESOURCE_IS_AUTHORIZED,userNames);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updateResource data
|
||||
List<Integer> childrenResource = listAllChildren(resource,false);
|
||||
String oldFullName = resource.getFullName();
|
||||
Date now = new Date();
|
||||
|
||||
resource.setAlias(nameWithSuffix);
|
||||
resource.setAlias(name);
|
||||
resource.setFullName(fullName);
|
||||
resource.setDescription(desc);
|
||||
resource.setUpdateTime(now);
|
||||
|
|
@ -381,7 +394,7 @@ public class ResourcesService extends BaseService {
|
|||
List<Resource> childResourceList = new ArrayList<>();
|
||||
List<Resource> resourceList = resourcesMapper.listResourceByIds(childrenResource.toArray(new Integer[childrenResource.size()]));
|
||||
childResourceList = resourceList.stream().map(t -> {
|
||||
t.setFullName(t.getFullName().replaceFirst(oldFullName, matcherFullName));
|
||||
t.setFullName(t.getFullName().replaceFirst(originFullName, matcherFullName));
|
||||
t.setUpdateTime(now);
|
||||
return t;
|
||||
}).collect(Collectors.toList());
|
||||
|
|
|
|||
Loading…
Reference in New Issue