@tech4good/angular-schematics 20.2.0 → 20.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/publish-npm/SKILL.md +2 -0
- package/.agents/skills/publish-npm/eval.yaml +1 -1
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +56 -0
- package/README.md +16 -7
- package/commitlint.config.js +15 -0
- package/package.json +6 -2
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +1 -1
- package/src/ng-add/files/.gitignore.template +3 -0
- package/src/ng-add/files/package.json.template +3 -2
- package/src/ng-add/files/public/images/abstract.png +0 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +27 -22
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.scss.template +35 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +31 -75
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.html.template +25 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.scss.template +67 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.ts.template +74 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.html.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.ts.template +36 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.html.template +11 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.ts.template +47 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.html.template +52 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.scss.template +66 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +220 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.html.template +81 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.scss.template +136 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +118 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -0
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +14 -18
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +58 -0
- package/src/ng-add/files/src/app/core/auth/guards/admin-override.ts.template +9 -0
- package/src/ng-add/files/src/app/core/auth/guards/index.ts.template +11 -0
- package/src/ng-add/files/src/app/core/auth/guards/redirect-if-authenticated.guard.ts.template +42 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +39 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +69 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth.guard.ts.template +35 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +1 -1
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +7 -1
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +71 -6
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +94 -53
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +5 -5
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +5 -7
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +3 -5
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +2 -5
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +4 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +54 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.animations.ts.template +6 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.html.template +70 -52
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.scss.template +73 -6
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +59 -111
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +44 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.animations.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +12 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +79 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +20 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +1 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +11 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.html.template +3 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.scss.template +26 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.ts.template +52 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.html.template +21 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +71 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.ts.template +70 -0
- package/src/ng-add/files/src/app/shared/hint-visibility/hint-visibility.directive.ts.template +131 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +2 -2
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/src/index.html.template +3 -2
- package/src/ng-add/files/src/styles/_variables.scss.template +1 -0
- package/src/ng-add/files/src/styles.scss.template +4 -2
- package/src/ng-add/files/src/app/core/auth/auth.guard.ts.template +0 -96
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.table-wrapper {
|
|
6
|
+
border: 1px solid #e0e0e0;
|
|
7
|
+
border-radius: 8px;
|
|
8
|
+
overflow-y: auto;
|
|
9
|
+
overflow-x: auto;
|
|
10
|
+
height: 250px;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
background: #fafafa;
|
|
14
|
+
|
|
15
|
+
table.mat-mdc-table {
|
|
16
|
+
width: 100%;
|
|
17
|
+
min-width: 800px;
|
|
18
|
+
table-layout: fixed;
|
|
19
|
+
|
|
20
|
+
// Fixed column widths to prevent resizing on filter
|
|
21
|
+
.mat-column-userName { width: 22%; }
|
|
22
|
+
.mat-column-questionOne { width: 30%; }
|
|
23
|
+
.mat-column-questionTwo { width: 30%; }
|
|
24
|
+
.mat-column-accessState {
|
|
25
|
+
width: 18%;
|
|
26
|
+
padding-right: 24px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Header row styling
|
|
30
|
+
tr.mat-mdc-header-row,
|
|
31
|
+
tr.mat-header-row {
|
|
32
|
+
background: #f5f7fa;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
th.mat-header-cell,
|
|
36
|
+
th.mat-mdc-header-cell {
|
|
37
|
+
padding: 12px 16px !important;
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
font-weight: 600;
|
|
40
|
+
color: #555;
|
|
41
|
+
text-transform: uppercase;
|
|
42
|
+
letter-spacing: 0.03em;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
td.mat-cell,
|
|
46
|
+
td.mat-mdc-cell {
|
|
47
|
+
padding: 10px 16px !important;
|
|
48
|
+
font-size: 13px;
|
|
49
|
+
color: #333;
|
|
50
|
+
border-bottom: 1px solid #f0f0f0;
|
|
51
|
+
|
|
52
|
+
.user-info {
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
gap: 10px;
|
|
56
|
+
|
|
57
|
+
.avatar {
|
|
58
|
+
width: 28px;
|
|
59
|
+
height: 28px;
|
|
60
|
+
border-radius: 50%;
|
|
61
|
+
object-fit: cover;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.name {
|
|
65
|
+
font-weight: 500;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Alternating row backgrounds
|
|
71
|
+
tr.mat-mdc-row:nth-child(even),
|
|
72
|
+
tr.mat-row:nth-child(even) {
|
|
73
|
+
background: #fafbfc;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Hover effect
|
|
77
|
+
tr.mat-mdc-row:hover,
|
|
78
|
+
tr.mat-row:hover {
|
|
79
|
+
background: #f0f4ff;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.update-btn {
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.status-container {
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 6px;
|
|
90
|
+
|
|
91
|
+
.status-date {
|
|
92
|
+
font-size: 0.85em;
|
|
93
|
+
color: #666;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.mat-column-questionOne,
|
|
98
|
+
.mat-column-questionTwo {
|
|
99
|
+
max-width: 300px;
|
|
100
|
+
white-space: pre-wrap;
|
|
101
|
+
padding-right: 24px;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.empty-state {
|
|
106
|
+
flex: 1;
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
align-items: center;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
padding: 48px 24px;
|
|
112
|
+
color: #757575;
|
|
113
|
+
text-align: center;
|
|
114
|
+
background: #fafafa;
|
|
115
|
+
|
|
116
|
+
mat-icon {
|
|
117
|
+
font-size: 48px;
|
|
118
|
+
width: 48px;
|
|
119
|
+
height: 48px;
|
|
120
|
+
margin-bottom: 12px;
|
|
121
|
+
color: #bdbdbd;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
p {
|
|
125
|
+
margin: 0;
|
|
126
|
+
font-size: 14px;
|
|
127
|
+
font-weight: 500;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Highlight the active filter option in the dropdown
|
|
133
|
+
::ng-deep .mat-mdc-menu-item.selected {
|
|
134
|
+
background: #e3f2fd;
|
|
135
|
+
font-weight: 600;
|
|
136
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { render } from '@testing-library/angular';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import { AdminUserTableComponent } from './admin-user-table.component';
|
|
5
|
+
import { DATABASE_SERVICE } from 'src/app/core/firebase/database.service';
|
|
6
|
+
import { FirebaseMockService } from 'src/app/core/firebase/firebase.mock.service';
|
|
7
|
+
import { BatchWriteMockService } from 'src/app/core/store/batch-write.mock.service';
|
|
8
|
+
import { BATCH_WRITE_SERVICE } from 'src/app/core/store/batch-write.service';
|
|
9
|
+
|
|
10
|
+
/** Sets up the testing environment for AdminUserTableComponent using render.*/
|
|
11
|
+
async function setup() {
|
|
12
|
+
const user = userEvent.setup();
|
|
13
|
+
const checkedSpy = jest.fn();
|
|
14
|
+
|
|
15
|
+
const view = await render(AdminUserTableComponent, {
|
|
16
|
+
imports: [],
|
|
17
|
+
providers: [
|
|
18
|
+
{ provide: DATABASE_SERVICE, useClass: FirebaseMockService },
|
|
19
|
+
{ provide: BATCH_WRITE_SERVICE, useClass: BatchWriteMockService },
|
|
20
|
+
],
|
|
21
|
+
componentInputs: {},
|
|
22
|
+
on: {},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
user,
|
|
27
|
+
fixture: view.fixture,
|
|
28
|
+
rerender: () => view.rerender(), // add component inputs if needed
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('AdminUserTableComponent', () => {
|
|
33
|
+
it('should create', async () => {
|
|
34
|
+
const { fixture } = await setup();
|
|
35
|
+
expect(fixture.componentInstance).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Component, OnInit, ChangeDetectionStrategy, input, output, inject, WritableSignal, Signal, signal, computed, Inject, Injector } from '@angular/core';
|
|
2
|
+
import { AdminUserTableAnimations } from './admin-user-table.animations';
|
|
3
|
+
import { DatePipe } from '@angular/common';
|
|
4
|
+
import { MatTable, MatColumnDef, MatHeaderCellDef, MatHeaderCell, MatCellDef, MatCell, MatHeaderRowDef, MatHeaderRow, MatRowDef, MatRow } from '@angular/material/table';
|
|
5
|
+
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
|
|
6
|
+
import { MatIcon } from '@angular/material/icon';
|
|
7
|
+
import { MatButton } from '@angular/material/button';
|
|
8
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
9
|
+
import { MatSortModule, Sort } from '@angular/material/sort';
|
|
10
|
+
import { User, AccessState } from 'src/app/core/store/user/user.model';
|
|
11
|
+
import { AdminRow } from '../admin-user-list.component';
|
|
12
|
+
|
|
13
|
+
@Component({
|
|
14
|
+
selector: 'app-admin-user-table',
|
|
15
|
+
templateUrl: './admin-user-table.component.html',
|
|
16
|
+
styleUrls: ['./admin-user-table.component.scss'],
|
|
17
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
18
|
+
animations: AdminUserTableAnimations,
|
|
19
|
+
imports: [
|
|
20
|
+
DatePipe,
|
|
21
|
+
MatTable,
|
|
22
|
+
MatColumnDef,
|
|
23
|
+
MatHeaderCellDef,
|
|
24
|
+
MatHeaderCell,
|
|
25
|
+
MatCellDef,
|
|
26
|
+
MatCell,
|
|
27
|
+
MatHeaderRowDef,
|
|
28
|
+
MatHeaderRow,
|
|
29
|
+
MatRowDef,
|
|
30
|
+
MatRow,
|
|
31
|
+
MatMenuTrigger,
|
|
32
|
+
MatMenu,
|
|
33
|
+
MatMenuItem,
|
|
34
|
+
MatIcon,
|
|
35
|
+
MatButton,
|
|
36
|
+
MatTooltipModule,
|
|
37
|
+
MatSortModule
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class AdminUserTableComponent implements OnInit {
|
|
41
|
+
// --------------- INPUTS AND OUTPUTS ------------------
|
|
42
|
+
|
|
43
|
+
/** The user data to display. */
|
|
44
|
+
dataSource = input.required<AdminRow[]>();
|
|
45
|
+
|
|
46
|
+
/** Columns to render. */
|
|
47
|
+
displayedColumns = input.required<string[]>();
|
|
48
|
+
|
|
49
|
+
/** Available access states for the dropdown menu. */
|
|
50
|
+
accessOptions = input.required<AccessState[]>();
|
|
51
|
+
|
|
52
|
+
/** Whether to enable table sorting. */
|
|
53
|
+
sortable = input<boolean>(false);
|
|
54
|
+
|
|
55
|
+
/** The currently active sort column. */
|
|
56
|
+
sortActive = input<string>('');
|
|
57
|
+
|
|
58
|
+
/** The current sort direction. */
|
|
59
|
+
sortDirection = input<string>('');
|
|
60
|
+
|
|
61
|
+
/** Whether to show the state filter in the column header. */
|
|
62
|
+
showFilter = input<boolean>(false);
|
|
63
|
+
|
|
64
|
+
/** The current filter state. */
|
|
65
|
+
filterState = input<AccessState | 'ALL'>('ALL');
|
|
66
|
+
|
|
67
|
+
/** Emitted when the user changes sorting. */
|
|
68
|
+
sortChange = output<Sort>();
|
|
69
|
+
|
|
70
|
+
/** Emitted when the user changes an access state. */
|
|
71
|
+
updateState = output<{user: User, key: string, value: AccessState}>();
|
|
72
|
+
|
|
73
|
+
/** Emitted when the user changes the state filter. */
|
|
74
|
+
filterChange = output<AccessState | 'ALL'>();
|
|
75
|
+
|
|
76
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
77
|
+
|
|
78
|
+
// --------------- COMPUTED DATA -----------------------
|
|
79
|
+
|
|
80
|
+
// --------------- EVENT HANDLING ----------------------
|
|
81
|
+
|
|
82
|
+
// --------------- OTHER -------------------------------
|
|
83
|
+
|
|
84
|
+
getAccessStateIcon(state: AccessState): string {
|
|
85
|
+
switch (state) {
|
|
86
|
+
case AccessState.SUBMIT_INTEREST: return 'forum';
|
|
87
|
+
case AccessState.WAITING: return 'pending_actions';
|
|
88
|
+
case AccessState.CONSENT: return 'psychology';
|
|
89
|
+
case AccessState.DONE: return 'check_circle';
|
|
90
|
+
default: return 'help_outline';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getAccessStateColor(state: AccessState): string {
|
|
95
|
+
switch (state) {
|
|
96
|
+
case AccessState.SUBMIT_INTEREST: return '#1976d2'; // Blue
|
|
97
|
+
case AccessState.WAITING: return '#f57c00'; // Orange
|
|
98
|
+
case AccessState.CONSENT: return '#7b1fa2'; // Purple
|
|
99
|
+
case AccessState.DONE: return '#388e3c'; // Green
|
|
100
|
+
default: return '#757575'; // Grey
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getStateDate(user: User): Date | null {
|
|
105
|
+
if (user.accessState === AccessState.WAITING && user.joinedWaitlistAt) {
|
|
106
|
+
return user.joinedWaitlistAt.toDate();
|
|
107
|
+
}
|
|
108
|
+
const timestamp = user._updatedAt || user._createdAt;
|
|
109
|
+
return timestamp ? timestamp.toDate() : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
constructor() { }
|
|
113
|
+
|
|
114
|
+
// --------------- LOAD AND CLEANUP --------------------
|
|
115
|
+
|
|
116
|
+
ngOnInit(): void {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -5,6 +5,7 @@ import { TimeAnalyticsService } from './core/analytics/time-analytics.service';
|
|
|
5
5
|
import { AuthStore } from './core/store/auth/auth.store';
|
|
6
6
|
import { DetectRedeploymentService } from './shared/redeployment-warning/redeployment-warning.service';
|
|
7
7
|
import { RedeploymentWarningComponent } from './shared/redeployment-warning/redeployment-warning.component';
|
|
8
|
+
import { DevStatusBarComponent } from './shared/dev-status-bar/dev-status-bar.component';
|
|
8
9
|
|
|
9
10
|
@Component({
|
|
10
11
|
selector: 'app-root',
|
|
@@ -12,6 +13,7 @@ import { RedeploymentWarningComponent } from './shared/redeployment-warning/rede
|
|
|
12
13
|
styleUrls: ['./app.component.scss'],
|
|
13
14
|
imports: [
|
|
14
15
|
RedeploymentWarningComponent,
|
|
16
|
+
DevStatusBarComponent,
|
|
15
17
|
RouterOutlet,
|
|
16
18
|
],
|
|
17
19
|
})
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import { Routes } from '@angular/router';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { LoginComponent } from './first-time/login/login.component';
|
|
6
|
-
import { ConsentComponent } from './first-time/consent/consent.component';
|
|
7
|
-
import { EarlyAccessComponent } from './first-time/early-access/early-access.component';
|
|
8
|
-
import { OnboardingComponent } from './first-time/onboarding/onboarding.component';
|
|
9
|
-
import { HomeComponent } from './main/home/home.component';
|
|
2
|
+
import { requireAuth, redirectIfAuthenticated, requireAdmin, requireAuthAndConsent } from './core/auth/guards';
|
|
3
|
+
import { earlyAccessGuard } from './first-time/early-access/early-access.guard';
|
|
4
|
+
import { consentGuard } from './first-time/consent/consent.guard';
|
|
10
5
|
|
|
11
6
|
export const routes: Routes = [
|
|
12
|
-
// Admin Routes
|
|
7
|
+
// Admin Routes — must be logged in + must be admin
|
|
13
8
|
{ path: 'admin', loadComponent: () => import('./admin/admin-panel/admin-panel.component')
|
|
14
|
-
.then((mod) => mod.AdminPanelComponent), canActivate: [
|
|
15
|
-
// First-Time User Experience Routes
|
|
9
|
+
.then((mod) => mod.AdminPanelComponent), canActivate: [requireAuth, requireAdmin] },
|
|
10
|
+
// First-Time User Experience Routes (public pages)
|
|
16
11
|
{ path: 'landing', loadComponent: () => import('./first-time/landing/landing.component')
|
|
17
|
-
.then((mod) => mod.LandingComponent), canActivate: [
|
|
12
|
+
.then((mod) => mod.LandingComponent), canActivate: [redirectIfAuthenticated] },
|
|
18
13
|
{ path: 'login', loadComponent: () => import('./first-time/login/login.component')
|
|
19
|
-
.then((mod) => mod.LoginComponent) },
|
|
14
|
+
.then((mod) => mod.LoginComponent), canActivate: [redirectIfAuthenticated] },
|
|
15
|
+
// First-Time User Experience Routes (gated pages)
|
|
20
16
|
{ path: 'consent', loadComponent: () => import('./first-time/consent/consent.component')
|
|
21
|
-
.then((mod) => mod.ConsentComponent), canActivate: [
|
|
17
|
+
.then((mod) => mod.ConsentComponent), canActivate: [requireAuth, consentGuard] },
|
|
22
18
|
{ path: 'early-access', loadComponent: () => import('./first-time/early-access/early-access.component')
|
|
23
|
-
.then((mod) => mod.EarlyAccessComponent), canActivate: [
|
|
19
|
+
.then((mod) => mod.EarlyAccessComponent), canActivate: [requireAuth, earlyAccessGuard] },
|
|
24
20
|
{ path: 'onboarding', loadComponent: () => import('./first-time/onboarding/onboarding.component')
|
|
25
|
-
.then((mod) => mod.OnboardingComponent), canActivate: [
|
|
21
|
+
.then((mod) => mod.OnboardingComponent), canActivate: [requireAuthAndConsent] },
|
|
26
22
|
// Main Routes
|
|
27
23
|
{ path: 'home', loadComponent: () => import('./main/home/home.component')
|
|
28
|
-
.then((mod) => mod.HomeComponent), canActivate: [
|
|
24
|
+
.then((mod) => mod.HomeComponent), canActivate: [requireAuthAndConsent] },
|
|
29
25
|
{ path: '', loadComponent: () => import('./first-time/landing/landing.component')
|
|
30
|
-
.then((mod) => mod.LandingComponent), canActivate: [
|
|
26
|
+
.then((mod) => mod.LandingComponent), canActivate: [redirectIfAuthenticated] },
|
|
31
27
|
{ path: '**', redirectTo: 'landing', pathMatch: 'full' },
|
|
32
28
|
];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { inject, Injectable } from '@angular/core';
|
|
2
|
+
import { Observable, of } from 'rxjs';
|
|
3
|
+
import { filter, switchMap, take } from 'rxjs/operators';
|
|
4
|
+
import { toObservable } from '@angular/core/rxjs-interop';
|
|
5
|
+
import { User } from '../store/user/user.model';
|
|
6
|
+
import { AuthStore } from '../store/auth/auth.store';
|
|
7
|
+
import { DATABASE_SERVICE } from '../firebase/database.service';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Shared authentication service used by all functional guards.
|
|
11
|
+
*
|
|
12
|
+
* Centralises the two key observables (Firebase auth user and database User)
|
|
13
|
+
* so that individual guards don't need to duplicate this setup. Every guard
|
|
14
|
+
* calls `resolveUser()` to get a single-emission observable of the current
|
|
15
|
+
* database user (or null if not authenticated).
|
|
16
|
+
*/
|
|
17
|
+
@Injectable({ providedIn: 'root' })
|
|
18
|
+
export class AuthService {
|
|
19
|
+
private readonly authStore = inject(AuthStore);
|
|
20
|
+
private readonly db = inject(DATABASE_SERVICE);
|
|
21
|
+
|
|
22
|
+
/** Firebase auth user stream (null when signed out). */
|
|
23
|
+
readonly afUser$ = this.db.afUser();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Database User record stream. Only emits once the AuthStore has loaded
|
|
27
|
+
* a non-null user value. This is safe to use in guards that already know
|
|
28
|
+
* the user is authenticated — it will wait until the store is populated
|
|
29
|
+
* rather than emitting a stale `null`.
|
|
30
|
+
*/
|
|
31
|
+
readonly user$: Observable<User> = toObservable(this.authStore.user).pipe(
|
|
32
|
+
filter((user): user is User => !!user),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the full database user in a single emission.
|
|
37
|
+
*
|
|
38
|
+
* - If the Firebase auth user exists, it first checks the synchronous
|
|
39
|
+
* signal value to bypass the async microtask delay of `toObservable`.
|
|
40
|
+
* This ensures routing guards executing immediately after a state patch
|
|
41
|
+
* do not read a stale state.
|
|
42
|
+
* - If the signal is not yet populated, it waits for the AuthStore to load
|
|
43
|
+
* the database user and takes the first emission.
|
|
44
|
+
* - If not authenticated, emits `null` immediately.
|
|
45
|
+
*
|
|
46
|
+
* This is the primary entry point for all guards.
|
|
47
|
+
*/
|
|
48
|
+
resolveUser(): Observable<User | null> {
|
|
49
|
+
return this.afUser$.pipe(
|
|
50
|
+
switchMap((afUser) => {
|
|
51
|
+
if (!afUser) return of(null);
|
|
52
|
+
const currentUser = this.authStore.user();
|
|
53
|
+
if (currentUser) return of(currentUser);
|
|
54
|
+
return this.user$.pipe(take(1));
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { User } from '../../store/user/user.model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper to check if a user is an admin and has an active route override
|
|
5
|
+
* for the current URL. Used inside guards to short-circuit redirects.
|
|
6
|
+
*/
|
|
7
|
+
export function hasAdminOverride(user: User | null | undefined, url: string): boolean {
|
|
8
|
+
return !!(user?.isAdmin && user.adminOverridePaths?.includes(url));
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export for all common auth guards.
|
|
3
|
+
*
|
|
4
|
+
* Common guards live in `core/auth/guards/` and are reusable across many
|
|
5
|
+
* routes. Page-specific guards are co-located with their components.
|
|
6
|
+
*/
|
|
7
|
+
export { requireAuth } from './require-auth.guard';
|
|
8
|
+
export { redirectIfAuthenticated } from './redirect-if-authenticated.guard';
|
|
9
|
+
export { requireAdmin } from './require-admin.guard';
|
|
10
|
+
export { requireAuthAndConsent } from './require-auth-and-consent.guard';
|
|
11
|
+
export { hasAdminOverride } from './admin-override';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { CanActivateFn, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { map } from 'rxjs/operators';
|
|
4
|
+
import { AuthService } from '../auth.service';
|
|
5
|
+
import { hasAdminOverride } from './admin-override';
|
|
6
|
+
import { User } from '../../store/user/user.model';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Redirects already-authenticated users away from public pages (landing,
|
|
10
|
+
* login) to `/home`. Returns `true` only for unauthenticated users,
|
|
11
|
+
* allowing them to view the public page.
|
|
12
|
+
*/
|
|
13
|
+
export function handleAccess(
|
|
14
|
+
user: User | null | undefined,
|
|
15
|
+
router: Router,
|
|
16
|
+
route: ActivatedRouteSnapshot,
|
|
17
|
+
state: RouterStateSnapshot
|
|
18
|
+
): boolean {
|
|
19
|
+
if (user) {
|
|
20
|
+
// Admin override short-circuit
|
|
21
|
+
if (hasAdminOverride(user, state.url)) return true;
|
|
22
|
+
|
|
23
|
+
// Already logged in → send to home
|
|
24
|
+
router.navigate(['/home'], { queryParams: route.queryParams });
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Route guard that delegates to `handleAccess`.
|
|
32
|
+
*/
|
|
33
|
+
export const redirectIfAuthenticated: CanActivateFn = (route, state) => {
|
|
34
|
+
const auth = inject(AuthService);
|
|
35
|
+
const router = inject(Router);
|
|
36
|
+
|
|
37
|
+
return auth.resolveUser().pipe(
|
|
38
|
+
map((user) => {
|
|
39
|
+
return handleAccess(user, router, route, state);
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { CanActivateFn, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { User } from '../../store/user/user.model';
|
|
4
|
+
import { map } from 'rxjs/operators';
|
|
5
|
+
import { AuthService } from '../auth.service';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Restricts access to admin users only. Non-admin users are redirected
|
|
9
|
+
* to `/home`.
|
|
10
|
+
*
|
|
11
|
+
* This guard should always be placed *after* `requireAuth` in the
|
|
12
|
+
* `canActivate` array, since it assumes the user is already authenticated.
|
|
13
|
+
*/
|
|
14
|
+
export function handleAccess(
|
|
15
|
+
user: User | null | undefined,
|
|
16
|
+
router: Router,
|
|
17
|
+
route: ActivatedRouteSnapshot,
|
|
18
|
+
state: RouterStateSnapshot
|
|
19
|
+
): boolean {
|
|
20
|
+
if (!user?.isAdmin) {
|
|
21
|
+
router.navigate(['/home'], { queryParams: route.queryParams });
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Route guard that delegates to `handleAccess`.
|
|
29
|
+
*/
|
|
30
|
+
export const requireAdmin: CanActivateFn = (route, state) => {
|
|
31
|
+
const auth = inject(AuthService);
|
|
32
|
+
const router = inject(Router);
|
|
33
|
+
|
|
34
|
+
return auth.resolveUser().pipe(
|
|
35
|
+
map((user) => {
|
|
36
|
+
return handleAccess(user, router, route, state);
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { CanActivateFn, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { map } from 'rxjs/operators';
|
|
4
|
+
import { AuthService } from '../auth.service';
|
|
5
|
+
import { AccessState, User } from '../../store/user/user.model';
|
|
6
|
+
import { hasAdminOverride } from './admin-override';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Combined guard that checks authentication, admin overrides, and full
|
|
10
|
+
* consent completion in a single pass. This avoids resolving the user
|
|
11
|
+
* multiple times when stacking separate guards.
|
|
12
|
+
*
|
|
13
|
+
* Use this on any route that requires the user to be fully through the
|
|
14
|
+
* onboarding pipeline (logged in + waitlist cleared + consented).
|
|
15
|
+
*
|
|
16
|
+
* Checks performed in order:
|
|
17
|
+
* 1. Not logged in → redirect to `/landing`
|
|
18
|
+
* 2. Admin with route in `adminOverridePaths` → allow immediately
|
|
19
|
+
* 3. `accessState` is `SUBMIT_INTEREST` or `WAITING` → redirect to `/early-access`
|
|
20
|
+
* 4. `accessState` is not `DONE` or `consented` is false → redirect to `/consent`
|
|
21
|
+
* 5. Otherwise → allow
|
|
22
|
+
*/
|
|
23
|
+
export function handleAccess(
|
|
24
|
+
user: User | null | undefined,
|
|
25
|
+
router: Router,
|
|
26
|
+
route: ActivatedRouteSnapshot,
|
|
27
|
+
state: RouterStateSnapshot
|
|
28
|
+
): boolean {
|
|
29
|
+
// Step 1: Not logged in → landing
|
|
30
|
+
if (!user) {
|
|
31
|
+
router.navigate(['/landing'], { queryParams: route.queryParams });
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Step 2: Admin override → bypass all downstream checks
|
|
36
|
+
if (hasAdminOverride(user, state.url)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Step 3: Still on the waitlist → early-access
|
|
41
|
+
const waitingStates = [AccessState.SUBMIT_INTEREST, AccessState.WAITING];
|
|
42
|
+
if (waitingStates.includes(user.accessState)) {
|
|
43
|
+
router.navigate(['/early-access'], { queryParams: route.queryParams });
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Step 4: Not fully consented → consent
|
|
48
|
+
if (user.accessState !== AccessState.DONE || !user.consented) {
|
|
49
|
+
router.navigate(['/consent'], { queryParams: route.queryParams });
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Step 5: Fully through the pipeline → allow
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Route guard that delegates to `handleAccess`.
|
|
59
|
+
*/
|
|
60
|
+
export const requireAuthAndConsent: CanActivateFn = (route, state) => {
|
|
61
|
+
const auth = inject(AuthService);
|
|
62
|
+
const router = inject(Router);
|
|
63
|
+
|
|
64
|
+
return auth.resolveUser().pipe(
|
|
65
|
+
map((user) => {
|
|
66
|
+
return handleAccess(user, router, route, state);
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { CanActivateFn, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { User } from '../../store/user/user.model';
|
|
4
|
+
import { map } from 'rxjs/operators';
|
|
5
|
+
import { AuthService } from '../auth.service';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ensures the user is logged in. If not, redirects to `/landing`.
|
|
9
|
+
*/
|
|
10
|
+
export function handleAccess(
|
|
11
|
+
user: User | null | undefined,
|
|
12
|
+
router: Router,
|
|
13
|
+
route: ActivatedRouteSnapshot,
|
|
14
|
+
state: RouterStateSnapshot
|
|
15
|
+
): boolean {
|
|
16
|
+
if (!user) {
|
|
17
|
+
router.navigate(['/landing'], { queryParams: route.queryParams });
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Route guard that delegates to `handleAccess`.
|
|
25
|
+
*/
|
|
26
|
+
export const requireAuth: CanActivateFn = (route, state) => {
|
|
27
|
+
const auth = inject(AuthService);
|
|
28
|
+
const router = inject(Router);
|
|
29
|
+
|
|
30
|
+
return auth.resolveUser().pipe(
|
|
31
|
+
map((user) => {
|
|
32
|
+
return handleAccess(user, router, route, state);
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -52,7 +52,7 @@ export class FirebaseMockService implements DatabaseService {
|
|
|
52
52
|
return autoId;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
afUser(): Observable<{ uid: string,
|
|
55
|
+
afUser(): Observable<{ uid: string, email: string, displayName: string, photoURL: string }> {
|
|
56
56
|
return this.user$;
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -151,7 +151,13 @@ export class FirebaseService implements DatabaseService {
|
|
|
151
151
|
switch (queryKey) {
|
|
152
152
|
case 'orderBy': {
|
|
153
153
|
if (Array.isArray(queryOptions.orderBy)) {
|
|
154
|
-
|
|
154
|
+
if (Array.isArray(queryOptions.orderBy[0])) {
|
|
155
|
+
for (const order of queryOptions.orderBy) {
|
|
156
|
+
queryArray.push(orderBy(order[0], order[1] as OrderByDirection));
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
queryArray.push(orderBy(queryOptions.orderBy[0] as string, queryOptions.orderBy[1] as OrderByDirection));
|
|
160
|
+
}
|
|
155
161
|
} else {
|
|
156
162
|
queryArray.push(orderBy(queryOptions.orderBy));
|
|
157
163
|
}
|
|
@@ -10,7 +10,7 @@ export type AnyEntity =
|
|
|
10
10
|
export type QueryParams = [string, string, any][];
|
|
11
11
|
|
|
12
12
|
export type QueryOptions = {
|
|
13
|
-
orderBy?: string | [string, string],
|
|
13
|
+
orderBy?: string | [string, string] | [string, string][],
|
|
14
14
|
limit?: number,
|
|
15
15
|
startAt?: string,
|
|
16
16
|
startAfter?: string,
|