Search in sources :

Example 11 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project agile-service by open-hand.

the class SendMsgUtil method getOperatorNameFromUserDetail.

private String getOperatorNameFromUserDetail() {
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    if (ObjectUtils.isEmpty(userDetails)) {
        throw new CommonException("error.user.not.login");
    }
    Long userId = userDetails.getUserId();
    Map<Long, UserMessageDTO> userMap = userService.queryUsersMap(Arrays.asList(userId), true);
    UserMessageDTO user = userMap.get(userId);
    if (ObjectUtils.isEmpty(user)) {
        return null;
    } else {
        return user.getName();
    }
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails) CommonException(io.choerodon.core.exception.CommonException) UserMessageDTO(io.choerodon.agile.infra.dto.UserMessageDTO)

Example 12 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project agile-service by open-hand.

the class SprintServiceImpl method moveNotDoneIssueToTargetSprint.

protected void moveNotDoneIssueToTargetSprint(Long projectId, SprintCompleteVO sprintCompleteVO) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<MoveIssueDTO> moveIssueDTOS = new ArrayList<>();
    Long targetSprintId = sprintCompleteVO.getIncompleteIssuesDestination();
    List<Long> moveIssueRankIds = sprintMapper.queryIssueIdOrderByRankDesc(projectId, sprintCompleteVO.getSprintId());
    moveIssueRankIds.addAll(sprintMapper.queryUnDoneSubOfParentIds(projectId, sprintCompleteVO.getSprintId()));
    beforeRank(projectId, sprintCompleteVO.getIncompleteIssuesDestination(), moveIssueDTOS, moveIssueRankIds);
    if (moveIssueDTOS.isEmpty()) {
        return;
    }
    List<Long> moveIssueIds = sprintMapper.queryIssueIds(projectId, sprintCompleteVO.getSprintId());
    moveIssueIds.addAll(issueMapper.querySubTaskIds(projectId, sprintCompleteVO.getSprintId()));
    moveIssueIds.addAll(sprintMapper.queryParentsDoneSubtaskUnDoneIds(projectId, sprintCompleteVO.getSprintId()));
    if (targetSprintId != null && !Objects.equals(targetSprintId, 0L)) {
        issueAccessDataService.issueToDestinationByIdsCloseSprint(projectId, targetSprintId, moveIssueIds, new Date(), customUserDetails.getUserId());
    }
    // 查询移动到下个迭代中已完成的子任务
    List<Long> completedSubIssues = issueMapper.selectCompletedSubIssue(projectId, moveIssueIds);
    // 将已完成的子任务设置为历史迭代完成
    if (!CollectionUtils.isEmpty(completedSubIssues)) {
        issueMapper.updateSubIssueHistoryCompleted(projectId, completedSubIssues);
    }
    issueAccessDataService.batchUpdateIssueRank(projectId, moveIssueDTOS);
    // 移动完成后重新对冲刺内的重新排序
    reorderSprintIssue(projectId, targetSprintId);
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Example 13 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project agile-service by open-hand.

the class FieldPermissionIssueServiceImpl method listNoPermissionFieldsByIssueType.

@Override
public List<IssueTypeNoPermissionFields> listNoPermissionFieldsByIssueType(Long organizationId, Long projectId) {
    List<IssueTypeNoPermissionFields> result = new ArrayList<>();
    Map<Long, IssueTypeNoPermissionFields> resultMap = new HashMap<>();
    // 查询当前项目下的问题类型
    List<IssueTypeWithStateMachineIdVO> issueTypes = projectConfigService.queryIssueTypesWithStateMachineIdByProjectId(projectId, null, false);
    Set<Long> issueTypeIds = new HashSet<>();
    issueTypes.forEach(issueType -> {
        issueTypeIds.add(issueType.getId());
        IssueTypeNoPermissionFields issueTypeNoPermissionFields = new IssueTypeNoPermissionFields();
        issueTypeNoPermissionFields.setIssueTypeId(issueType.getId());
        issueTypeNoPermissionFields.setIssueTypeName(issueType.getName());
        issueTypeNoPermissionFields.setTypeCode(issueType.getTypeCode());
        issueTypeNoPermissionFields.setNoPermissionFieldCodes(new ArrayList<>());
        result.add(issueTypeNoPermissionFields);
        resultMap.put(issueType.getId(), issueTypeNoPermissionFields);
    });
    // 查询配置权限的字段
    List<FieldPermissionDTO> fieldPermissionList = fieldPermissionMapper.listPermissionsConfigured(projectId, organizationId, issueTypeIds);
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    boolean isAdmin = Boolean.TRUE.equals(userDetails.getAdmin());
    if (ObjectUtils.isEmpty(fieldPermissionList) || isAdmin) {
        return result;
    }
    Long userId = userDetails.getUserId();
    List<RoleVO> roles = Optional.ofNullable(baseFeignClient.getUserWithProjLevelRolesByUserId(projectId, userId).getBody()).orElse(new ArrayList<>());
    Set<Long> userRoleIds = new HashSet<>();
    if (!ObjectUtils.isEmpty(roles)) {
        userRoleIds.addAll(roles.stream().map(RoleVO::getId).collect(Collectors.toSet()));
    }
    Map<Long, List<FieldPermissionDTO>> issueTypeFieldPermissionMap = fieldPermissionList.stream().collect(Collectors.groupingBy(FieldPermissionDTO::getIssueTypeId));
    issueTypeFieldPermissionMap.keySet().forEach(issueTypeId -> {
        List<FieldPermissionDTO> issueTypeFieldPermissionDTOS = issueTypeFieldPermissionMap.get(issueTypeId);
        Map<String, List<FieldPermissionDTO>> fieldPermissionMap = issueTypeFieldPermissionDTOS.stream().collect(Collectors.groupingBy(FieldPermissionDTO::getFieldCode));
        IssueTypeNoPermissionFields issueTypeNoPermissionFields = resultMap.get(issueTypeId);
        List<String> noPermissionFieldCodes = issueTypeNoPermissionFields.getNoPermissionFieldCodes();
        // 当前问题类型下没有权限的字段
        fieldPermissionMap.keySet().forEach(fieldCode -> {
            boolean hasPermission = false;
            List<FieldPermissionDTO> fieldPermissionDTOS = fieldPermissionMap.get(fieldCode);
            List<Long> roleIds = fieldPermissionDTOS.stream().filter(v -> ROLE.equals(v.getType())).map(FieldPermissionDTO::getRoleMemberId).collect(Collectors.toList());
            List<Long> userIds = fieldPermissionDTOS.stream().filter(v -> USER.equals(v.getType())).map(FieldPermissionDTO::getRoleMemberId).collect(Collectors.toList());
            if (!ObjectUtils.isEmpty(userIds) && userIds.contains(userId)) {
                hasPermission = true;
            }
            long roleCount = userRoleIds.stream().filter(roleIds::contains).count();
            if (!ObjectUtils.isEmpty(roleIds) && roleCount > 0) {
                hasPermission = true;
            }
            if (Boolean.FALSE.equals(hasPermission)) {
                noPermissionFieldCodes.add(fieldCode);
            }
        });
    });
    return result;
}
Also used : FieldPermissionDTO(io.choerodon.agile.infra.dto.FieldPermissionDTO) CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Example 14 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project agile-service by open-hand.

