Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flow): the disabled user can still approving or rejecting a flow #2589

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.oceanbase.odc.service.flow;

import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -70,6 +71,7 @@
import com.oceanbase.odc.metadb.flow.ServiceTaskInstanceRepository;
import com.oceanbase.odc.metadb.flow.UserTaskInstanceCandidateRepository;
import com.oceanbase.odc.metadb.flow.UserTaskInstanceRepository;
import com.oceanbase.odc.metadb.iam.UserEntity;
import com.oceanbase.odc.metadb.task.TaskEntity;
import com.oceanbase.odc.metadb.task.TaskRepository;
import com.oceanbase.odc.plugin.task.api.datatransfer.model.DataTransferConfig;
Expand Down Expand Up @@ -201,6 +203,9 @@ public void setUp() {
when(riskLevelService.findDefaultRiskLevel()).thenReturn(getRiskLevel());
when(riskLevelService.list()).thenReturn(Arrays.asList(getRiskLevel(), getRiskLevel()));
doNothing().when(databasePermissionHelper).checkPermissions(Mockito.anyCollection(), Mockito.anyCollection());
UserEntity user = new UserEntity();
user.setEnabled(true);
when(userService.nullSafeGet(anyLong())).thenReturn(user);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ private ProjectMember fromUserResourceRole(UserResourceRole userResourceRole) {
member.setId(userResourceRole.getUserId());
member.setName(user.getName());
member.setAccountName(user.getAccountName());
member.setUserEnabled(user.isEnabled());
return member;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public static class ProjectMember {
@JsonProperty(access = Access.READ_ONLY)
private String accountName;

@JsonProperty(access = Access.READ_ONLY)
private Boolean userEnabled;
MarkPotato777 marked this conversation as resolved.
Show resolved Hide resolved

@JsonProperty(access = Access.READ_ONLY)
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -97,6 +98,9 @@ public boolean isApprovable(@NonNull Long approvalInstanceId) {

public List<UserTaskInstanceEntity> getApprovableApprovalInstances() {
long userId = authenticationFacade.currentUserId();
if (!userService.nullSafeGet(userId).isEnabled()) {
return new ArrayList<>();
}
Set<Long> roleIds = userService.getCurrentUserRoleIds();
Set<String> resourceRoleIdentifiers = userService.getCurrentUserResourceRoleIdentifiers();
Set<FlowNodeStatus> unViewableStatuses = Collections.singleton(FlowNodeStatus.CREATED);
Expand Down Expand Up @@ -180,12 +184,12 @@ private Map<Long, Set<UserEntity>> getUsersByFlowInstanceIdsAndStatus(@NonNull C
if (approvalUserIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, UserEntity> userId2User = userRepository.findByUserIds(approvalUserIds).stream()
Map<Long, UserEntity> userId2User = userRepository.findByUserIdsAndEnabled(approvalUserIds, true).stream()
.collect(Collectors.toMap(UserEntity::getId, userEntity -> userEntity));

Map<Long, Set<UserEntity>> instanceId2Candidates = instanceId2UserIds.entrySet().stream().collect(
Collectors.toMap(Entry::getKey, entry -> entry.getValue().stream().map(userId2User::get).collect(
Collectors.toSet())));
Collectors.toMap(Entry::getKey, entry -> entry.getValue().stream().map(userId2User::get)
.filter(Objects::nonNull).collect(Collectors.toSet())));
// map flow instance ids to users entity
return instanceId2UserIds.entrySet().stream().collect(
Collectors.toMap(entry -> approvalInstanceId2FlowInstanceId.get(entry.getKey()),
Expand Down