feat(auth): login screen and domain-scoped navigation
Session login against /auth/*, with a guard on every route and an interceptor that returns to the login on 401. The header, the import workspace and both governance panels only offer the account's own domains (auth/dominios.ts), and a batch opens on the account's database. The sign-in screen follows the app's palette: logo above the title, the action button in the shared tokens, and no register or password-recovery rows.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
aria-label="Base de datos destino"
|
||||
[matTooltip]="store.domainLocked() ? 'Una carga va a una sola base; quita los flujos para cambiarla' : 'Base de datos destino'"
|
||||
>
|
||||
@for (domain of domains; track domain.id) {
|
||||
@for (domain of domains(); track domain.id) {
|
||||
<mat-button-toggle [value]="domain.id" [attr.aria-label]="domain.description">{{ domain.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, Injector, inject, signal } from '@angular/core';
|
||||
import { Component, Injector, computed, inject, signal } from '@angular/core';
|
||||
import { MatBadgeModule } from '@angular/material/badge';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
@@ -12,6 +12,8 @@ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Domain, TargetMeta } from '../../api/api.types';
|
||||
import { AuthService } from '../../../auth/auth.service';
|
||||
import { dominiosPermitidos } from '../../../auth/dominios';
|
||||
import { DataConnection, SourceTable } from '../../domain/data-source';
|
||||
import { PdfConnection } from '../../domain/pdf-source';
|
||||
import { SqlConnection } from '../../domain/sql-source';
|
||||
@@ -59,11 +61,13 @@ import { SqlQueryDialog, SqlQueryResult } from '../sql-query-dialog/sql-query-di
|
||||
})
|
||||
export class ConnectPage {
|
||||
readonly store = inject(ConnectWorkspaceStore);
|
||||
private readonly auth = inject(AuthService);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly injector = inject(Injector);
|
||||
|
||||
readonly domains = DOMAINS;
|
||||
/** Only the account's own databases: the picker never offers a domain the server will reject. */
|
||||
readonly domains = computed(() => dominiosPermitidos(this.auth, DOMAINS));
|
||||
readonly paneOpen = signal(true);
|
||||
readonly validatingAll = signal(false);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { Observable, firstValueFrom, of } from 'rxjs';
|
||||
import { AuthService } from '../../auth/auth.service';
|
||||
import { BatchResult, ConflictStrategy, ImportSourcePayload, TargetMeta } from '../api/api.types';
|
||||
import { ImportsApi } from '../api/imports.api';
|
||||
import { SourceGateway } from '../api/source-gateway';
|
||||
@@ -32,6 +33,8 @@ describe('ConnectWorkspaceStore', () => {
|
||||
{ provide: TargetsApi, useValue: { list: () => of([PACIENTE, NOTA, tama]) } },
|
||||
{ provide: ImportsApi, useValue: imports },
|
||||
{ provide: SourceGateway, useValue: {} },
|
||||
// Sin sesión resuelta el alcance es todo; el caso restringido se arma en su propia prueba.
|
||||
{ provide: AuthService, useValue: { puedeVer: () => true } },
|
||||
],
|
||||
});
|
||||
store = TestBed.inject(ConnectWorkspaceStore);
|
||||
@@ -52,6 +55,25 @@ describe('ConnectWorkspaceStore', () => {
|
||||
expect(store.domain()).toBe('cacu');
|
||||
});
|
||||
|
||||
it('opens on the account\'s own domain and refuses the others', () => {
|
||||
// Fails if the destination database ignores the session: a CaMa team could load into CaCu's database.
|
||||
TestBed.resetTestingModule();
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
ConnectWorkspaceStore,
|
||||
{ provide: TargetsApi, useValue: { list: () => of([PACIENTE, NOTA, tama]) } },
|
||||
{ provide: ImportsApi, useValue: imports },
|
||||
{ provide: SourceGateway, useValue: {} },
|
||||
{ provide: AuthService, useValue: { puedeVer: (dominio: string) => dominio === 'cama' } },
|
||||
],
|
||||
});
|
||||
const restringido = TestBed.inject(ConnectWorkspaceStore);
|
||||
|
||||
expect(restringido.domain()).toBe('cama');
|
||||
restringido.setDomain('cacu');
|
||||
expect(restringido.domain()).toBe('cama');
|
||||
});
|
||||
|
||||
it('removing a connection removes the flows built on its tables', () => {
|
||||
const { connection } = flowFrom('a.csv', PACIENTE);
|
||||
flowFrom('b.csv', PACIENTE);
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Injectable, computed, inject, signal } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { Observable, catchError, from, of, switchMap, tap } from 'rxjs';
|
||||
import { BatchResult, ConflictStrategy, ConnectorInfo, Domain, TargetMeta, apiErrorMessage } from '../api/api.types';
|
||||
import { AuthService } from '../../auth/auth.service';
|
||||
import { dominiosPermitidos } from '../../auth/dominios';
|
||||
import { ConnectorsApi } from '../api/connectors.api';
|
||||
import { ImportsApi } from '../api/imports.api';
|
||||
import { SourceGateway } from '../api/source-gateway';
|
||||
@@ -29,6 +31,7 @@ export const DOMAINS: { id: Domain; label: string; description: string }[] = [
|
||||
export class ConnectWorkspaceStore {
|
||||
private readonly gateway = inject(SourceGateway);
|
||||
private readonly importsApi = inject(ImportsApi);
|
||||
private readonly auth = inject(AuthService);
|
||||
|
||||
private readonly targetsError = signal<string | null>(null);
|
||||
readonly allTargets = toSignal(
|
||||
@@ -50,7 +53,8 @@ export class ConnectWorkspaceStore {
|
||||
});
|
||||
readonly acceptedExtensions = computed(() => acceptedExtensions(this.connectors()));
|
||||
|
||||
private readonly _domain = signal<Domain>('cacu');
|
||||
/** The destination database: the account's own when it only reaches one. */
|
||||
private readonly _domain = signal<Domain>(this.dominioInicial());
|
||||
private readonly _connections = signal<DataConnection[]>([]);
|
||||
private readonly _flows = signal<ImportFlow[]>([]);
|
||||
private readonly _selectedFlowId = signal<string | null>(null);
|
||||
@@ -128,7 +132,12 @@ export class ConnectWorkspaceStore {
|
||||
});
|
||||
|
||||
setDomain(domain: Domain): void {
|
||||
if (!this.domainLocked()) this._domain.set(domain);
|
||||
if (!this.domainLocked() && this.auth.puedeVer(domain)) this._domain.set(domain);
|
||||
}
|
||||
|
||||
/** The first domain the account may see; every account has at least one (`WebApi` gives none other). */
|
||||
private dominioInicial(): Domain {
|
||||
return dominiosPermitidos(this.auth, DOMAINS)[0]?.id ?? 'cacu';
|
||||
}
|
||||
|
||||
setOnConflict(strategy: ConflictStrategy): void {
|
||||
|
||||
Reference in New Issue
Block a user