Skip to content

Commit

Permalink
fix addPermission for test
Browse files Browse the repository at this point in the history
  • Loading branch information
feellmoose committed Nov 16, 2023
1 parent 1b15295 commit a2a0bde
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/sast/evento/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
import sast.evento.annotation.OperateLog;
import sast.evento.common.enums.ActionState;
import sast.evento.common.enums.ErrorEnum;
import sast.evento.config.ActionRegister;
import sast.evento.entitiy.Event;
import sast.evento.entitiy.Permission;
import sast.evento.exception.LocalRunTimeException;
import sast.evento.interceptor.HttpInterceptor;
import sast.evento.mapper.EventMapper;
import sast.evento.mapper.PermissionMapper;
import sast.evento.model.Action;
import sast.evento.model.UserModel;
import sast.evento.service.PermissionService;
import sast.sastlink.sdk.service.SastLinkService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@ConditionalOnProperty(prefix = "test", name = "challenge")
Expand All @@ -39,6 +43,8 @@ public class TestController {
@Resource
private PermissionService permissionService;
@Resource
private PermissionMapper permissionMapper;
@Resource
private EventMapper eventMapper;


Expand All @@ -65,27 +71,26 @@ public String linkLogin(@RequestParam String email,
public String permission(@RequestParam ActionState type,
@RequestParam(required = false) Integer eventId,
@RequestParam(required = false) List<String> permission) {
//异常丑陋的代码,随他去吧,反正是测试用的(
UserModel userModel = HttpInterceptor.userHolder.get();
final List<String> adminPermission = ActionRegister.actionName2action.values().stream()
.filter(a -> a.getActionState().equals(ActionState.ADMIN))
.map(Action::getMethodName).toList();
final List<String> managerPermission = ActionRegister.actionName2action.values().stream()
.filter(a -> a.getActionState().equals(ActionState.MANAGER))
.map(Action::getMethodName).toList();
switch (type) {
case ADMIN -> {
List<String> adminPermission = permissionService.getAllAdminPermissions().stream().map(Action::getMethodName).collect(Collectors.toList());
List<String> addedPermission = permission.isEmpty() ? adminPermission : permission;
if (permissionService.getUserAdminPermissions(userModel.getId()).isEmpty()) {
if (!permissionMapper.exists(Wrappers.lambdaQuery(Permission.class)
.eq(Permission::getUserId, userModel.getId())
.and(wrapper -> wrapper.eq(Permission::getEventId, 0)))) {
permissionService.addAdmin(addedPermission, userModel.getId());
} else {
permissionService.updateAdminPermission(addedPermission, userModel.getId());
}
}
case MANAGER -> {
List<String> managerPermission = permissionService.getAllManagerPermissions().stream().map(Action::getMethodName).collect(Collectors.toList());
if (eventMapper.exists(Wrappers.lambdaQuery(Event.class).eq(Event::getId, eventId))) {
List<String> addedPermission = permission.isEmpty() ? managerPermission : permission;
if (permissionService.getUserManagerPermissions(eventId, userModel.getId()).isEmpty()) {
if (!permissionMapper.exists(Wrappers.lambdaQuery(Permission.class)
.eq(Permission::getUserId, userModel.getId())
.and(wrapper -> wrapper.eq(Permission::getEventId, eventId)))) {
permissionService.addManager(eventId, addedPermission, userModel.getId());
} else {
permissionService.updateManagerPermission(eventId, addedPermission, userModel.getId());
Expand Down

0 comments on commit a2a0bde

Please sign in to comment.