1
This commit is contained in:
@@ -55,6 +55,27 @@ module.exports = {
|
||||
});
|
||||
ctx.success({ id: row.id, status: row.status });
|
||||
},
|
||||
"POST /biz_token/regenerate": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const result = await tokenLogic.regenerateToken(body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: result.row.user_id,
|
||||
action: "biz_token.regenerate",
|
||||
resource_type: "biz_api_token",
|
||||
resource_id: result.row.id,
|
||||
detail: { token_name: result.row.token_name },
|
||||
});
|
||||
ctx.success({
|
||||
id: result.row.id,
|
||||
user_id: result.row.user_id,
|
||||
plan_id: result.row.plan_id,
|
||||
token_name: result.row.token_name,
|
||||
expire_at: result.row.expire_at,
|
||||
plain_token: result.plain_token,
|
||||
warn: result.warn,
|
||||
});
|
||||
},
|
||||
"POST /biz_token/export": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const param = body.param || body;
|
||||
|
||||
@@ -46,7 +46,40 @@ module.exports = {
|
||||
resource_id: row.id,
|
||||
detail: { name: row.name },
|
||||
});
|
||||
ctx.success(row);
|
||||
|
||||
const out = row.get({ plain: true });
|
||||
let plain_token = null;
|
||||
let token_warn = null;
|
||||
let token_error = null;
|
||||
const auto_token = body.auto_create_token !== false;
|
||||
if (auto_token && row.status === "active") {
|
||||
try {
|
||||
const result = await tokenLogic.createToken({
|
||||
user_id: row.id,
|
||||
token_name: body.initial_token_name || "default",
|
||||
expire_at: body.initial_token_expire_at || tokenLogic.defaultTokenExpireAt(),
|
||||
});
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: row.id,
|
||||
action: "biz_token.create",
|
||||
resource_type: "biz_api_token",
|
||||
resource_id: result.row.id,
|
||||
detail: { token_name: result.row.token_name, via: "biz_user.add" },
|
||||
});
|
||||
plain_token = result.plain_token;
|
||||
token_warn = result.warn;
|
||||
} catch (e) {
|
||||
token_error = e.message || String(e);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.success({
|
||||
...out,
|
||||
plain_token,
|
||||
token_warn,
|
||||
token_error,
|
||||
});
|
||||
},
|
||||
"POST /biz_user/edit": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
|
||||
Reference in New Issue
Block a user