mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
refactor(server): immich-admin list-users (#8862)
This commit is contained in:
parent
c227f9893e
commit
3a9df6dae8
5 changed files with 36 additions and 20 deletions
19
e2e/src/immich-admin/specs/immich-admin.e2e-spec.ts
Normal file
19
e2e/src/immich-admin/specs/immich-admin.e2e-spec.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { immichAdmin, utils } from 'src/utils';
|
||||||
|
import { beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
describe(`immich-admin`, () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await utils.resetDatabase();
|
||||||
|
await utils.adminSetup();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('list-users', () => {
|
||||||
|
it('should list the admin user', async () => {
|
||||||
|
const { stdout, stderr, exitCode } = await immichAdmin(['list-users']);
|
||||||
|
expect(exitCode).toBe(0);
|
||||||
|
expect(stderr).toBe('');
|
||||||
|
expect(stdout).toContain("email: 'admin@immich.cloud'");
|
||||||
|
expect(stdout).toContain("name: 'Immich Admin'");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -43,7 +43,7 @@ import { loginDto, signupDto } from 'src/fixtures';
|
||||||
import { makeRandomImage } from 'src/generators';
|
import { makeRandomImage } from 'src/generators';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
|
|
||||||
type CliResponse = { stdout: string; stderr: string; exitCode: number | null };
|
type CommandResponse = { stdout: string; stderr: string; exitCode: number | null };
|
||||||
type EventType = 'assetUpload' | 'assetUpdate' | 'assetDelete' | 'userDelete';
|
type EventType = 'assetUpload' | 'assetUpdate' | 'assetDelete' | 'userDelete';
|
||||||
type WaitOptions = { event: EventType; id?: string; total?: number; timeout?: number };
|
type WaitOptions = { event: EventType; id?: string; total?: number; timeout?: number };
|
||||||
type AdminSetupOptions = { onboarding?: boolean };
|
type AdminSetupOptions = { onboarding?: boolean };
|
||||||
|
@ -59,13 +59,15 @@ export const testAssetDirInternal = '/data/assets';
|
||||||
export const tempDir = tmpdir();
|
export const tempDir = tmpdir();
|
||||||
export const asBearerAuth = (accessToken: string) => ({ Authorization: `Bearer ${accessToken}` });
|
export const asBearerAuth = (accessToken: string) => ({ Authorization: `Bearer ${accessToken}` });
|
||||||
export const asKeyAuth = (key: string) => ({ 'x-api-key': key });
|
export const asKeyAuth = (key: string) => ({ 'x-api-key': key });
|
||||||
export const immichCli = async (args: string[]) => {
|
export const immichCli = (args: string[]) =>
|
||||||
let _resolve: (value: CliResponse) => void;
|
executeCommand('node', ['node_modules/.bin/immich', '-d', `/${tempDir}/immich/`, ...args]);
|
||||||
const deferred = new Promise<CliResponse>((resolve) => (_resolve = resolve));
|
export const immichAdmin = (args: string[]) =>
|
||||||
const _args = ['node_modules/.bin/immich', '-d', `/${tempDir}/immich/`, ...args];
|
executeCommand('docker', ['exec', '-i', 'immich-e2e-server', '/bin/bash', '-c', `immich-admin ${args.join(' ')}`]);
|
||||||
const child = spawn('node', _args, {
|
|
||||||
stdio: 'pipe',
|
const executeCommand = (command: string, args: string[]) => {
|
||||||
});
|
let _resolve: (value: CommandResponse) => void;
|
||||||
|
const deferred = new Promise<CommandResponse>((resolve) => (_resolve = resolve));
|
||||||
|
const child = spawn(command, args, { stdio: 'pipe' });
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
|
|
|
@ -10,7 +10,7 @@ try {
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
include: ['src/{api,cli}/specs/*.e2e-spec.ts'],
|
include: ['src/{api,cli,immich-admin}/specs/*.e2e-spec.ts'],
|
||||||
globalSetup,
|
globalSetup,
|
||||||
testTimeout: 15_000,
|
testTimeout: 15_000,
|
||||||
poolOptions: {
|
poolOptions: {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Command, CommandRunner } from 'nest-commander';
|
import { Command, CommandRunner } from 'nest-commander';
|
||||||
import { UserEntity } from 'src/entities/user.entity';
|
|
||||||
import { UserService } from 'src/services/user.service';
|
import { UserService } from 'src/services/user.service';
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
|
@ -13,16 +12,7 @@ export class ListUsersCommand extends CommandRunner {
|
||||||
|
|
||||||
async run(): Promise<void> {
|
async run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const users = await this.userService.getAll(
|
const users = await this.userService.listUsers();
|
||||||
{
|
|
||||||
user: {
|
|
||||||
id: 'cli',
|
|
||||||
email: 'cli@immich.app',
|
|
||||||
isAdmin: true,
|
|
||||||
} as UserEntity,
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
console.dir(users);
|
console.dir(users);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
@ -37,6 +37,11 @@ export class UserService {
|
||||||
this.configCore = SystemConfigCore.create(configRepository, this.logger);
|
this.configCore = SystemConfigCore.create(configRepository, this.logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async listUsers(): Promise<UserResponseDto[]> {
|
||||||
|
const users = await this.userRepository.getList({ withDeleted: true });
|
||||||
|
return users.map((user) => mapUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
async getAll(auth: AuthDto, isAll: boolean): Promise<UserResponseDto[]> {
|
async getAll(auth: AuthDto, isAll: boolean): Promise<UserResponseDto[]> {
|
||||||
const users = await this.userRepository.getList({ withDeleted: !isAll });
|
const users = await this.userRepository.getList({ withDeleted: !isAll });
|
||||||
return users.map((user) => mapUser(user));
|
return users.map((user) => mapUser(user));
|
||||||
|
|
Loading…
Add table
Reference in a new issue