the class FieldPermissionServiceImpl method filterHavingPermissionFieldIds.

private Set<Long> filterHavingPermissionFieldIds(Long projectId, Long organizationId, Set<Long> issueTypeIds, Set<Long> fieldIds) {
    Set<Long> hasPermissionFieldIds = new HashSet<>();
    if (!fieldIds.isEmpty()) {
        CustomUserDetails userDetails = DetailsHelper.getUserDetails();
        Long userId = userDetails.getUserId();
        List<RoleVO> roles = baseFeignClient.getUserWithProjLevelRolesByUserId(projectId, userId).getBody();
        Set<Long> userIds = new HashSet<>(Arrays.asList(userId));
        Set<Long> roleIds = new HashSet<>();
        if (!ObjectUtils.isEmpty(roles)) {
            roleIds.addAll(roles.stream().map(RoleVO::getId).collect(Collectors.toSet()));
        }
        PermissionVO permissionVO = new PermissionVO();
        permissionVO.setScope(FieldPermissionScope.READ.value());
        permissionVO.setUserIds(userIds);
        permissionVO.setRoleIds(roleIds);
        hasPermissionFieldIds.addAll(fieldPermissionMapper.filterHasPermissionFields(projectId, organizationId, issueTypeIds, permissionVO, fieldIds));
    }
    return hasPermissionFieldIds;
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Example 15 with CustomUserDetails

use of io.choerodon.core.oauth.CustomUserDetails in project agile-service by open-hand.

the class FieldPermissionServiceImpl method filterPageFieldViewVO.

@Override
public List<PageFieldViewVO> filterPageFieldViewVO(Long projectId, Long organizationId, Long issueTypeId, List<PageFieldViewVO> pageFieldViews) {
    Set<Long> issueTypeIds = new HashSet<>(Arrays.asList(issueTypeId));
    boolean isPermissionsConfigured = fieldPermissionMapper.isPermissionsConfigured(projectId, organizationId, issueTypeIds);
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    boolean isAdmin = Boolean.TRUE.equals(userDetails.getAdmin());
    if (!isPermissionsConfigured || isAdmin) {
        return pageFieldViews;
    }
    List<PageFieldViewVO> result = new ArrayList<>();
    Set<Long> hasPermissionFieldIds = new HashSet<>();
    Set<Long> fieldIds = new HashSet<>();
    pageFieldViews.forEach(x -> {
        if (IGNORED_FIELDS.contains(x.getFieldCode())) {
            hasPermissionFieldIds.add(x.getFieldId());
        } else {
            fieldIds.add(x.getFieldId());
        }
    });
    hasPermissionFieldIds.addAll(filterHavingPermissionFieldIds(projectId, organizationId, issueTypeIds, fieldIds));
    pageFieldViews.forEach(field -> {
        if (hasPermissionFieldIds.contains(field.getFieldId())) {
            result.add(field);
        }
    });
    return result;
}
Also used : CustomUserDetails(io.choerodon.core.oauth.CustomUserDetails)

Aggregations

CustomUserDetails (io.choerodon.core.oauth.CustomUserDetails)53 CommonException (io.choerodon.core.exception.CommonException)17 DetailsHelper (io.choerodon.core.oauth.DetailsHelper)7 Collectors (java.util.stream.Collectors)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PageRequest (io.choerodon.mybatis.pagehelper.domain.PageRequest)6 java.util (java.util)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 MockHttpServletRequest (io.choerodon.asgard.saga.consumer.MockHttpServletRequest)4 Value (org.springframework.beans.factory.annotation.Value)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Authentication (org.springframework.security.core.Authentication)4 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)4 Service (org.springframework.stereotype.Service)4 CollectionUtils (org.springframework.util.CollectionUtils)4 IssueDetailDTO (io.choerodon.agile.infra.dto.business.IssueDetailDTO)3 Page (io.choerodon.core.domain.Page)3