fix:删除白名单记录前先删玩家答题记录
This commit is contained in:
parent
65584bb8d8
commit
a8c3f70973
|
|
@ -129,7 +129,7 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
GET /api/whitelist/rejected
|
GET /api/whitelist/rejected
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns paginated list of rejected players (status=0).
|
Returns paginated list of rejected players (status=3).
|
||||||
|
|
||||||
**Parameters:** Same as `/list` (including `all`).
|
**Parameters:** Same as `/list` (including `all`).
|
||||||
|
|
||||||
|
|
@ -364,9 +364,9 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
||||||
| status | statusText |
|
| status | statusText |
|
||||||
|--------|------------|
|
|--------|------------|
|
||||||
| 0 | 已拒绝 (Rejected) |
|
|
||||||
| 1 | 已通过 (Approved) |
|
| 1 | 已通过 (Approved) |
|
||||||
| 2 | 待审核 (Pending) |
|
| 2 | 待审核 (Pending) |
|
||||||
|
| 3 | 已拒绝 (Rejected) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -409,7 +409,7 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
| playerName | String | Minecraft username |
|
| playerName | String | Minecraft username |
|
||||||
| uuid | String | Mojang account UUID |
|
| uuid | String | Mojang account UUID |
|
||||||
| qq | String | QQ number |
|
| qq | String | QQ number |
|
||||||
| status | Byte | 0=rejected, 1=approved, 2=pending |
|
| status | Byte | 1=approved, 2=pending, 3=rejected |
|
||||||
| description | String | Application note |
|
| description | String | Application note |
|
||||||
| createTime | String | Application timestamp (ISO 8601) |
|
| createTime | String | Application timestamp (ISO 8601) |
|
||||||
| regionCode | Long | Region postal code |
|
| regionCode | Long | Region postal code |
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
GET /api/whitelist/rejected
|
GET /api/whitelist/rejected
|
||||||
```
|
```
|
||||||
|
|
||||||
分页查询已被拒绝的玩家(status=0)。
|
分页查询已被拒绝的玩家(status=3)。
|
||||||
|
|
||||||
**请求参数:** 同 `/list`(含 `all` 参数)。
|
**请求参数:** 同 `/list`(含 `all` 参数)。
|
||||||
|
|
||||||
|
|
@ -350,9 +350,9 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
||||||
| status | statusText |
|
| status | statusText |
|
||||||
|--------|------------|
|
|--------|------------|
|
||||||
| 0 | 已拒绝 |
|
|
||||||
| 1 | 已通过 |
|
| 1 | 已通过 |
|
||||||
| 2 | 待审核 |
|
| 2 | 待审核 |
|
||||||
|
| 3 | 已拒绝 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -395,7 +395,7 @@ curl -H "X-API-TOKEN: <token>" \
|
||||||
| playerName | String | Minecraft 用户名 |
|
| playerName | String | Minecraft 用户名 |
|
||||||
| uuid | String | Mojang 正版 UUID |
|
| uuid | String | Mojang 正版 UUID |
|
||||||
| qq | String | QQ 号 |
|
| qq | String | QQ 号 |
|
||||||
| status | Byte | 0=已拒绝, 1=已通过, 2=待审核 |
|
| status | Byte | 1=已通过, 2=待审核, 3=已拒绝 |
|
||||||
| description | String | 申请备注 |
|
| description | String | 申请备注 |
|
||||||
| createTime | String | 申请时间(ISO 8601) |
|
| createTime | String | 申请时间(ISO 8601) |
|
||||||
| regionCode | Long | 地区邮政编码 |
|
| regionCode | Long | 地区邮政编码 |
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -10,7 +10,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.linearpast</groupId>
|
<groupId>com.linearpast</groupId>
|
||||||
<artifactId>MinecraftManager</artifactId>
|
<artifactId>MinecraftManager</artifactId>
|
||||||
<version>1.1.3</version>
|
<version>1.1.5</version>
|
||||||
<name>MinecraftManager</name>
|
<name>MinecraftManager</name>
|
||||||
<description>MinecraftManager</description>
|
<description>MinecraftManager</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class WhitelistController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取被拒绝列表(status=0)
|
* 获取被拒绝列表(status=3)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/rejected")
|
@GetMapping("/rejected")
|
||||||
public Result<?> getRejected(
|
public Result<?> getRejected(
|
||||||
|
|
@ -72,7 +72,7 @@ public class WhitelistController {
|
||||||
) {
|
) {
|
||||||
Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size);
|
Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size);
|
||||||
Page<PlayerInfoView> players = playersService.getPlayers(
|
Page<PlayerInfoView> players = playersService.getPlayers(
|
||||||
playerName, null, null, (byte) 0,
|
playerName, null, null, (byte) 3,
|
||||||
null, null, pageable
|
null, null, pageable
|
||||||
);
|
);
|
||||||
return Result.successPage(players.getContent(), players.getTotalElements());
|
return Result.successPage(players.getContent(), players.getTotalElements());
|
||||||
|
|
@ -94,7 +94,7 @@ public class WhitelistController {
|
||||||
@PostMapping("/reject/{id}")
|
@PostMapping("/reject/{id}")
|
||||||
public Result<?> reject(@PathVariable Integer id, HttpSession session) {
|
public Result<?> reject(@PathVariable Integer id, HttpSession session) {
|
||||||
Operators operators = (Operators) session.getAttribute("adminAccount");
|
Operators operators = (Operators) session.getAttribute("adminAccount");
|
||||||
int code = playersService.updatePlayerStatus(id, (byte) 0, operators);
|
int code = playersService.updatePlayerStatus(id, (byte) 3, operators);
|
||||||
return code > 0 ? Result.success().msg("已拒绝申请") : Result.error("操作失败,Rcon连接错误或玩家不存在");
|
return code > 0 ? Result.success().msg("已拒绝申请") : Result.error("操作失败,Rcon连接错误或玩家不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ public class WhitelistController {
|
||||||
@PostMapping("/batchReject")
|
@PostMapping("/batchReject")
|
||||||
public Result<?> batchReject(@RequestBody List<Integer> ids, HttpSession session) {
|
public Result<?> batchReject(@RequestBody List<Integer> ids, HttpSession session) {
|
||||||
Operators operators = (Operators) session.getAttribute("adminAccount");
|
Operators operators = (Operators) session.getAttribute("adminAccount");
|
||||||
int code = playersService.updatePlayersStatus(ids, (byte) 0, operators);
|
int code = playersService.updatePlayersStatus(ids, (byte) 3, operators);
|
||||||
return code > 0 ? Result.success().msg("成功处理:" + code + "/" + ids.size()) : Result.error("操作失败");
|
return code > 0 ? Result.success().msg("成功处理:" + code + "/" + ids.size()) : Result.error("操作失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ public class WhitelistController {
|
||||||
Map<String, Object> stats = new HashMap<>();
|
Map<String, Object> stats = new HashMap<>();
|
||||||
stats.put("approved", playersService.getPlayersCountByStatus((byte) 1));
|
stats.put("approved", playersService.getPlayersCountByStatus((byte) 1));
|
||||||
stats.put("pending", playersService.getPlayersCountByStatus((byte) 2));
|
stats.put("pending", playersService.getPlayersCountByStatus((byte) 2));
|
||||||
stats.put("rejected", playersService.getPlayersCountByStatus((byte) 0));
|
stats.put("rejected", playersService.getPlayersCountByStatus((byte) 3));
|
||||||
return Result.success(stats);
|
return Result.success(stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.linearpast.minecraftmanager.entity.Players;
|
||||||
import com.linearpast.minecraftmanager.entity.view.PlayerInfoView;
|
import com.linearpast.minecraftmanager.entity.view.PlayerInfoView;
|
||||||
import com.linearpast.minecraftmanager.repository.PlayersRepository;
|
import com.linearpast.minecraftmanager.repository.PlayersRepository;
|
||||||
import com.linearpast.minecraftmanager.repository.view.PlayerInfoViewRepository;
|
import com.linearpast.minecraftmanager.repository.view.PlayerInfoViewRepository;
|
||||||
|
import com.linearpast.minecraftmanager.service.inter.PlayerAnswersService;
|
||||||
import com.linearpast.minecraftmanager.service.inter.PlayersService;
|
import com.linearpast.minecraftmanager.service.inter.PlayersService;
|
||||||
import com.linearpast.minecraftmanager.utils.WhitelistTarget;
|
import com.linearpast.minecraftmanager.utils.WhitelistTarget;
|
||||||
import com.linearpast.minecraftmanager.utils.config.ConfigLoader;
|
import com.linearpast.minecraftmanager.utils.config.ConfigLoader;
|
||||||
|
|
@ -44,6 +45,8 @@ public class PlayersServiceImpl implements PlayersService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlayerInfoViewRepository playerInfoViewRepository;
|
private PlayerInfoViewRepository playerInfoViewRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private PlayerAnswersService playerAnswersService;
|
||||||
|
@Autowired
|
||||||
private MinecraftRconUtils rconService;
|
private MinecraftRconUtils rconService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private JavaMailSenderImpl mailSender;
|
private JavaMailSenderImpl mailSender;
|
||||||
|
|
@ -76,13 +79,18 @@ public class PlayersServiceImpl implements PlayersService {
|
||||||
if(minecraftRcon == null) return false;
|
if(minecraftRcon == null) return false;
|
||||||
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(byId.getPlayerName()), WhiteListModes.REMOVE));
|
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(byId.getPlayerName()), WhiteListModes.REMOVE));
|
||||||
if(response.getResponseId() != 0) return false;
|
if(response.getResponseId() != 0) return false;
|
||||||
this.asyncSendEmail(byId, (byte)0, true);
|
this.asyncSendEmail(byId, (byte)3, true);
|
||||||
|
playerAnswersService.deleteAllPlayerAnswers(byId);
|
||||||
playersRepository.deleteById(id);
|
playersRepository.deleteById(id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceDeletePlayer(List<Integer> ids) {
|
public void forceDeletePlayer(List<Integer> ids) {
|
||||||
|
List<Players> players = playersRepository.findAllById(ids);
|
||||||
|
for (Players player : players) {
|
||||||
|
playerAnswersService.deleteAllPlayerAnswers(player);
|
||||||
|
}
|
||||||
playersRepository.deleteAllById(ids);
|
playersRepository.deleteAllById(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +173,8 @@ public class PlayersServiceImpl implements PlayersService {
|
||||||
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(players.getPlayerName()), WhiteListModes.REMOVE));
|
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(players.getPlayerName()), WhiteListModes.REMOVE));
|
||||||
if (response.getResponseId() == 0) {
|
if (response.getResponseId() == 0) {
|
||||||
successIds.add(players.getId());
|
successIds.add(players.getId());
|
||||||
asyncSendEmail(players, (byte) 0, true);
|
asyncSendEmail(players, (byte) 3, true);
|
||||||
|
playerAnswersService.deleteAllPlayerAnswers(players);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
playersRepository.deleteAllById(successIds);
|
playersRepository.deleteAllById(successIds);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class WhitelistControllerTest {
|
||||||
@Test
|
@Test
|
||||||
void getRejected_shouldReturnPage() throws Exception {
|
void getRejected_shouldReturnPage() throws Exception {
|
||||||
Page<PlayerInfoView> page = new PageImpl<>(Collections.emptyList());
|
Page<PlayerInfoView> page = new PageImpl<>(Collections.emptyList());
|
||||||
when(playersService.getPlayers(isNull(), isNull(), isNull(), eq((byte) 0),
|
when(playersService.getPlayers(isNull(), isNull(), isNull(), eq((byte) 3),
|
||||||
isNull(), isNull(), any(Pageable.class))).thenReturn(page);
|
isNull(), isNull(), any(Pageable.class))).thenReturn(page);
|
||||||
|
|
||||||
mockMvc.perform(get("/api/whitelist/rejected"))
|
mockMvc.perform(get("/api/whitelist/rejected"))
|
||||||
|
|
@ -149,7 +149,7 @@ class WhitelistControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void reject_success() throws Exception {
|
void reject_success() throws Exception {
|
||||||
when(playersService.updatePlayerStatus(eq(1), eq((byte) 0), any(Operators.class))).thenReturn(1);
|
when(playersService.updatePlayerStatus(eq(1), eq((byte) 3), any(Operators.class))).thenReturn(1);
|
||||||
|
|
||||||
mockMvc.perform(post("/api/whitelist/reject/1").session(adminSession))
|
mockMvc.perform(post("/api/whitelist/reject/1").session(adminSession))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|
@ -159,7 +159,7 @@ class WhitelistControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void reject_failure() throws Exception {
|
void reject_failure() throws Exception {
|
||||||
when(playersService.updatePlayerStatus(eq(99), eq((byte) 0), any(Operators.class))).thenReturn(0);
|
when(playersService.updatePlayerStatus(eq(99), eq((byte) 3), any(Operators.class))).thenReturn(0);
|
||||||
|
|
||||||
mockMvc.perform(post("/api/whitelist/reject/99").session(adminSession))
|
mockMvc.perform(post("/api/whitelist/reject/99").session(adminSession))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|
@ -234,7 +234,7 @@ class WhitelistControllerTest {
|
||||||
@Test
|
@Test
|
||||||
void batchReject_success() throws Exception {
|
void batchReject_success() throws Exception {
|
||||||
List<Integer> ids = List.of(1, 2);
|
List<Integer> ids = List.of(1, 2);
|
||||||
when(playersService.updatePlayersStatus(eq(ids), eq((byte) 0), any(Operators.class))).thenReturn(2);
|
when(playersService.updatePlayersStatus(eq(ids), eq((byte) 3), any(Operators.class))).thenReturn(2);
|
||||||
|
|
||||||
mockMvc.perform(post("/api/whitelist/batchReject")
|
mockMvc.perform(post("/api/whitelist/batchReject")
|
||||||
.session(adminSession)
|
.session(adminSession)
|
||||||
|
|
@ -277,7 +277,7 @@ class WhitelistControllerTest {
|
||||||
void getStats_shouldReturnCounts() throws Exception {
|
void getStats_shouldReturnCounts() throws Exception {
|
||||||
when(playersService.getPlayersCountByStatus((byte) 1)).thenReturn(10);
|
when(playersService.getPlayersCountByStatus((byte) 1)).thenReturn(10);
|
||||||
when(playersService.getPlayersCountByStatus((byte) 2)).thenReturn(5);
|
when(playersService.getPlayersCountByStatus((byte) 2)).thenReturn(5);
|
||||||
when(playersService.getPlayersCountByStatus((byte) 0)).thenReturn(3);
|
when(playersService.getPlayersCountByStatus((byte) 3)).thenReturn(3);
|
||||||
|
|
||||||
mockMvc.perform(get("/api/whitelist/stats"))
|
mockMvc.perform(get("/api/whitelist/stats"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|
@ -332,7 +332,7 @@ class WhitelistControllerTest {
|
||||||
@Test
|
@Test
|
||||||
void checkPlayer_rejectedStatus() throws Exception {
|
void checkPlayer_rejectedStatus() throws Exception {
|
||||||
Players player = new Players();
|
Players player = new Players();
|
||||||
player.setStatus((byte) 0);
|
player.setStatus((byte) 3);
|
||||||
|
|
||||||
when(playersService.getPlayer("RejectedGuy")).thenReturn(player);
|
when(playersService.getPlayer("RejectedGuy")).thenReturn(player);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user