Browse Source

feat(cli): list users (#1341)

Jason Rasmussen 2 years ago
parent
commit
adacfb1110

BIN
docs/docs/features/img/list-users.png


+ 5 - 0
docs/docs/features/server-commands.md

@@ -8,6 +8,7 @@ The `immich-server` docker image comes preinstalled with an administrative CLI (
 | `reset-admin-password`   | Reset the password for the admin user |
 | `disable-password-login` | Disable password login                |
 | `enable-password-login`  | Enable password login                 |
+| `list-users`             | List Immich users                     |
 
 ## How to run a command
 
@@ -26,3 +27,7 @@ Disable Password Login
 Enabled Password Login
 
 ![Enable Password Login](./img/enable-password-login.png)
+
+List Users
+
+![List Users](./img/list-users.png)

+ 2 - 0
server/apps/cli/src/app.module.ts

@@ -2,6 +2,7 @@ import { DomainModule } from '@app/domain';
 import { InfraModule, SystemConfigEntity } from '@app/infra';
 import { Module } from '@nestjs/common';
 import { TypeOrmModule } from '@nestjs/typeorm';
+import { ListUsersCommand } from './commands/list-users.command';
 import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './commands/password-login';
 import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command';
 
@@ -17,6 +18,7 @@ import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/r
     PromptPasswordQuestions,
     EnablePasswordLoginCommand,
     DisablePasswordLoginCommand,
+    ListUsersCommand,
   ],
 })
 export class AppModule {}

+ 23 - 0
server/apps/cli/src/commands/list-users.command.ts

@@ -0,0 +1,23 @@
+import { UserService } from '@app/domain';
+import { Command, CommandRunner } from 'nest-commander';
+import { CLI_USER } from '../constants';
+
+@Command({
+  name: 'list-users',
+  description: 'List Immich users',
+})
+export class ListUsersCommand extends CommandRunner {
+  constructor(private userService: UserService) {
+    super();
+  }
+
+  async run(): Promise<void> {
+    try {
+      const users = await this.userService.getAllUsers(CLI_USER, true);
+      console.dir(users);
+    } catch (error) {
+      console.error(error);
+      console.error('Unable to load users');
+    }
+  }
+}

+ 9 - 0
server/apps/cli/src/constants.ts

@@ -0,0 +1,9 @@
+import { AuthUserDto } from '@app/domain';
+
+export const CLI_USER: AuthUserDto = {
+  id: 'cli',
+  email: 'cli@immich.app',
+  isAdmin: true,
+  isPublicUser: false,
+  isAllowUpload: true,
+};