From c3a7e25f582d27808abd18beee2d4275e1c97108 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Tue, 29 Oct 2024 13:14:17 +0100 Subject: [PATCH] syn2mas: import the admin flag on users --- tools/syn2mas/src/advisor.mts | 9 --------- tools/syn2mas/src/migrate.mts | 5 ++++- tools/syn2mas/src/types/MUser.d.ts | 4 +++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/syn2mas/src/advisor.mts b/tools/syn2mas/src/advisor.mts index b2b7ae86e..e67aa119c 100644 --- a/tools/syn2mas/src/advisor.mts +++ b/tools/syn2mas/src/advisor.mts @@ -82,15 +82,6 @@ export async function advisor(): Promise { return res["count(*)"] as number; } - const adminUsers = await count( - synapse.count("*").from("users").where({ admin: 1 }), - ); - if (adminUsers > 0) { - warn( - `Synapse database contains ${adminUsers} admin users which will need to be added to the MAS configuration.`, - ); - } - const guestUsers = await count( synapse.count("*").from("users").where({ is_guest: 1 }), ); diff --git a/tools/syn2mas/src/migrate.mts b/tools/syn2mas/src/migrate.mts index 8f5d7bbba..7433b95a1 100644 --- a/tools/syn2mas/src/migrate.mts +++ b/tools/syn2mas/src/migrate.mts @@ -19,6 +19,7 @@ import type { MCompatRefreshToken } from "./types/MCompatRefreshToken.d.ts"; import type { MCompatSession } from "./types/MCompatSession.d.ts"; import type { MUpstreamOauthLink } from "./types/MUpstreamOauthLink.d.ts"; import type { MUpstreamOauthProvider } from "./types/MUpstreamOauthProvider.d.ts"; +import type { MUser } from "./types/MUser.js"; import type { MUserEmail } from "./types/MUserEmail.d.ts"; import type { MUserPassword } from "./types/MUserPassword.d.ts"; import type { SAccessToken } from "./types/SAccessToken.d.ts"; @@ -207,11 +208,13 @@ export async function migrate(): Promise { const userCreatedAt = new Date( Number.parseInt(`${user.creation_ts}`) * 1000, ); - const masUser = { + const masUser: MUser = { user_id: makeUuid(userCreatedAt), username: localpart, created_at: userCreatedAt, locked_at: user.deactivated === 1 ? userCreatedAt : null, + primary_user_email_id: null, + can_request_admin: user.admin === 1, }; executions.push(() => mas.insert(masUser).into("users")); log.debug(`${stringifyAndRedact(user)} => ${stringifyAndRedact(masUser)}`); diff --git a/tools/syn2mas/src/types/MUser.d.ts b/tools/syn2mas/src/types/MUser.d.ts index 1f30d13e8..7e5328b93 100644 --- a/tools/syn2mas/src/types/MUser.d.ts +++ b/tools/syn2mas/src/types/MUser.d.ts @@ -12,5 +12,7 @@ export interface MUser { user_id: UUID; username: string; // localpart only without @ created_at: Date; - primary_user_email_id?: UUID; + locked_at: Date | null; + primary_user_email_id: UUID | null; + can_request_admin: boolean; }