Add mark-admin command (#5705)

* mark-admin command

* no cli
This commit is contained in:
MeiMei 2020-01-20 01:50:12 +09:00 committed by syuilo
parent 85971d3d88
commit 10f237be95
8 changed files with 41 additions and 22 deletions

1
.github/CODEOWNERS vendored
View File

@ -6,7 +6,6 @@
/.github/ @syuilo @AyaMorisawa @acid-chicken /.github/ @syuilo @AyaMorisawa @acid-chicken
/.vscode/ @acid-chicken /.vscode/ @acid-chicken
/assets/ @syuilo # @tamaina /assets/ @syuilo # @tamaina
/cli/ @syuilo
/docs/ @syuilo /docs/ @syuilo
/docs/*.en.md @AyaMorisawa # @skid9000 /docs/*.en.md @AyaMorisawa # @skid9000
# /docs/*.fr.md @BoFFire # /docs/*.fr.md @BoFFire

View File

@ -88,7 +88,7 @@ Just `docker-compose up -d`. GLHF!
7. `docker-compose stop && docker-compose up -d` 7. `docker-compose stop && docker-compose up -d`
### How to execute [cli commands](manage.en.md): ### How to execute [cli commands](manage.en.md):
`docker-compose run --rm web node cli/mark-admin @example` `docker-compose run --rm web node built/tools/mark-admin @example`
---------------------------------------------------------------- ----------------------------------------------------------------

View File

@ -55,7 +55,7 @@ Utilisez la commande `docker-compose up -d`. GLHF!
7. `docker-compose stop && docker-compose up -d` 7. `docker-compose stop && docker-compose up -d`
### Comment exécuter des [commandes](manage.fr.md) ### Comment exécuter des [commandes](manage.fr.md)
`docker-compose run --rm web node cli/mark-admin @example` `docker-compose run --rm web node built/tools/mark-admin @example`
### Configuration d'ElasticSearch (pour la fonction de recherche) ### Configuration d'ElasticSearch (pour la fonction de recherche)
*1.* Préparation de l'environnement *1.* Préparation de l'environnement

View File

@ -89,7 +89,7 @@ docker-compose run --rm web yarn run init
### cliコマンドを実行する方法: ### cliコマンドを実行する方法:
`docker-compose run --rm web node cli/mark-admin @example` `docker-compose run --rm web node built/tools/mark-admin @example`
---------------------------------------------------------------- ----------------------------------------------------------------

View File

@ -5,14 +5,10 @@ coming soon
## Mark as 'admin' user ## Mark as 'admin' user
``` shell ``` shell
node cli/mark-admin (User-ID or Username) node built/tools/mark-admin (Username)
``` ```
e.g. e.g.
``` shell ``` shell
# By id node built/tools/mark-admin @syuilo
node cli/mark-admin 57d01a501fdf2d07be417afe
# By username
node cli/suspend @syuilo
``` ```

View File

@ -5,14 +5,10 @@ coming soon
## Marquer un utilisateur en tant que 'admin' ## Marquer un utilisateur en tant que 'admin'
``` shell ``` shell
node cli/mark-admin (ID utilisateur ou nom d'utilisateur) node built/tools/mark-admin (nom d'utilisateur)
``` ```
Exemple : Exemple :
``` shell ``` shell
# Par id node built/tools/mark-admin @syuilo
node cli/mark-admin 57d01a501fdf2d07be417afe
# Par nom d'utilisateur
node cli/suspend @syuilo
``` ```

View File

@ -5,14 +5,10 @@ coming soon
## 管理者ユーザーを設定する ## 管理者ユーザーを設定する
``` shell ``` shell
node cli/mark-admin (ユーザーID または ユーザー名) node built/tools/mark-admin (ユーザー名)
``` ```
例: 例:
``` shell ``` shell
# ユーザーID node built/tools/mark-admin @syuilo
node cli/mark-admin 57d01a501fdf2d07be417afe
# ユーザー名
node cli/mark-admin @syuilo
``` ```

32
src/tools/mark-admin.ts Normal file
View File

@ -0,0 +1,32 @@
import { initDb } from '../db/postgre';
import { getRepository } from 'typeorm';
import { User } from '../models/entities/user';
async function main(username: string) {
if (!username) throw `username required`;
username = username.replace(/^@/, '');
await initDb();
const Users = getRepository(User);
const res = await Users.update({
usernameLower: username.toLowerCase(),
host: null
}, {
isAdmin: true
});
if (res.affected !== 1) {
throw 'Failed';
}
}
const args = process.argv.slice(2);
main(args[0]).then(() => {
console.log('Success');
process.exit(0);
}).catch(e => {
console.error(`Error: ${e.message || e}`);
process.exit(1);
});