feat(im): add tenant admin edit flows
这个提交包含在:
父节点
eae18723a5
当前提交
b89cd35b15
@ -34,7 +34,7 @@ public class GroupController {
|
||||
@AuthenticationPrincipal String userId,
|
||||
@RequestParam String appId) {
|
||||
return ResponseEntity.ok(ApiResponse.success(
|
||||
groupService.create(appId, req.name(), userId, req.memberIds(), req.groupType())));
|
||||
groupService.create(appId, req.name(), userId, req.memberIds(), req.groupType(), null)));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -83,7 +83,7 @@ public class GroupController {
|
||||
@RequestBody UpdateGroupRequest req,
|
||||
@AuthenticationPrincipal String userId) {
|
||||
return ResponseEntity.ok(ApiResponse.success(
|
||||
groupService.update(groupId, userId, req.name(), req.announcement())));
|
||||
groupService.update(groupId, userId, req.name(), req.groupType(), req.announcement())));
|
||||
}
|
||||
|
||||
@PostMapping("/{groupId}/members")
|
||||
@ -200,7 +200,7 @@ public class GroupController {
|
||||
}
|
||||
|
||||
public record CreateGroupRequest(String name, List<String> memberIds, String groupType) {}
|
||||
public record UpdateGroupRequest(String name, String announcement) {}
|
||||
public record UpdateGroupRequest(String name, String groupType, String announcement) {}
|
||||
public record MemberRequest(String userId) {}
|
||||
public record MemberBatchRequest(List<String> userIds) {}
|
||||
public record SetRoleRequest(String userId, String role) {}
|
||||
|
||||
@ -89,6 +89,24 @@ public class ImAdminController {
|
||||
return ResponseEntity.ok(ApiResponse.success(saved));
|
||||
}
|
||||
|
||||
/** Update a registered IM user profile without changing userId. */
|
||||
@PutMapping("/users/{userId}")
|
||||
public ResponseEntity<ApiResponse<ImAccountEntity>> updateUser(
|
||||
@RequestParam String appId,
|
||||
@PathVariable String userId,
|
||||
@AuthenticationPrincipal String operatorId,
|
||||
@RequestBody UpdateUserRequest req) {
|
||||
ImAccountEntity saved = accountService.updateAccount(
|
||||
appId,
|
||||
userId,
|
||||
req.nickname(),
|
||||
req.avatar(),
|
||||
req.gender(),
|
||||
req.status());
|
||||
operationLogService.record(appId, operatorId, "UPDATE_USER", "ACCOUNT", userId, req.nickname());
|
||||
return ResponseEntity.ok(ApiResponse.success(saved));
|
||||
}
|
||||
|
||||
/** List all groups for the given appId. */
|
||||
@GetMapping("/groups")
|
||||
public ResponseEntity<ApiResponse<List<ImGroupEntity>>> listGroups(@RequestParam String appId) {
|
||||
@ -101,9 +119,13 @@ public class ImAdminController {
|
||||
@RequestParam String appId,
|
||||
@AuthenticationPrincipal String operatorId,
|
||||
@RequestBody RegisterUserRequest req) {
|
||||
accountService.loginOrRegister(appId, req.userId(), req.nickname(), req.avatar());
|
||||
ImAccountEntity account = accountRepository.findByAppIdAndUserId(appId, req.userId())
|
||||
.orElseThrow();
|
||||
ImAccountEntity account = accountService.importAccount(
|
||||
appId,
|
||||
req.userId(),
|
||||
req.nickname(),
|
||||
req.avatar(),
|
||||
req.gender(),
|
||||
req.status());
|
||||
operationLogService.record(appId, operatorId, "REGISTER_USER", "ACCOUNT", req.userId(), req.nickname());
|
||||
return ResponseEntity.ok(ApiResponse.success(account));
|
||||
}
|
||||
@ -114,11 +136,34 @@ public class ImAdminController {
|
||||
@RequestParam String appId,
|
||||
@AuthenticationPrincipal String operatorId,
|
||||
@RequestBody CreateGroupRequest req) {
|
||||
ImGroupEntity group = groupService.create(appId, req.name(), req.creatorId(), req.memberIds(), "WORK");
|
||||
ImGroupEntity group = groupService.create(
|
||||
appId,
|
||||
req.name(),
|
||||
req.creatorId(),
|
||||
req.memberIds(),
|
||||
req.groupType(),
|
||||
req.announcement());
|
||||
operationLogService.record(appId, operatorId, "CREATE_GROUP", "GROUP", group.getId(), group.getName());
|
||||
return ResponseEntity.ok(ApiResponse.success(group));
|
||||
}
|
||||
|
||||
/** Admin updates a group without changing its id. */
|
||||
@PutMapping("/groups/{groupId}")
|
||||
public ResponseEntity<ApiResponse<ImGroupEntity>> updateGroup(
|
||||
@RequestParam String appId,
|
||||
@PathVariable String groupId,
|
||||
@AuthenticationPrincipal String operatorId,
|
||||
@RequestBody UpdateGroupRequest req) {
|
||||
ImGroupEntity group = groupService.update(
|
||||
groupId,
|
||||
operatorId,
|
||||
req.name(),
|
||||
req.groupType(),
|
||||
req.announcement());
|
||||
operationLogService.record(appId, operatorId, "UPDATE_GROUP", "GROUP", groupId, req.name());
|
||||
return ResponseEntity.ok(ApiResponse.success(group));
|
||||
}
|
||||
|
||||
/** Fuzzy search users by userId or nickname. */
|
||||
@GetMapping("/users/search")
|
||||
public ResponseEntity<ApiResponse<List<ImAccountEntity>>> searchUsers(
|
||||
@ -317,8 +362,19 @@ public class ImAdminController {
|
||||
operationLogService.list(appId, PageRequest.of(page, size))));
|
||||
}
|
||||
|
||||
public record RegisterUserRequest(String userId, String nickname, String avatar) {}
|
||||
public record CreateGroupRequest(String name, String creatorId, List<String> memberIds) {}
|
||||
public record RegisterUserRequest(
|
||||
String userId,
|
||||
String nickname,
|
||||
String avatar,
|
||||
ImAccountEntity.Gender gender,
|
||||
ImAccountEntity.Status status) {}
|
||||
public record UpdateUserRequest(
|
||||
String nickname,
|
||||
String avatar,
|
||||
ImAccountEntity.Gender gender,
|
||||
ImAccountEntity.Status status) {}
|
||||
public record CreateGroupRequest(String name, String creatorId, List<String> memberIds, String groupType, String announcement) {}
|
||||
public record UpdateGroupRequest(String name, String groupType, String announcement) {}
|
||||
public record WebhookConfigRequest(String url, String secret, Boolean enabled) {}
|
||||
public record KeywordFilterRequest(String pattern, String replacement, String action, Boolean enabled) {}
|
||||
}
|
||||
|
||||
@ -90,6 +90,21 @@ public class ImAccountService {
|
||||
return accountRepository.save(account);
|
||||
}
|
||||
|
||||
public ImAccountEntity updateAccount(
|
||||
String appId,
|
||||
String userId,
|
||||
String nickname,
|
||||
String avatar,
|
||||
ImAccountEntity.Gender gender,
|
||||
ImAccountEntity.Status status) {
|
||||
ImAccountEntity account = getAccount(appId, userId);
|
||||
if (nickname != null) account.setNickname(nickname);
|
||||
if (avatar != null) account.setAvatar(avatar);
|
||||
if (gender != null) account.setGender(gender);
|
||||
if (status != null) account.setStatus(status);
|
||||
return accountRepository.save(account);
|
||||
}
|
||||
|
||||
public ImAccountEntity importAccount(String appId, String userId, String nickname,
|
||||
String avatar, ImAccountEntity.Gender gender,
|
||||
ImAccountEntity.Status status) {
|
||||
|
||||
@ -54,7 +54,13 @@ public class ImGroupService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ImGroupEntity create(String appId, String name, String creatorId, List<String> memberIds, String groupType) {
|
||||
public ImGroupEntity create(
|
||||
String appId,
|
||||
String name,
|
||||
String creatorId,
|
||||
List<String> memberIds,
|
||||
String groupType,
|
||||
String announcement) {
|
||||
List<String> members = new ArrayList<>(memberIds);
|
||||
if (!members.contains(creatorId)) members.add(creatorId);
|
||||
|
||||
@ -66,7 +72,7 @@ public class ImGroupService {
|
||||
group.setCreatorId(creatorId);
|
||||
group.setMemberIds(toJson(members));
|
||||
group.setAdminIds(toJson(List.of(creatorId)));
|
||||
group.setAnnouncement(null);
|
||||
group.setAnnouncement(announcement);
|
||||
group.setCreatedAt(LocalDateTime.now());
|
||||
return groupRepository.save(group);
|
||||
}
|
||||
@ -155,12 +161,15 @@ public class ImGroupService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ImGroupEntity update(String groupId, String operatorId, String name, String announcement) {
|
||||
public ImGroupEntity update(String groupId, String operatorId, String name, String groupType, String announcement) {
|
||||
ImGroupEntity group = get(groupId);
|
||||
ensureCanManage(group, operatorId);
|
||||
if (name != null && !name.isBlank()) {
|
||||
group.setName(name);
|
||||
}
|
||||
if (groupType != null && !groupType.isBlank()) {
|
||||
group.setGroupType(normalizeGroupType(groupType));
|
||||
}
|
||||
if (announcement != null) {
|
||||
group.setAnnouncement(announcement);
|
||||
}
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户