After finalise with the internationarization of web part3
This commit is contained in:
parent
f2343dd4ee
commit
58b58c39a2
@ -782,10 +782,17 @@ export async function setEmailVerified(userId: string, verified: boolean): Promi
|
||||
|
||||
export async function countUsersWithRole(roleName: string): Promise<number> {
|
||||
const rows = await query<{ count: string }[]>(
|
||||
`SELECT COUNT(*)::text AS count
|
||||
FROM users u
|
||||
JOIN roles r ON r.id = u.role_id
|
||||
WHERE r.name = $1`,
|
||||
`SELECT COUNT(DISTINCT uid)::text AS count FROM (
|
||||
SELECT ur.user_id AS uid
|
||||
FROM user_roles ur
|
||||
JOIN roles r ON r.id = ur.role_id
|
||||
WHERE r.name = $1
|
||||
UNION
|
||||
SELECT u.id AS uid
|
||||
FROM users u
|
||||
JOIN roles r ON r.id = u.role_id
|
||||
WHERE r.name = $1
|
||||
) t`,
|
||||
[roleName]
|
||||
);
|
||||
return parseInt(rows[0]?.count ?? '0', 10);
|
||||
|
||||
@ -34,17 +34,22 @@ function assertSetupToken(provided: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** True when at least one administrator exists (admin or super_admin in user_roles). */
|
||||
async function hasPlatformAdministrator(): Promise<boolean> {
|
||||
const adminCount = await roleRepository.countUsersWithRoleName('admin');
|
||||
const superAdminCount = await roleRepository.countUsersWithRoleName('super_admin');
|
||||
return adminCount > 0 || superAdminCount > 0;
|
||||
}
|
||||
|
||||
export async function getSetupStatus(): Promise<SetupStatus> {
|
||||
const adminCount = await userRepository.countUsersWithRole('admin');
|
||||
return {
|
||||
needsSetup: adminCount === 0,
|
||||
needsSetup: !(await hasPlatformAdministrator()),
|
||||
setupEnabled: Boolean(config.setup.token && config.setup.token.length >= 16),
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureNoAdminYet(): Promise<void> {
|
||||
const adminCount = await userRepository.countUsersWithRole('admin');
|
||||
if (adminCount > 0) {
|
||||
if (await hasPlatformAdministrator()) {
|
||||
throw new Error('Platform setup is already complete. An administrator account exists.');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user