Skip to content

Commit 38b9eb5

Browse files
committed
delete remove group endpoint, refactor user list of group
1 parent ba57a73 commit 38b9eb5

File tree

7 files changed

+40
-33
lines changed

7 files changed

+40
-33
lines changed

core/src/main/java/com/flowci/core/flow/controller/FlowController.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,15 @@ public class FlowController {
4343

4444
private final FlowService flowService;
4545

46-
private final FlowGroupService flowGroupService;
47-
4846
private final FlowItemService flowItemService;
4947

5048
public FlowController(List<Template> templates,
5149
UserService userService,
5250
FlowService flowService,
53-
FlowGroupService flowGroupService,
5451
FlowItemService flowItemService) {
5552
this.templates = templates;
5653
this.userService = userService;
5754
this.flowService = flowService;
58-
this.flowGroupService = flowGroupService;
5955
this.flowItemService = flowItemService;
6056
}
6157

core/src/main/java/com/flowci/core/flow/controller/FlowGroupController.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ public void addToGroup(@PathVariable String groupName, @PathVariable String flow
3333
flowGroupService.addToGroup(flowName, groupName);
3434
}
3535

36-
@DeleteMapping("/{groupName}/{flowName}")
37-
@Action(FlowAction.GROUP_UPDATE)
38-
public void removeFromGroup(@PathVariable("groupName") String ignore, @PathVariable String flowName) {
39-
flowGroupService.removeFromGroup(flowName);
40-
}
41-
4236
@DeleteMapping("/{name}")
4337
@Action(FlowAction.GROUP_UPDATE)
4438
public void delete(@PathVariable String name, @RequestParam(required = false) boolean deleteFlow) {

core/src/main/java/com/flowci/core/flow/dao/FlowItemDao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import java.util.Collection;
88
import java.util.List;
9+
import java.util.Set;
910

1011
@Repository
1112
public interface FlowItemDao extends MongoRepository<FlowItem, String> {
1213

13-
List<FlowItem> findAllByIdInOrderByCreatedAt(Collection<String> ids);
14+
Set<FlowItem> findAllByIdIn(Collection<String> ids);
1415

1516
boolean existsByName(String name);
1617
}

core/src/main/java/com/flowci/core/flow/domain/FlowItem.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
@Document("flow")
1818
public class FlowItem extends Mongoable {
1919

20-
private final static String DefaultRootId = "-1";
20+
public final static String ROOT_ID = "-1";
21+
22+
public final static String ROOT_NAME = "flows";
2123

2224
public enum Type {
2325
Flow,
@@ -35,9 +37,13 @@ public enum Type {
3537
/**
3638
* Parent flow item id
3739
*/
38-
protected String parentId = DefaultRootId;
40+
protected String parentId = ROOT_ID;
3941

4042
public boolean hasParentId() {
4143
return StringHelper.hasValue(parentId);
4244
}
45+
46+
public boolean hasRootParent() {
47+
return hasParentId() && parentId.equals(ROOT_ID);
48+
}
4349
}

core/src/main/java/com/flowci/core/flow/service/FlowGroupService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,5 @@ public interface FlowGroupService {
1818
*/
1919
void addToGroup(String flowName, String groupName);
2020

21-
/**
22-
* Remove flow from a group
23-
*/
24-
void removeFromGroup(String flowName);
25-
2621
void delete(String name);
2722
}

core/src/main/java/com/flowci/core/flow/service/FlowGroupServiceImpl.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.flowci.core.flow.dao.FlowUserDao;
77
import com.flowci.core.flow.domain.Flow;
88
import com.flowci.core.flow.domain.FlowGroup;
9+
import com.flowci.core.flow.domain.FlowItem;
910
import com.flowci.exception.ArgumentException;
1011
import com.flowci.exception.DuplicateException;
1112
import com.flowci.exception.NotFoundException;
@@ -70,20 +71,14 @@ public void addToGroup(String flowName, String groupName) {
7071
throw new ArgumentException("Cannot add to same group");
7172
}
7273

73-
var group = get(groupName);
74-
var flow = getFlow(flowName);
75-
flow.setParentId(group.getId());
76-
flowDao.save(flow);
77-
78-
// add all users from current flow to parent group
79-
var users = flowUserDao.findAllUsers(flow.getId());
80-
flowUserDao.insert(group.getId(), Sets.newHashSet(users));
81-
}
74+
var groupId = FlowItem.ROOT_ID;
75+
if (!FlowItem.ROOT_NAME.equals(groupName)) {
76+
var group = get(groupName);
77+
groupId = group.getId();
78+
}
8279

83-
@Override
84-
public void removeFromGroup(String flowName) {
8580
var flow = getFlow(flowName);
86-
flow.setParentId(null);
81+
flow.setParentId(groupId);
8782
flowDao.save(flow);
8883
}
8984

core/src/main/java/com/flowci/core/flow/service/FlowItemServiceImpl.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import com.flowci.core.flow.dao.FlowItemDao;
55
import com.flowci.core.flow.dao.FlowUserDao;
66
import com.flowci.core.flow.domain.FlowItem;
7+
import com.google.common.collect.ImmutableList;
78
import org.springframework.stereotype.Service;
89

9-
import java.util.List;
10+
import java.util.*;
1011

1112
@Service
1213
public class FlowItemServiceImpl implements FlowItemService {
@@ -26,8 +27,27 @@ public FlowItemServiceImpl(FlowItemDao flowItemDao, FlowUserDao flowUserDao, Ses
2627
@Override
2728
public List<FlowItem> list() {
2829
var email = sessionManager.getUserEmail();
29-
List<String> flows = flowUserDao.findAllFlowsByUserEmail(email);
30-
return flowItemDao.findAllByIdInOrderByCreatedAt(flows);
30+
31+
List<String> itemIdList = flowUserDao.findAllFlowsByUserEmail(email);
32+
Set<FlowItem> items = flowItemDao.findAllByIdIn(itemIdList);
33+
34+
// find all group id, since need to load group that user has permission for flow
35+
Set<String> groupIdSet = new HashSet<>(items.size() / 2);
36+
for (FlowItem item : items) {
37+
if (item.hasRootParent()) {
38+
continue;
39+
}
40+
groupIdSet.add(item.getParentId());
41+
}
42+
43+
// load and remove duplicated groups, since some groups created by current user
44+
Set<FlowItem> groups = flowItemDao.findAllByIdIn(groupIdSet);
45+
items.removeAll(groups);
46+
47+
List<FlowItem> list = new ArrayList<>(items.size() + groups.size());
48+
list.addAll(items);
49+
list.addAll(groups);
50+
return list;
3151
}
3252

3353
@Override

0 commit comments

Comments
 (0)