Skip to content

Commit

Permalink
[Improve] open API minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfboys committed Aug 12, 2024
1 parent ed19587 commit 9314938
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public RestResponse permissionAction(ProceedingJoinPoint joinPoint) throws Throw
// 2) check team
Long teamId = getId(joinPoint, methodSignature, permissionScope.team());
if (teamId != null) {
Member member = memberService.findByUserName(teamId, currentUser.getUsername());
Member member = memberService.findByUserId(teamId, currentUser.getUserId());
ApiAlertException.throwIfTrue(
member == null,
"Permission denied, only members of this team can access this permission");
Expand All @@ -199,7 +199,7 @@ public RestResponse permissionAction(ProceedingJoinPoint joinPoint) throws Throw
Application app = applicationService.getById(appId);
ApiAlertException.throwIfTrue(app == null, "Invalid operation, application is null");
if (!currentUser.getUserId().equals(app.getUserId())) {
Member member = memberService.findByUserName(app.getTeamId(), currentUser.getUsername());
Member member = memberService.findByUserId(app.getTeamId(), currentUser.getUserId());
ApiAlertException.throwIfTrue(
member == null,
"Permission denied, this job not created by the current user, And the job cannot be found in the current user's team.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public RestResponse delete(FlinkSql flinkSql) {
}

@PostMapping("get")
@PermissionScope(app = "#appId", team = "#teamId")
@PermissionScope(app = "#appId")
public RestResponse get(Long appId, Long teamId, String id) throws InternalException {
ApiAlertException.throwIfTrue(
appId == null || teamId == null, "Permission denied, appId and teamId cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ public class OpenAPIController {
required = true,
type = Long.class,
bindFor = "appId"),
@OpenAPI.Param(
name = "teamId",
description = "current user teamId",
required = true,
type = Long.class),
@OpenAPI.Param(
name = "argument",
description = "flink program run argument",
Expand All @@ -91,7 +86,7 @@ public class OpenAPIController {
type = Boolean.class,
defaultValue = "false"),
})
@PermissionScope(app = "#app.appId", team = "#app.teamId")
@PermissionScope(app = "#app.appId")
@PostMapping("app/start")
@RequiresPermissions("app:start")
public RestResponse flinkStart(Application app) throws Exception {
Expand All @@ -115,11 +110,6 @@ public RestResponse flinkStart(Application app) throws Exception {
required = true,
type = Long.class,
bindFor = "appId"),
@OpenAPI.Param(
name = "teamId",
description = "current user teamId",
required = true,
type = Long.class),
@OpenAPI.Param(
name = "triggerSavepoint",
description = "trigger savepoint before taking stopping",
Expand All @@ -139,7 +129,7 @@ public RestResponse flinkStart(Application app) throws Exception {
type = Boolean.class,
defaultValue = "false"),
})
@PermissionScope(app = "#app.appId", team = "#app.teamId")
@PermissionScope(app = "#app.appId")
@PostMapping("app/cancel")
@RequiresPermissions("app:cancel")
public RestResponse flinkCancel(Application app) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ResponseEntity<?> proxyFlinkUI(HttpServletRequest request, Long appId) th
return builder.body("Invalid operation, appId is invalid.");
}
if (!currentUser.getUserId().equals(app.getUserId())) {
Member member = memberService.findByUserName(app.getTeamId(), currentUser.getUsername());
Member member = memberService.findByUserId(app.getTeamId(), currentUser.getUserId());
if (member == null) {
return builder.body(
"Permission denied, this job not created by the current user, And the job cannot be found in the current user's team.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import java.util.List;

Expand All @@ -57,7 +56,7 @@ public RestResponse memberList(RestRequest restRequest, Member member) {
return RestResponse.success(userList);
}

@PostMapping("candidateUsers")
@PostMapping("candidate_users")
@RequiresPermissions("member:add")
public RestResponse candidateUsers(Long teamId) {
List<User> userList = memberService.findCandidateUsers(teamId);
Expand All @@ -70,12 +69,6 @@ public RestResponse listTeams(Long userId) {
return RestResponse.success(teamList);
}

@PostMapping("check/user")
public RestResponse check(@NotBlank(message = "{required}") Long teamId, String userName) {
Member result = this.memberService.findByUserName(teamId, userName);
return RestResponse.success(result == null);
}

@PermissionScope(team = "#member.teamId")
@PostMapping("post")
@RequiresPermissions("member:add")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

public interface MemberService extends IService<Member> {

void deleteByRoleIds(String[] roleIds);

void deleteByUserId(Long userId);

void deleteByTeamId(Long teamId);
Expand All @@ -41,7 +39,7 @@ public interface MemberService extends IService<Member> {

List<Team> findUserTeams(Long userId);

Member findByUserName(Long teamId, String userName);
Member findByUserId(Long teamId, Long userId);

List<Long> findUserIdsByRoleId(Long roleId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
Expand All @@ -58,12 +57,6 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
@Autowired private TeamService teamService;
@Autowired private ServiceHelper serviceHelper;

@Override
@Transactional
public void deleteByRoleIds(String[] roleIds) {
Arrays.stream(roleIds).forEach(id -> baseMapper.deleteByRoleId(Long.valueOf(id)));
}

@Override
@Transactional
public void deleteByUserId(Long userId) {
Expand Down Expand Up @@ -95,15 +88,7 @@ public List<Team> findUserTeams(Long userId) {
}

@Override
public Member findByUserName(Long teamId, String userName) {
User user = userService.findByName(userName);
if (user == null) {
return null;
}
return findByUserId(teamId, user.getUserId());
}

private Member findByUserId(Long teamId, Long userId) {
public Member findByUserId(Long teamId, Long userId) {
ApiAlertException.throwIfNull(teamId, "The team id is required.");
LambdaQueryWrapper<Member> queryWrapper =
new LambdaQueryWrapper<Member>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ enum MEMBER_API {
UPDATE = '/member/update',
LIST = '/member/list',
TEAMS = '/member/teams',
CHECK_NAME = '/user/check/name',
DELETE = '/member/delete',
CANDIDATE_USERS = '/member/candidateUsers',
CANDIDATE_USERS = '/member/candidate_users',
}

/**
Expand Down Expand Up @@ -78,14 +77,6 @@ export function fetchUserTeam(data: {
}): Promise<Array<{ id: string; teamName: string }>> {
return defHttp.post({ url: MEMBER_API.TEAMS, data });
}
/**
* name check
* @param {Object} data username
* @returns {Promise<boolean>}
*/
export function fetchCheckUserName(data: { username: string }): Promise<boolean> {
return defHttp.post({ url: MEMBER_API.CHECK_NAME, data });
}

/**
* delete
Expand Down

0 comments on commit 9314938

Please sign in to comment.