mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(improvement)[build] Use Spotless to customize the code formatting (#1750)
This commit is contained in:
@@ -31,8 +31,7 @@ public class AuthController {
|
||||
}
|
||||
|
||||
@GetMapping("/queryGroup")
|
||||
public List<AuthGroup> queryAuthGroup(
|
||||
@RequestParam("modelId") String modelId,
|
||||
public List<AuthGroup> queryAuthGroup(@RequestParam("modelId") String modelId,
|
||||
@RequestParam(value = "groupId", required = false) Integer groupId) {
|
||||
return authService.queryAuthGroups(modelId, groupId);
|
||||
}
|
||||
@@ -69,10 +68,8 @@ public class AuthController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/queryAuthorizedRes")
|
||||
public AuthorizedResourceResp queryAuthorizedResources(
|
||||
@RequestBody QueryAuthResReq req,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
public AuthorizedResourceResp queryAuthorizedResources(@RequestBody QueryAuthResReq req,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return authService.queryAuthorizedResources(req, user);
|
||||
}
|
||||
|
||||
@@ -39,18 +39,15 @@ public class AuthServiceImpl implements AuthService {
|
||||
List<String> rows =
|
||||
jdbcTemplate.queryForList("select config from s2_auth_groups", String.class);
|
||||
Gson g = new Gson();
|
||||
return rows.stream()
|
||||
.map(row -> g.fromJson(row, AuthGroup.class))
|
||||
return rows.stream().map(row -> g.fromJson(row, AuthGroup.class))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AuthGroup> queryAuthGroups(String modelId, Integer groupId) {
|
||||
return load().stream()
|
||||
.filter(
|
||||
group ->
|
||||
(Objects.isNull(groupId) || groupId.equals(group.getGroupId()))
|
||||
&& modelId.equals(group.getModelId().toString()))
|
||||
.filter(group -> (Objects.isNull(groupId) || groupId.equals(group.getGroupId()))
|
||||
&& modelId.equals(group.getModelId().toString()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -65,15 +62,11 @@ public class AuthServiceImpl implements AuthService {
|
||||
nextGroupId = obj + 1;
|
||||
}
|
||||
group.setGroupId(nextGroupId);
|
||||
jdbcTemplate.update(
|
||||
"insert into s2_auth_groups (group_id, config) values (?, ?);",
|
||||
nextGroupId,
|
||||
g.toJson(group));
|
||||
jdbcTemplate.update("insert into s2_auth_groups (group_id, config) values (?, ?);",
|
||||
nextGroupId, g.toJson(group));
|
||||
} else {
|
||||
jdbcTemplate.update(
|
||||
"update s2_auth_groups set config = ? where group_id = ?;",
|
||||
g.toJson(group),
|
||||
group.getGroupId());
|
||||
jdbcTemplate.update("update s2_auth_groups set config = ? where group_id = ?;",
|
||||
g.toJson(group), group.getGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,30 +112,24 @@ public class AuthServiceImpl implements AuthService {
|
||||
return resource;
|
||||
}
|
||||
|
||||
private List<AuthGroup> getAuthGroups(
|
||||
List<Long> modelIds, String userName, List<String> departmentIds) {
|
||||
List<AuthGroup> groups =
|
||||
load().stream()
|
||||
.filter(
|
||||
group -> {
|
||||
if (!modelIds.contains(group.getModelId())) {
|
||||
return false;
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(group.getAuthorizedUsers())
|
||||
&& group.getAuthorizedUsers().contains(userName)) {
|
||||
return true;
|
||||
}
|
||||
for (String departmentId : departmentIds) {
|
||||
if (!CollectionUtils.isEmpty(
|
||||
group.getAuthorizedDepartmentIds())
|
||||
&& group.getAuthorizedDepartmentIds()
|
||||
.contains(departmentId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
private List<AuthGroup> getAuthGroups(List<Long> modelIds, String userName,
|
||||
List<String> departmentIds) {
|
||||
List<AuthGroup> groups = load().stream().filter(group -> {
|
||||
if (!modelIds.contains(group.getModelId())) {
|
||||
return false;
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(group.getAuthorizedUsers())
|
||||
&& group.getAuthorizedUsers().contains(userName)) {
|
||||
return true;
|
||||
}
|
||||
for (String departmentId : departmentIds) {
|
||||
if (!CollectionUtils.isEmpty(group.getAuthorizedDepartmentIds())
|
||||
&& group.getAuthorizedDepartmentIds().contains(departmentId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
log.info("user:{} department:{} authGroups:{}", userName, departmentIds, groups);
|
||||
return groups;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user