From ac50bb92252d999e6417eaaa585fd957f52d59cf Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 6 Nov 2018 06:24:31 +0900 Subject: [PATCH] Resolve #3137 --- .config/example.yml | 4 ++++ src/config/load.ts | 2 ++ src/config/types.ts | 2 ++ src/server/api/private/signup.ts | 3 +++ 4 files changed, 11 insertions(+) diff --git a/.config/example.yml b/.config/example.yml index 0265c8cc2..44c58ccf3 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -110,6 +110,10 @@ drive: # accessKey: XXX # secretKey: YYY +# If enabled: +# The first account created is automatically marked as Admin. +autoAdmin: true + # # Below settings are optional # diff --git a/src/config/load.ts b/src/config/load.ts index 738d6427f..56a8ff0ab 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -49,6 +49,8 @@ export default function load() { if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256; if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8; + if (config.autoAdmin == null) config.autoAdmin = false; + return Object.assign(config, mixin); } diff --git a/src/config/types.ts b/src/config/types.ts index a3c761cc6..f5049beb8 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -58,6 +58,8 @@ export type Source = { config?: any; }; + autoAdmin?: boolean; + /** * ゴーストアカウントのID */ diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index d6eba6981..ab7342d6b 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -67,6 +67,8 @@ export default async (ctx: Koa.Context) => { return; } + const usersCount = await User.count({}); + // Fetch exist user that same username const usernameExist = await User .count({ @@ -106,6 +108,7 @@ export default async (ctx: Koa.Context) => { token: secret, email: null, password: hash, + isAdmin: config.autoAdmin && usersCount === 0, profile: { bio: null, birthday: null,