Skip to content

Commit

Permalink
fix(mis-server): 创建账户并判断为不封锁账户时,集群下没有实现对帐户的解封 (#1295)
Browse files Browse the repository at this point in the history
### 问题

当前scow及集群中创建账户的逻辑为
1. 在scow中创建账户,且通过判断当前租户封锁阈值在数据库中写入集群中应为的封锁状态
2. 在当前可用集群中创建账户,并写入账户与账户拥有者的关联
3. 在当前可用集群中根据1中计算的封锁状态值实现在集群中的封锁或解封
4. 2或3失败时对1中创建的数据进行回滚

当前只实现了3中的封锁并没有单独执行解封导致题目的问题

### 修复
补充上述3中,根据封锁阈值判断应为解封的情况,调用适配器接口在集群中实现对帐户的解封

租户默认封锁阈值为0时,应为在集群中封锁状态

![image](https://github.com/PKUHPC/SCOW/assets/43978285/78a02f03-fe81-46d8-9dff-488d50b41915)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/0552a0fe-0260-45e7-a431-3fd8c903d476)

修改租户默认封锁阈值为负数时,应为在集群中解封状态

![image](https://github.com/PKUHPC/SCOW/assets/43978285/247f0f4c-cfc1-490c-800a-304c053ed610)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/b0792768-dff8-4585-b742-b16bb9d63f11)

![image](https://github.com/PKUHPC/SCOW/assets/43978285/f3c314bf-0317-42de-af98-af87d1351cd5)
  • Loading branch information
piccaSun authored Jun 13, 2024
1 parent 5a707df commit d427530
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quiet-adults-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-server": patch
---

修复创建账户且判断为需要解封时未在集群中执行解封操作的问题
2 changes: 2 additions & 0 deletions apps/mis-server/src/bl/importUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ export async function importUsers(data: ImportUsersData, em: SqlEntityManager,
// 如果不选择全部添加白名单时,判断租户默认阈值选择是否在集群中封锁账户
} else {
const shouldBlockInCluster = tenant.defaultAccountBlockThreshold.gte(0);
// 只判断当前为未在集群中封锁的账户
const shouldBlockAccounts = accounts.filter((a) => !a.blockedInCluster);

// 判断封锁阈值需要封锁时
if (shouldBlockInCluster) {
await Promise.allSettled(shouldBlockAccounts.map((acc) => {
return em.transactional(async (em) => {
Expand Down
16 changes: 15 additions & 1 deletion apps/mis-server/src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,27 @@ export const accountServiceServer = plugin((server) => {
accountName, ownerUserId: ownerId,
});

// 判断为需在集群中封锁时
if (shouldBlockInCluster) {
await asyncClientCall(client.account, "blockAccount", {
accountName,
}).catch((e) => {
if (e.code === Status.NOT_FOUND) {
throw <ServiceError>{
code: Status.INTERNAL, message: `Account ${accountName} hasn't been created. block failed`,
code: Status.INTERNAL, message: `Account ${accountName} hasn't been created. Block failed`,
};
} else {
throw e;
}
});
// 判断为需在集群中解封时
} else {
await asyncClientCall(client.account, "unblockAccount", {
accountName,
}).catch((e) => {
if (e.code === Status.NOT_FOUND) {
throw <ServiceError>{
code: Status.INTERNAL, message: `Account ${accountName} hasn't been created. Unblock failed`,
};
} else {
throw e;
Expand Down

0 comments on commit d427530

Please sign in to comment.