Auto-sync Fri Feb 13 08:51:24 UTC 2026
This commit is contained in:
72
g/all/setup_app.app/change_account.inline_script.deno.ts
Normal file
72
g/all/setup_app.app/change_account.inline_script.deno.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import * as wmill from "https://deno.land/x/windmill@v1.99.0/mod.ts";
|
||||
|
||||
export async function main(
|
||||
oldEmail: string,
|
||||
newEmail: string,
|
||||
newPassword: string,
|
||||
enable_hub_sync: boolean,
|
||||
sync_now: boolean,
|
||||
) {
|
||||
try {
|
||||
await wmill.UserService.createUserGlobally({
|
||||
requestBody: {
|
||||
email: newEmail,
|
||||
password: newPassword,
|
||||
super_admin: true,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw Error("User already exists: " + e.body);
|
||||
}
|
||||
|
||||
let new_token;
|
||||
|
||||
try {
|
||||
new_token = await wmill.UserService.login({
|
||||
requestBody: {
|
||||
email: newEmail,
|
||||
password: newPassword,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw Error("Login failed: " + e.body);
|
||||
}
|
||||
|
||||
wmill.setClient(new_token, Deno.env.get("BASE_INTERNAL_URL")!);
|
||||
|
||||
if (sync_now) {
|
||||
try {
|
||||
await wmill.JobService.runScriptByPath({
|
||||
workspace: "admins",
|
||||
path: "u/admin/hub_sync",
|
||||
requestBody: {},
|
||||
});
|
||||
} catch (e) {
|
||||
throw Error("Hub sync failed:" + e.body);
|
||||
}
|
||||
}
|
||||
|
||||
if (enable_hub_sync) {
|
||||
try {
|
||||
await wmill.ScheduleService.createSchedule({
|
||||
workspace: "admins",
|
||||
requestBody: {
|
||||
path: "g/all/hub_sync",
|
||||
schedule: "0 0 0 * * *",
|
||||
script_path: "u/admin/hub_sync",
|
||||
is_flow: false,
|
||||
args: {},
|
||||
enabled: true,
|
||||
timezone: "Etc/UTC",
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw Error("Error creating schedule: " + e.body);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await wmill.UserService.globalUserDelete({ email: oldEmail });
|
||||
} catch (e) {
|
||||
throw Error("Deleting old account failed: " + e.body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user