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 18aa4bb commit 4b43bd8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
50 changes: 38 additions & 12 deletions src/main/java/sast/evento/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -61,31 +62,56 @@ public String linkLogin(@RequestParam String email,
@OperateLog("addPermissionForTest")
@DefaultActionState(ActionState.LOGIN)
@PostMapping("/permission")
@Transactional
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 ->
permissionService.addAdmin(Objects.requireNonNullElse(permission, adminPermission), userModel.getId());
case MANAGER -> {
if (eventMapper.exists(Wrappers.lambdaQuery(Event.class).eq(Event::getId, eventId))) {
permissionService.addManager(eventId, Objects.requireNonNullElse(permission, managerPermission), userModel.getId());
} else {
return "no such event";
if(!permissionService.getUserAdminPermissions(userModel.getId()).isEmpty()){
switch (type) {
case ADMIN ->{
List<String> addedPermission = permission.isEmpty()?adminPermission:permission;
permissionService.addAdmin(addedPermission, userModel.getId());
}
case MANAGER -> {
if (eventMapper.exists(Wrappers.lambdaQuery(Event.class).eq(Event::getId, eventId))) {
List<String> addedPermission = permission.isEmpty()?managerPermission:permission;
permissionService.addManager(eventId, addedPermission, userModel.getId());
} else {
return "no such event";
}
}
default -> {
return "error type";
}
}
default -> {
return "error type";
return "ok";
}else {
switch (type) {
case ADMIN ->{
List<String> addedPermission = permission.isEmpty()?adminPermission:permission;
permissionService.updateAdminPermission(addedPermission, userModel.getId());
}
case MANAGER -> {
if (eventMapper.exists(Wrappers.lambdaQuery(Event.class).eq(Event::getId, eventId))) {
List<String> addedPermission = permission.isEmpty()?managerPermission:permission;
permissionService.updateManagerPermission(eventId, addedPermission, userModel.getId());
} else {
return "no such event";
}
}
default -> {
return "error type";
}
}
return "ok";
}
return "ok";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public List<User> getAdmins() {

@Override
public void updateAdminPermission(List<String> methodNames, String userId) {
System.out.println(methodNames);
System.out.println(defaultManagerPermission);
methodNames.addAll(defaultManagerPermission);

Permission permission = new Permission(null, 0, userId, methodNames, null);
permissionServiceCacheAble.updatePermission(permission);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/sast/evento/service/impl/WxServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public JsCodeSessionResponse login(String code) {
throw new LocalRunTimeException(ErrorEnum.WX_SERVICE_ERROR, "null response from wx");
}
JsCodeSessionResponse jsCodeSessionResponse = JsonUtil.fromJson(text, JsCodeSessionResponse.class);
System.out.println(text);
if (jsCodeSessionResponse == null ||!jsCodeSessionResponse.getErrmsg().isEmpty()) {
log.error("error get userInfo: " + text);
throw new LocalRunTimeException(ErrorEnum.WX_SERVICE_ERROR, "error get userInfo from WeChat");
Expand Down

0 comments on commit 4b43bd8

Please sign in to comment.