feature/30-group-authentication #9
|
@ -5,18 +5,23 @@ import {SharedModule} from '../shared/shared.module'
|
|||
import {Login, Logout} from './accounts'
|
||||
import {CreInputsModule} from '../shared/components/inputs/inputs.module'
|
||||
import {CreButtonsModule} from '../shared/components/buttons/buttons.module'
|
||||
import {GroupTokenAdd} from "./group-tokens";
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
Login,
|
||||
Logout
|
||||
Logout,
|
||||
GroupTokenAdd
|
||||
],
|
||||
exports: [
|
||||
GroupTokenAdd
|
||||
],
|
||||
imports: [
|
||||
SharedModule,
|
||||
AccountsRoutingModule,
|
||||
CreInputsModule,
|
||||
CreButtonsModule,
|
||||
CreButtonsModule
|
||||
]
|
||||
})
|
||||
export class AccountsModule {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<cre-prompt-dialog
|
||||
title="Définir le groupe par défaut de cet ordinateur">
|
||||
<cre-dialog-body>
|
||||
<div>
|
||||
<cre-input [control]="controls.name" label="Name" icon="form-textbox"></cre-input>
|
||||
</div>
|
||||
</cre-dialog-body>
|
||||
</cre-prompt-dialog>
|
|
@ -0,0 +1,18 @@
|
|||
import {Component, ViewChild} from "@angular/core";
|
||||
import {CrePromptDialog} from "../shared/components/dialogs/dialogs";
|
||||
import {Group} from "../shared/model/account.model";
|
||||
import {FormControl, Validators} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-group-token-add',
|
||||
templateUrl: 'group-token-add.html'
|
||||
})
|
||||
export class GroupTokenAdd {
|
||||
@ViewChild(CrePromptDialog) dialog: CrePromptDialog
|
||||
|
||||
controls = {name: new FormControl(null, Validators.required)}
|
||||
|
||||
show(group: Group) {
|
||||
this.dialog.show()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import {Injectable} from "@angular/core";
|
||||
import {ApiService} from "../../shared/service/api.service";
|
||||
import {Observable} from "rxjs";
|
||||
import {GroupToken} from "../../shared/model/account.model";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root"
|
||||
})
|
||||
export class GroupTokenService {
|
||||
constructor(
|
||||
private api: ApiService
|
||||
) {
|
||||
}
|
||||
|
||||
get all(): Observable<GroupToken[]> {
|
||||
return this.api.get<GroupToken[]>('/account/group/token')
|
||||
}
|
||||
|
||||
get current(): Observable<GroupToken | null> {
|
||||
return this.api.get<GroupToken | null>('/account/group/token/current')
|
||||
}
|
||||
|
||||
save(name: string): Observable<GroupToken> {
|
||||
return this.api.post<GroupToken>('/account/group/token')
|
||||
}
|
||||
}
|
|
@ -5,13 +5,21 @@ import {ListComponent} from './pages/list/list.component';
|
|||
import {SharedModule} from "../shared/shared.module";
|
||||
import {AddComponent} from './pages/add/add.component';
|
||||
import {EditComponent} from './pages/edit/edit.component';
|
||||
import {AccountsModule} from "../accounts/accounts.module";
|
||||
import {CreActionBarModule} from "../shared/components/action-bar/action-bar.module";
|
||||
import {CreButtonsModule} from "../shared/components/buttons/buttons.module";
|
||||
import {CreTablesModule} from "../shared/components/tables/tables.module";
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [ListComponent, AddComponent, EditComponent],
|
||||
imports: [
|
||||
GroupRoutingModule,
|
||||
SharedModule
|
||||
SharedModule,
|
||||
AccountsModule,
|
||||
CreActionBarModule,
|
||||
CreButtonsModule,
|
||||
CreTablesModule
|
||||
]
|
||||
})
|
||||
export class GroupModule { }
|
||||
|
|
|
@ -1,13 +1,42 @@
|
|||
<cre-entity-list
|
||||
addLink="/admin/group/add"
|
||||
addPermission="EDIT_USERS"
|
||||
[entities$]="groups$"
|
||||
[columns]="columns"
|
||||
[buttons]="buttons"
|
||||
[expandable]="true"
|
||||
[rowDetailsTemplate]="groupDetailsTemplate">
|
||||
</cre-entity-list>
|
||||
<cre-action-bar [reverse]="true">
|
||||
<cre-action-group>
|
||||
<cre-accent-button *ngIf="hasEditPermission" routerLink="/admin/group/add">Ajouter</cre-accent-button>
|
||||
</cre-action-group>
|
||||
</cre-action-bar>
|
||||
|
||||
<ng-template #groupDetailsTemplate let-group="entity">
|
||||
<cre-permissions-list [group]="group"></cre-permissions-list>
|
||||
</ng-template>
|
||||
<cre-warning-alert *ngIf="groupsEmpty">
|
||||
<p>Il n'y a actuellement aucun groupe enregistré dans le système.</p>
|
||||
<p *ngIf="hasEditPermission">Vous pouvez en créer un <b><a routerLink="/admin/group/add">ici</a></b>.</p>
|
||||
</cre-warning-alert>
|
||||
|
||||
<cre-table *ngIf="!groupsEmpty" class="mx-auto" [data]="groups$ | async" [columns]="columns">
|
||||
<ng-container matColumnDef="name">
|
||||
<th mat-header-cell *matHeaderCellDef>Nom</th>
|
||||
<td mat-cell *matCellDef="let group">{{group.name}}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="permissionCount">
|
||||
<th mat-header-cell *matHeaderCellDef>Nombre de permissions</th>
|
||||
<td mat-cell *matCellDef="let group">{{group.permissions.length}}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="setAsDefaultButton">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell [class.disabled]="!hasAdminPermission" *matCellDef="let group; let i = index">
|
||||
<cre-accent-button [creInteractiveCell]="i" (click)="setDefaultGroup(group)" >
|
||||
Définir par défaut
|
||||
</cre-accent-button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="editButton">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell [class.disabled]="!hasEditPermission" *matCellDef="let group; let i = index">
|
||||
<cre-accent-button [creInteractiveCell]="i" routerLink="/admin/group/edit/{{group.id}}">
|
||||
Modifier
|
||||
</cre-accent-button>
|
||||
</td>
|
||||
</ng-container>
|
||||
</cre-table>
|
||||
|
||||
<cre-group-token-add></cre-group-token-add>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Component} from '@angular/core'
|
||||
import {Component, ViewChild} from '@angular/core'
|
||||
import {GroupService} from '../../services/group.service'
|
||||
import {Group, Permission} from '../../../shared/model/account.model'
|
||||
import {AccountService} from '../../../accounts/services/account.service'
|
||||
|
@ -7,6 +7,8 @@ import {ActivatedRoute, Router} from '@angular/router'
|
|||
import {ErrorHandler, ErrorService} from '../../../shared/service/error.service'
|
||||
import {AlertService} from '../../../shared/service/alert.service'
|
||||
import {AppState} from '../../../shared/app-state'
|
||||
import {GroupTokenService} from "../../../accounts/services/group-token.service";
|
||||
import {GroupTokenAdd} from "../../../accounts/group-tokens";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-groups',
|
||||
|
@ -16,27 +18,34 @@ import {AppState} from '../../../shared/app-state'
|
|||
export class ListComponent extends ErrorHandlingComponent {
|
||||
groups$ = this.groupService.all
|
||||
defaultGroup: Group = null
|
||||
columns = [
|
||||
{def: 'name', title: 'Nom', valueFn: g => g.name},
|
||||
{def: 'permissionCount', title: 'Nombre de permissions', valueFn: g => g.permissions.length}
|
||||
]
|
||||
buttons = [{
|
||||
text: 'Définir par défaut',
|
||||
clickFn: group => this.setDefaultGroup(group),
|
||||
disabledFn: group => this.isDefaultGroup(group)
|
||||
}, {
|
||||
text: 'Modifier',
|
||||
linkFn: group => `/admin/group/edit/${group.id}`,
|
||||
permission: Permission.EDIT_USERS
|
||||
}]
|
||||
// columns = [
|
||||
// {def: 'name', title: 'Nom', valueFn: g => g.name},
|
||||
// {def: 'permissionCount', title: 'Nombre de permissions', valueFn: g => g.permissions.length}
|
||||
// ]
|
||||
// buttons = [{
|
||||
// text: 'Définir par défaut',
|
||||
// clickFn: group => this.setDefaultGroup(group),
|
||||
// disabledFn: group => this.isDefaultGroup(group)
|
||||
// }, {
|
||||
// text: 'Modifier',
|
||||
// linkFn: group => `/admin/group/edit/${group.id}`,
|
||||
// permission: Permission.EDIT_USERS
|
||||
// }]
|
||||
|
||||
groupsEmpty = false
|
||||
|
||||
columns = ['name', 'permissionCount', 'setAsDefaultButton', 'editButton']
|
||||
|
||||
errorHandlers: ErrorHandler[] = [{
|
||||
filter: error => error.type === 'nodefaultgroup',
|
||||
consumer: () => this.alertService.pushWarning('Aucun groupe par défaut n\'a été défini sur cet ordinateur')
|
||||
}]
|
||||
|
||||
@ViewChild(GroupTokenAdd) groupTokenDialog: GroupTokenAdd
|
||||
|
||||
constructor(
|
||||
private groupService: GroupService,
|
||||
private groupTokenService: GroupTokenService,
|
||||
private accountService: AccountService,
|
||||
private alertService: AlertService,
|
||||
private appState: AppState,
|
||||
|
@ -49,22 +58,30 @@ export class ListComponent extends ErrorHandlingComponent {
|
|||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
// this.subscribe(
|
||||
// this.groupService.defaultGroup,
|
||||
// group => this.defaultGroup = group,
|
||||
// true
|
||||
// )
|
||||
this.subscribe(
|
||||
this.groupService.defaultGroup,
|
||||
group => this.defaultGroup = group,
|
||||
true
|
||||
this.groupTokenService.current,
|
||||
token => console.info(token)
|
||||
)
|
||||
}
|
||||
|
||||
setDefaultGroup(group: Group) {
|
||||
this.subscribe(
|
||||
this.groupService.setDefaultGroup(group),
|
||||
() => this.defaultGroup = group,
|
||||
true
|
||||
)
|
||||
this.groupTokenDialog.show(group)
|
||||
}
|
||||
|
||||
isDefaultGroup(group: Group): boolean {
|
||||
return this.defaultGroup && this.defaultGroup.id == group.id
|
||||
}
|
||||
|
||||
get hasEditPermission(): boolean {
|
||||
return this.accountService.hasPermission(Permission.EDIT_USERS)
|
||||
}
|
||||
|
||||
get hasAdminPermission(): boolean {
|
||||
return this.accountService.hasPermission(Permission.ADMIN)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export class GroupService {
|
|||
}
|
||||
|
||||
get all(): Observable<Group[]> {
|
||||
return this.api.get<Group[]>('/user/group')
|
||||
return this.api.get<Group[]>('/account/group')
|
||||
}
|
||||
|
||||
get allWithDefault(): Observable<Group[]> {
|
||||
|
@ -27,40 +27,40 @@ export class GroupService {
|
|||
}
|
||||
|
||||
getById(id: number): Observable<Group> {
|
||||
return this.api.get<Group>(`/user/group/${id}`)
|
||||
return this.api.get<Group>(`/account/group/${id}`)
|
||||
}
|
||||
|
||||
get defaultGroup(): Observable<Group> {
|
||||
return this.api.get<Group>('/user/group/default')
|
||||
return this.api.get<Group>('/account/group/default')
|
||||
}
|
||||
|
||||
setDefaultGroup(value: Group): Observable<void> {
|
||||
return this.api.post<void>(`/user/group/default/${value.id}`, {})
|
||||
return this.api.post<void>(`/account/group/default/${value.id}`, {})
|
||||
}
|
||||
|
||||
getUsersForGroup(id: number): Observable<AccountModel[]> {
|
||||
return this.api.get<AccountModel[]>(`/user/group/${id}/users`)
|
||||
return this.api.get<AccountModel[]>(`/account/group/${id}/users`)
|
||||
}
|
||||
|
||||
addUserToGroup(id: number, user: AccountModel): Observable<void> {
|
||||
return this.api.put<void>(`/user/group/${id}/${user.id}`)
|
||||
return this.api.put<void>(`/account/group/${id}/${user.id}`)
|
||||
}
|
||||
|
||||
removeUserFromGroup(user: AccountModel): Observable<void> {
|
||||
return this.api.delete<void>(`/user/group/${user.group.id}/${user.id}`)
|
||||
return this.api.delete<void>(`/account/group/${user.group.id}/${user.id}`)
|
||||
}
|
||||
|
||||
save(name: string, permissions: Permission[]): Observable<Group> {
|
||||
const group = {name, permissions}
|
||||
return this.api.post<Group>('/user/group', group)
|
||||
return this.api.post<Group>('/account/group', group)
|
||||
}
|
||||
|
||||
update(id: number, name: string, permissions: Permission[]): Observable<Group> {
|
||||
const group = {id, name, permissions}
|
||||
return this.api.put<Group>('/user/group', group)
|
||||
return this.api.put<Group>('/account/group', group)
|
||||
}
|
||||
|
||||
delete(id: number): Observable<Group> {
|
||||
return this.api.delete<Group>(`/user/group/${id}`)
|
||||
return this.api.delete<Group>(`/account/group/${id}`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,13 @@ export class Group {
|
|||
}
|
||||
}
|
||||
|
||||
export interface GroupToken {
|
||||
id: string,
|
||||
name: string,
|
||||
enabled: boolean,
|
||||
groupId: Group
|
||||
}
|
||||
|
||||
export enum Permission {
|
||||
VIEW_RECIPES = 'VIEW_RECIPES',
|
||||
VIEW_USERS = 'VIEW_USERS',
|
||||
|
|
Loading…
Reference in New Issue