ФУНКЦИИ - NODEDC LAUNCHER: рабочий invite onboarding
This commit is contained in:
@@ -353,6 +353,30 @@ app.post("/api/profile/password", requireSession, asyncRoute(async (req, res) =>
|
||||
res.json({ data: result.data, ok: true });
|
||||
}));
|
||||
|
||||
app.get("/api/invites/:token", (req, res) => {
|
||||
try {
|
||||
res.json(controlPlaneStore.getInviteByToken(req.params.token));
|
||||
} catch (error) {
|
||||
sendInviteApiError(res, error);
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/invites/:token/accept", requireSession, asyncRoute(async (req, res) => {
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = await controlPlaneStore.acceptInvite(req.params.token, req.nodedcSession.user);
|
||||
} catch (error) {
|
||||
sendInviteApiError(res, error);
|
||||
return;
|
||||
}
|
||||
|
||||
const syncResult = await syncUsersToAuthentik(result.data, [result.user.id], req.nodedcSession.user);
|
||||
|
||||
publishControlPlaneEvent("invite.accepted", syncResult.userIds);
|
||||
res.json({ ...result, data: syncResult.data });
|
||||
}));
|
||||
|
||||
app.get("/api/admin/control-plane", requireLauncherAdmin, (req, res) => {
|
||||
res.json(controlPlaneStore.getSnapshot(req.nodedcSession.user));
|
||||
});
|
||||
@@ -759,6 +783,20 @@ function sanitizeNewPassword(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function sendInviteApiError(res, error) {
|
||||
const message = error instanceof Error ? error.message : "Инвайт недоступен";
|
||||
const status =
|
||||
message.includes("не найден")
|
||||
? 404
|
||||
: message.includes("другую почту")
|
||||
? 403
|
||||
: message.includes("истёк") || message.includes("отозван")
|
||||
? 410
|
||||
: 400;
|
||||
|
||||
res.status(status).json({ error: message });
|
||||
}
|
||||
|
||||
function sanitizeSelfProfilePatch(payload) {
|
||||
return {
|
||||
name: payload?.name,
|
||||
|
||||
Reference in New Issue
Block a user