angular-firebase-authorizator
Version:
Beta version of authorizator for angular linked to firebase, it creates a model in firestore to assign permissions to users an roles, and creates a view to update this permissions
1,332 lines • 67.1 kB
JavaScript
import { __decorate, __metadata, __param } from 'tslib';
import { ɵɵdefineInjectable, Injectable, InjectionToken, ChangeDetectorRef, Inject, Input, Component, EventEmitter, Output, ViewChild, NgModule } from '@angular/core';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { auth, firestore } from 'firebase';
import { Router } from '@angular/router';
import { take, map, catchError } from 'rxjs/operators';
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarConfig, MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { MatGridListModule } from '@angular/material/grid-list';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatSelect, MatSelectModule } from '@angular/material/select';
import { MatIconModule } from '@angular/material/icon';
import { MatTabsModule } from '@angular/material/tabs';
import { MatTableModule } from '@angular/material/table';
import { MatButtonModule } from '@angular/material/button';
import { MatInputModule } from '@angular/material/input';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { CommonModule } from '@angular/common';
import { DataSource } from '@angular/cdk/table';
import { FormGroup, FormControl, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
var Operation;
(function (Operation) {
Operation[Operation["Create"] = 0] = "Create";
Operation[Operation["Read"] = 1] = "Read";
Operation[Operation["Update"] = 2] = "Update";
Operation[Operation["Delete"] = 3] = "Delete";
Operation[Operation["Deny"] = 4] = "Deny";
})(Operation || (Operation = {}));
let ProgressbarService = class ProgressbarService {
constructor() {
this.usersWaitBar = new BehaviorSubject(null);
this.rolesWaitBar = new BehaviorSubject(null);
}
showUsersWaitBar(show) {
this.usersWaitBar.next(show);
}
showRolesWaitBar(show) {
this.rolesWaitBar.next(show);
}
};
ProgressbarService.ɵprov = ɵɵdefineInjectable({ factory: function ProgressbarService_Factory() { return new ProgressbarService(); }, token: ProgressbarService, providedIn: "root" });
ProgressbarService = __decorate([
Injectable({
providedIn: 'root'
}),
__metadata("design:paramtypes", [])
], ProgressbarService);
const AUTHORIZATOR_CONFIG = new InjectionToken('AUTHORIZATOR_CONFIG');
let AuthGuard = class AuthGuard {
constructor(router, authorizatorservice) {
this.router = router;
this.authorizatorservice = authorizatorservice;
}
isAuthorized(rootFirebasePath, resource) {
return new Observable(observer => {
auth().onAuthStateChanged(user => {
if (user) {
if (resource) {
Promise.all([
this.authorizatorservice.getUser(rootFirebasePath, user.email),
this.authorizatorservice.getRolesByUser(rootFirebasePath, user.email)
]).then(values => {
const userDB = values[0];
const rolesDB = values[1] || [];
const resourcePermissionsByUser = [];
const resourcePermissionsByRoles = [];
if (userDB && userDB.data.permissions) {
userDB.data.permissions.filter(permission => permission.resource === resource || permission.resource === 'owner').forEach(permission => {
resourcePermissionsByUser.push(permission);
});
}
rolesDB.forEach(rolDB => {
if (rolDB.data.permissions) {
rolDB.data.permissions.filter(permission => permission.resource === resource).forEach(permission => {
resourcePermissionsByRoles.push(permission);
});
}
});
if (resourcePermissionsByUser && resourcePermissionsByUser.length > 0 &&
resourcePermissionsByUser.findIndex(permission => permission.operations && permission.operations.findIndex(operation => operation === Operation.Deny) > -1) === -1) {
observer.next('authorized');
}
else {
if (resourcePermissionsByRoles && resourcePermissionsByRoles.length > 0 &&
resourcePermissionsByRoles.findIndex(permission => permission.operations.findIndex(operation => operation === Operation.Deny) > -1) === -1) {
observer.next('authorized');
}
else {
console.error('Unauthorized resource');
observer.next('unauthorized');
}
}
}).catch(error => {
console.error('Error getting permissions from database');
console.error(error);
observer.next('unauthorized');
});
}
else {
console.error('Resource not received');
observer.next('unauthorized');
}
}
else {
console.error('Unauthenticated user');
observer.next('unauthenticated');
}
}, err => {
observer.error(err);
}, () => {
observer.complete();
});
});
}
canActivate(route, state) {
let rootFirebasePath = route.data.rootFirebasePath;
const resource = route.data.resource;
const anonymousRoute = route.data.anonymousRoute || '/';
const unauthorizedRoute = route.data.unauthorizedRoute || '/';
const findVariable = rootFirebasePath.indexOf(':');
if (findVariable > -1) {
const variableEnd = rootFirebasePath.indexOf('/', findVariable);
let variableFound;
if (variableEnd > -1) {
variableFound = rootFirebasePath.substring(findVariable + 1, variableEnd);
}
else {
variableFound = rootFirebasePath.substring(findVariable + 1);
}
const existsVariable = Object.keys(route.params).findIndex(key => key === variableFound);
if (existsVariable > -1) {
rootFirebasePath = rootFirebasePath.replace(':' + variableFound, route.params[variableFound]);
}
}
return this.isAuthorized(rootFirebasePath, resource).pipe(take(1), map(isAuth => {
if (isAuth === 'unauthenticated') {
this.router.navigate([anonymousRoute], { queryParams: { returnUrl: state.url } });
return false;
}
if (isAuth === 'unauthorized') {
this.router.navigate([unauthorizedRoute], { queryParams: { returnUrl: state.url } });
return false;
}
if (isAuth === 'authorized') {
return true;
}
return false;
}), catchError((err) => {
console.error('Error getting authenticated user');
console.error(err);
// not resource sended so redirect to unauthorized page with the return url
this.router.navigate([anonymousRoute], { queryParams: { returnUrl: state.url } });
return of(false);
}));
}
};
AuthGuard.ctorParameters = () => [
{ type: Router },
{ type: AuthorizatorService }
];
AuthGuard = __decorate([
Injectable(),
__metadata("design:paramtypes", [Router, AuthorizatorService])
], AuthGuard);
let AuthorizatorService = class AuthorizatorService {
constructor() { }
//#region Users
addUser(rootFirebasePath, user) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).doc(user.id).get().then(userDB => {
if (userDB.exists) {
reject({ key: 'exists', message: 'User already exists' });
}
else {
firestore$1.collection(path).doc(user.id).set(user.data).then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error adding user' });
});
}
});
});
}
removeUser(rootFirebasePath, userId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).doc(userId).delete().then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error removing user' });
});
});
}
getUser(rootFirebasePath, userId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).doc(userId).get().then(userDB => {
resolve({
id: userDB.id,
data: userDB.data()
});
}).catch(error => {
reject(error);
});
});
}
getUsers(rootFirebasePath) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
if (!rootFirebasePath) {
rootFirebasePath = '';
}
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).get().then(usersDB => {
if (usersDB.empty) {
resolve(null);
}
else {
resolve(usersDB.docs.map(userDB => {
return {
id: userDB.id,
data: userDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
updateUserPermissions(rootFirebasePath, user) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).doc(user.id).get().then(userDB => {
if (!userDB.exists) {
reject({ key: 'notexists', message: 'User not exists' });
}
else {
firestore$1.collection(path).doc(user.id).update({ permissions: user.data.permissions }).then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error updating permissions' });
});
}
});
});
}
//#endregion
//#region Resources
addResource(rootFirebasePath, resource) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/resources').replace('//', '/');
firestore$1.collection(path).add(resource.data).then(resourceCreated => {
resolve(resourceCreated.id);
}).catch(error => {
reject(error);
});
});
}
removeResource(rootFirebasePath, resourceId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const resourcePath = (rootFirebasePath + '/resources').replace('//', '/');
const usersPath = (rootFirebasePath + '/users').replace('//', '/');
const rolesPath = (rootFirebasePath + '/roles').replace('//', '/');
const resourceRef = firestore$1.collection(resourcePath).doc(resourceId);
Promise.all([
this.getUsersByResource(rootFirebasePath, resourceId),
this.getRolesByResource(rootFirebasePath, resourceId)
]).then(values => {
const batch = firestore$1.batch();
const usersToUpdate = values[0];
const rolesToUpdate = values[1];
usersToUpdate.forEach(userToUpdate => {
userToUpdate.data.permissions.splice(userToUpdate.data.permissions.findIndex(permission => permission.resource === resourceId), 1);
const userRef = firestore$1.collection(usersPath).doc(userToUpdate.id);
batch.update(userRef, { data: userToUpdate.data });
});
rolesToUpdate.forEach(roleToUpdate => {
roleToUpdate.data.permissions.splice(roleToUpdate.data.permissions.findIndex(permission => permission.resource === resourceId), 1);
const roleRef = firestore$1.collection(rolesPath).doc(roleToUpdate.id);
batch.update(roleRef, { data: roleToUpdate.data });
});
batch.delete(resourceRef);
batch.commit().then(() => {
resolve();
}).catch(error => {
reject(error);
});
}).catch(error => {
reject(error);
});
});
}
updateResource(rootFirebasePath, resource) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/resources').replace('//', '/');
firestore$1.collection(path).doc(resource.id).set(resource.data).then(() => {
resolve();
}).catch(error => {
reject(error);
});
});
}
getResource(rootFirebasePath, resourceId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/resources').replace('//', '/');
firestore$1.collection(path).doc(resourceId).get().then(resourceDB => {
resolve({
id: resourceDB.id,
data: resourceDB.data()
});
}).catch(error => {
reject(error);
});
});
}
getResources(rootFirebasePath) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/resources').replace('//', '/');
firestore$1.collection(path).get().then(resourcesDB => {
if (resourcesDB.empty) {
resolve(null);
}
else {
resolve(resourcesDB.docs.map(resourceDB => {
return {
id: resourceDB.id,
data: resourceDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
// endregion
//#region Roles
addRole(rootFirebasePath, role) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).where('name', '==', role.data.name).get().then(roleDB => {
if (!roleDB.empty) {
reject({ key: 'exists', message: 'Role already exists' });
}
else {
firestore$1.collection(path).add(role.data).then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error adding role' });
});
}
});
});
}
removeRole(rootFirebasePath, roleId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).doc(roleId).delete().then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error removing role' });
});
});
}
updateRole(rootFirebasePath, role) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).doc(role.id).set(role.data).then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error updating role' });
});
});
}
getRole(rootFirebasePath, roleId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).doc(roleId).get().then(roleDB => {
resolve({
id: roleDB.id,
data: roleDB.data()
});
}).catch(error => {
reject(error);
});
});
}
getRoles(rootFirebasePath) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
if (!rootFirebasePath) {
rootFirebasePath = '';
}
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).get().then(rolesDB => {
if (rolesDB.empty) {
resolve(null);
}
else {
resolve(rolesDB.docs.map(roleDB => {
return {
id: roleDB.id,
data: roleDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
getRolesByResource(rootFirebasePath, resourceId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).where('data.resources', 'array-contains', resourceId).get().then(rolesDB => {
if (rolesDB.empty) {
resolve(null);
}
else {
resolve(rolesDB.docs.map(roleDB => {
return {
id: roleDB.id,
data: roleDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
getRolesByUser(rootFirebasePath, userId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).where('users', 'array-contains', userId).get().then(rolesDB => {
if (rolesDB.empty) {
resolve(null);
}
else {
resolve(rolesDB.docs.map(roleDB => {
return {
id: roleDB.id,
data: roleDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
updateRolePermissions(rootFirebasePath, role) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
rootFirebasePath = rootFirebasePath || '';
const path = (rootFirebasePath + '/roles').replace('//', '/');
firestore$1.collection(path).doc(role.id).get().then(roleDB => {
if (!roleDB.exists) {
reject({ key: 'notexists', message: 'Role not exists' });
}
else {
firestore$1.collection(path).doc(role.id).update({ permissions: role.data.permissions }).then(() => {
resolve();
}).catch(error => {
console.error(error);
reject({ key: 'defaulterror', message: 'Error updating permissions' });
});
}
});
});
}
// endregion
//#region Roles
removeUserFromRole(rootFirebasePath, userId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const usersPath = (rootFirebasePath + '/users').replace('//', '/');
const rolesPath = (rootFirebasePath + '/roles').replace('//', '/');
this.getRolesByUser(rootFirebasePath, userId).then(rolesDB => {
const batch = firestore$1.batch();
const rolesToUpdate = rolesDB;
rolesToUpdate.forEach(roleToUpdate => {
roleToUpdate.data.users.splice(roleToUpdate.data.users.findIndex(user => user === userId), 1);
const roleRef = firestore$1.collection(rolesPath).doc(roleToUpdate.id);
batch.update(roleRef, { data: roleToUpdate.data });
});
const userRef = firestore$1.collection(usersPath).doc(userId);
batch.delete(userRef);
batch.commit().then(() => {
resolve();
}).catch(error => {
reject(error);
});
}).catch(error => {
reject(error);
});
});
}
getUsersByResource(rootFirebasePath, resourceId) {
return new Promise((resolve, reject) => {
const firestore$1 = firestore();
const path = (rootFirebasePath + '/users').replace('//', '/');
firestore$1.collection(path).where('data.resources', 'array-contains', resourceId).get().then(usersDB => {
if (usersDB.empty) {
resolve(null);
}
else {
resolve(usersDB.docs.map(userDB => {
return {
id: userDB.id,
data: userDB.data()
};
}));
}
}).catch(error => {
reject(error);
});
});
}
};
AuthorizatorService = __decorate([
Injectable(),
__metadata("design:paramtypes", [])
], AuthorizatorService);
let AngularFirebaseAuthotizatorComponent = class AngularFirebaseAuthotizatorComponent {
constructor(progressbarservice, cd, authorizatorConfig, authroizatorservice) {
this.progressbarservice = progressbarservice;
this.cd = cd;
this.authorizatorConfig = authorizatorConfig;
this.authroizatorservice = authroizatorservice;
this.isUsersWaitBarShowing = false;
this.isRolesWaitBarShowing = false;
}
ngOnInit() {
this.progressbarservice.usersWaitBar.subscribe(isShowing => {
this.isUsersWaitBarShowing = isShowing;
this.cd.detectChanges();
});
this.progressbarservice.rolesWaitBar.subscribe(isShowing => {
this.isRolesWaitBarShowing = isShowing;
this.cd.detectChanges();
});
}
};
AngularFirebaseAuthotizatorComponent.ctorParameters = () => [
{ type: ProgressbarService },
{ type: ChangeDetectorRef },
{ type: undefined, decorators: [{ type: Inject, args: [AUTHORIZATOR_CONFIG,] }] },
{ type: AuthorizatorService }
];
__decorate([
Input(),
__metadata("design:type", String)
], AngularFirebaseAuthotizatorComponent.prototype, "rootFirebasePath", void 0);
AngularFirebaseAuthotizatorComponent = __decorate([
Component({
selector: 'angular-firebase-authotizator',
template: "<mat-tab-group>\n <mat-tab label=\"Users\">\n <mat-progress-bar color=\"accent\" mode=\"indeterminate\" *ngIf=\"isUsersWaitBarShowing\"></mat-progress-bar>\n <lib-users [rootFirebasePath]=\"rootFirebasePath\"></lib-users>\n </mat-tab>\n <mat-tab label=\"Roles\">\n <mat-progress-bar mode=\"indeterminate\" *ngIf=\"isRolesWaitBarShowing\"></mat-progress-bar>\n <lib-roles [rootFirebasePath]=\"rootFirebasePath\"></lib-roles>\n </mat-tab>\n</mat-tab-group>",
styles: ["table{width:100%}::ng-deep .success-bar{background-color:#c8e6c9!important;color:#1b5e20!important}::ng-deep .error-bar{background-color:#ffcdd2!important;color:#b71c1c!important}"]
}),
__param(2, Inject(AUTHORIZATOR_CONFIG)),
__metadata("design:paramtypes", [ProgressbarService, ChangeDetectorRef, Object, AuthorizatorService])
], AngularFirebaseAuthotizatorComponent);
let PermissionManagerComponent = class PermissionManagerComponent {
constructor(authorizatorConfig, cd, data, authorizatorservice, snackbar) {
this.authorizatorConfig = authorizatorConfig;
this.cd = cd;
this.data = data;
this.authorizatorservice = authorizatorservice;
this.snackbar = snackbar;
this.AllowedOperation = Operation;
this.resourceCols = 5;
this.permissionCols = 5;
this.change = new EventEmitter();
this.user = data.user;
this.role = data.role;
}
ngOnInit() {
if (this.authorizatorConfig && this.authorizatorConfig.permissions) {
this.permissionsConfig = this.authorizatorConfig.permissions.map(permission => {
return {
resource: permission.resource,
operations: permission.allowedOperations.map(operation => {
return {
id: operation,
value: this.user ?
(this.user.data.permissions ?
(this.user.data.permissions.find(perm => perm.resource === permission.resource.id) ?
(this.user.data.permissions.find(perm => perm.resource === permission.resource.id).operations.findIndex(oper => oper === operation) > -1) : false) : false) :
this.role ?
(this.role.data.permissions ?
(this.role.data.permissions.find(perm => perm.resource === permission.resource.id) ?
(this.role.data.permissions.find(perm => perm.resource === permission.resource.id).operations.findIndex(oper => oper === operation) > -1) : false) : false) : false
};
})
};
});
}
else {
console.error(`Configuration of module missing, please add the next code in the Module declaration:
AngularFirebaseAuthorizatorModule.forRoot({
permissions: [
{
resource: {
id: 'someid',
data: {
description: 'Resource description'
}
},
allowedOperations: [
Operation.Create,
Operation.Read,
Operation.Update,
Operation.Delete,
Operation.Deny
]
}
]
})`);
}
}
ngAfterViewInit() {
if (this.permissionsConfig) {
const permissionManagerWidth = document.getElementById('permission_manager_container').offsetWidth;
if (permissionManagerWidth <= 400) {
this.resourceCols = 5;
this.permissionCols = 5;
}
else if (permissionManagerWidth > 400 && permissionManagerWidth <= 600) {
this.resourceCols = 6;
this.permissionCols = 4;
}
else if (permissionManagerWidth > 600 && permissionManagerWidth <= 800) {
this.resourceCols = 7;
this.permissionCols = 3;
}
else {
this.resourceCols = 8;
this.permissionCols = 2;
}
}
this.cd.detectChanges();
}
onPermissionChange(resource, operation, event) {
const updatePermissionsMonitor = new BehaviorSubject(null);
const permissions = this.user ? this.user.data.permissions || [] :
this.role ? this.role.data.permissions || [] : [];
const permissionIndex = permissions.findIndex(permission => permission.resource === resource.id);
if (event.checked) {
if (permissionIndex > -1) {
const operationIndex = permissions[permissionIndex].operations.findIndex(oper => oper === operation);
if (operationIndex === -1) {
permissions[permissionIndex].operations.push(operation);
updatePermissionsMonitor.next(permissions);
}
}
else {
permissions.push({
resource: resource.id,
operations: [operation]
});
updatePermissionsMonitor.next(permissions);
}
}
else {
if (permissionIndex > -1) {
const operationIndex = permissions[permissionIndex].operations.findIndex(oper => oper === operation);
if (operationIndex > -1) {
if (permissions[permissionIndex].operations.length > 1) {
permissions[permissionIndex].operations.splice(operationIndex, 1);
}
else {
permissions.splice(permissionIndex, 1);
}
updatePermissionsMonitor.next(permissions);
}
}
}
updatePermissionsMonitor.subscribe(permissionsToUpdate => {
if (permissionsToUpdate) {
if (this.user) {
const userToUpdate = this.data.user;
userToUpdate.data.permissions = permissionsToUpdate;
const config = new MatSnackBarConfig();
config.duration = 2000;
this.authorizatorservice.updateUserPermissions(this.data.rootFirebasePath, userToUpdate).then(() => {
config.panelClass = ['success-bar'];
this.snackbar.open('Permissions updated', null, config);
}).catch(error => {
config.panelClass = ['error-bar'];
this.snackbar.open(error.message, null, config);
});
}
if (this.role) {
const roleToUpdate = this.data.role;
roleToUpdate.data.permissions = permissionsToUpdate;
const config = new MatSnackBarConfig();
config.duration = 2000;
this.authorizatorservice.updateRolePermissions(this.data.rootFirebasePath, roleToUpdate).then(() => {
config.panelClass = ['success-bar'];
this.snackbar.open('Permissions updated', null, config);
}).catch(error => {
console.log('ban5');
console.log(error);
config.panelClass = ['error-bar'];
this.snackbar.open(error.message, null, config);
});
}
updatePermissionsMonitor.unsubscribe();
}
});
}
};
PermissionManagerComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [AUTHORIZATOR_CONFIG,] }] },
{ type: ChangeDetectorRef },
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] },
{ type: AuthorizatorService },
{ type: MatSnackBar }
];
__decorate([
Output(),
__metadata("design:type", EventEmitter)
], PermissionManagerComponent.prototype, "change", void 0);
PermissionManagerComponent = __decorate([
Component({
selector: 'lib-permission-manager',
template: "<h1 mat-dialog-title>User Permissions</h1>\n<div mat-dialog-content>\n <div *ngIf=\"permissionsConfig\" id=\"permission_manager_container\">\n <div>\n <mat-grid-list cols=\"10\" rowHeight=\"48px\" style=\"width: 100%;\">\n <mat-grid-tile [colspan]=\"resourceCols\">\n Resource\n </mat-grid-tile>\n <mat-grid-tile [colspan]=\"permissionCols\">\n Permissions\n </mat-grid-tile>\n </mat-grid-list>\n </div>\n <div *ngFor=\"let permission of permissionsConfig\">\n <mat-grid-list cols=\"10\" rowHeight=\"48px\" style=\"width: 100%;\">\n <mat-grid-tile [rowspan]=\"permission.operations.length\" class=\"permission-grid\" [colspan]=\"resourceCols\">\n {{permission.resource.data.description}}\n </mat-grid-tile>\n <mat-grid-tile *ngFor=\"let operation of permission.operations\" class=\"permission-grid\" [colspan]=\"permissionCols\">\n <mat-slide-toggle [checked]=\"operation.value\"\n (change)=\"onPermissionChange(permission.resource, operation.id, $event)\">\n {{\n operation.id === AllowedOperation.Create ? 'Create' :\n operation.id === AllowedOperation.Read ? 'Read':\n operation.id === AllowedOperation.Update ? 'Update':\n operation.id === AllowedOperation.Delete ? 'Delete':\n operation.id === AllowedOperation.Deny ? 'Deny' : ''\n }}\n </mat-slide-toggle>\n </mat-grid-tile>\n </mat-grid-list>\n </div>\n </div> \n</div>\n<div mat-dialog-actions>\n <button mat-button cdkFocusInitial [mat-dialog-close]>Close</button>\n</div>\n\n",
styles: [".permission-grid{background:#f5f5f5;border:1px solid #d3d3d3}.mat-dialog-actions{-webkit-box-pack:end;justify-content:flex-end}div#permission_manager_container{margin-bottom:5px!important}"]
}),
__param(0, Inject(AUTHORIZATOR_CONFIG)),
__param(2, Inject(MAT_DIALOG_DATA)),
__metadata("design:paramtypes", [Object, ChangeDetectorRef, Object, AuthorizatorService,
MatSnackBar])
], PermissionManagerComponent);
let UpsertUserComponent = class UpsertUserComponent {
constructor(data, authorizatorservice, dialogRef) {
this.data = data;
this.authorizatorservice = authorizatorservice;
this.dialogRef = dialogRef;
this.userForm = new FormGroup({
email: new FormControl(null, [Validators.required, Validators.email])
});
}
onSubmitUser() {
if (this.userForm.valid) {
const userToAdd = {
id: this.userForm.controls.email.value,
data: {
name: null,
email: this.userForm.controls.email.value,
picture: null,
permissions: null
}
};
this.authorizatorservice.addUser(this.data.rootFirebasePath, userToAdd).then(() => {
this.dialogRef.close(userToAdd);
}).catch(error => {
if (error.key === 'exists') {
this.userForm.controls.email.setErrors({ exists: true });
}
else {
this.userForm.controls.email.setErrors({ defaulterror: true });
}
});
}
}
};
UpsertUserComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] },
{ type: AuthorizatorService },
{ type: MatDialogRef }
];
UpsertUserComponent = __decorate([
Component({
selector: 'lib-upsert-user',
template: "<form [formGroup]=\"userForm\" (ngSubmit)=\"onSubmitUser()\" method=\"post\">\n <h1 mat-dialog-title>{{data.type === 'add' ? 'Add User' : 'Edit User'}}</h1>\n <div mat-dialog-content>\n <mat-form-field style=\"width: 100%;\">\n <input matInput cdkFocusInitial type=\"email\" placeholder=\"Email\" formControlName=\"email\" maxlength=\"254\">\n <mat-error *ngIf=\"userForm.controls['email'].hasError('required')\">Mandatory field</mat-error>\n <mat-error *ngIf=\"userForm.controls['email'].hasError('email')\">Email format incorrect</mat-error>\n <mat-error *ngIf=\"userForm.controls['email'].hasError('exists')\">Email already exists</mat-error>\n <mat-error *ngIf=\"userForm.controls['email'].hasError('defaulterror')\">Error updating user</mat-error>\n </mat-form-field>\n </div>\n <div mat-dialog-actions>\n <button mat-button [mat-dialog-close]>Close</button>\n <button mat-raised-button type=\"submit\" [disabled]=\"!userForm.valid\">Add</button>\n </div>\n</form>\n",
styles: [".mat-dialog-actions{-webkit-box-pack:end;justify-content:flex-end}"]
}),
__param(0, Inject(MAT_DIALOG_DATA)),
__metadata("design:paramtypes", [Object, AuthorizatorService,
MatDialogRef])
], UpsertUserComponent);
let DeleteUserWarningComponent = class DeleteUserWarningComponent {
constructor(data) {
this.data = data;
}
ngOnInit() {
}
};
DeleteUserWarningComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] }
];
DeleteUserWarningComponent = __decorate([
Component({
selector: 'lib-delete-user-warning',
template: "<h1 mat-dialog-title>Remove User</h1>\n<div mat-dialog-content>\n <div>Are yo sure you want to remove user?</div>\n <div>{{data.id}}</div>\n</div>\n<div mat-dialog-actions>\n <button mat-button cdkFocusInitial [mat-dialog-close]>Close</button>\n <button mat-raised-button color=\"warn\" [mat-dialog-close]=\"true\">Remove</button>\n</div>",
styles: [".mat-dialog-actions{-webkit-box-pack:end;justify-content:flex-end}"]
}),
__param(0, Inject(MAT_DIALOG_DATA)),
__metadata("design:paramtypes", [Object])
], DeleteUserWarningComponent);
class UsersDatabase {
constructor() {
this.dataChange = new BehaviorSubject([]);
}
get data() { return this.dataChange.value; }
}
class UsersDataSource extends DataSource {
constructor(usersDatabase) {
super();
this.usersDatabase = usersDatabase;
}
connect() {
return this.usersDatabase.dataChange;
}
disconnect() { }
}
let UsersComponent = class UsersComponent {
constructor(authorizatorservice, dialog, snackbar, progressbarservice) {
this.authorizatorservice = authorizatorservice;
this.dialog = dialog;
this.snackbar = snackbar;
this.progressbarservice = progressbarservice;
this.displayedColumns = ['remove', 'user', 'permissions'];
this.usersDatabase = new UsersDatabase();
this.users = [];
}
ngOnInit() {
this.progressbarservice.showUsersWaitBar(true);
this.authorizatorservice.getUsers(this.rootFirebasePath).then(users => {
this.progressbarservice.showUsersWaitBar(false);
if (users) {
this.users = users.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.usersDataSource = new UsersDataSource(this.usersDatabase);
this.usersDatabase.dataChange.next(users);
}
});
}
addUser() {
const dialogRef = this.dialog.open(UpsertUserComponent, {
width: '300px',
data: { type: 'add', user: null, rootFirebasePath: this.rootFirebasePath }
});
dialogRef.afterClosed().subscribe(userAdded => {
if (userAdded) {
this.users.push(userAdded);
this.users = this.users.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.usersDatabase.dataChange.next(this.users);
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['success-bar'];
this.snackbar.open('User added successfully', null, config);
}
});
}
removeUser(user) {
const dialogRef = this.dialog.open(DeleteUserWarningComponent, {
width: '300px',
data: user
});
dialogRef.afterClosed().subscribe(response => {
if (response) {
this.progressbarservice.showUsersWaitBar(true);
this.authorizatorservice.removeUser(this.rootFirebasePath, user.id).then(() => {
this.progressbarservice.showUsersWaitBar(false);
this.users.splice(this.users.findIndex(userArr => userArr.id === user.id), 1);
this.usersDatabase.dataChange.next(this.users);
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['success-bar'];
this.snackbar.open('User removed successfully', null, config);
}).catch(error => {
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['error-bar'];
this.snackbar.open(error.message, null, config);
});
}
});
}
setPermissions(userInput) {
const dialogRef = this.dialog.open(PermissionManagerComponent, {
width: '95%',
maxWidth: '600px',
data: { rootFirebasePath: this.rootFirebasePath, user: userInput }
});
}
};
UsersComponent.ctorParameters = () => [
{ type: AuthorizatorService },
{ type: MatDialog },
{ type: MatSnackBar },
{ type: ProgressbarService }
];
__decorate([
Input(),
__metadata("design:type", String)
], UsersComponent.prototype, "rootFirebasePath", void 0);
UsersComponent = __decorate([
Component({
selector: 'lib-users',
template: "<div class=\"users-container\">\n <button mat-raised-button (click)=\"addUser()\"><mat-icon color=\"primary\">person_add</mat-icon> Add User</button>\n <table mat-table [dataSource]=\"usersDataSource\" style=\"width: 100%;\">\n <!--- Note that these columns can be defined in any order.\n The actual rendered columns are set as a property on the row definition\" -->\n \n <!-- Remove Column -->\n <ng-container matColumnDef=\"remove\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'icon-column'\"></th>\n <td mat-cell *matCellDef=\"let user\" [ngClass]=\"'icon-column'\">\n <button mat-icon-button (click)=\"removeUser(user)\">\n <mat-icon color=\"primary\" aria-label=\"Remove user\">delete</mat-icon>\n </button>\n </td>\n </ng-container>\n \n <!-- User Column -->\n <ng-container matColumnDef=\"user\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'users-column'\"> User </th>\n <td mat-cell *matCellDef=\"let user\" [ngClass]=\"'users-column'\">\n <div>{{user.data.name}}</div>\n <div>{{user.data.email}}</div>\n </td>\n </ng-container>\n \n <!-- Permissions Column -->\n <ng-container matColumnDef=\"permissions\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'permissions-column'\">Permissions</th>\n <td mat-cell *matCellDef=\"let user\" [ngClass]=\"'permissions-column'\">\n <button mat-button (click)=\"setPermissions(user)\">\n <mat-icon color=\"primary\" aria-label=\"Set permissions\">vpn_key</mat-icon>\n </button>\n </td>\n </ng-container>\n \n <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n </table>\n</div>\n",
styles: [".icon-column{-webkit-box-flex:0;flex:0 0 50px}.permissions-column{-webkit-box-flex:0;flex:0 0 100px}.users-column{-webkit-box-flex:0;flex:0 0 300px}.users-container{width:470px;margin:auto;padding:20px}"]
}),
__metadata("design:paramtypes", [AuthorizatorService, MatDialog,
MatSnackBar,
ProgressbarService])
], UsersComponent);
class UsersDatabase$1 {
constructor() {
this.dataChange = new BehaviorSubject([]);
}
get data() { return this.dataChange.value; }
}
class UsersDataSource$1 extends DataSource {
constructor(usersDatabase) {
super();
this.usersDatabase = usersDatabase;
}
connect() {
return this.usersDatabase.dataChange;
}
disconnect() { }
}
let UpsertRoleComponent = class UpsertRoleComponent {
constructor(data, authorizatorservice, dialogRef) {
this.data = data;
this.authorizatorservice = authorizatorservice;
this.dialogRef = dialogRef;
this.displayedColumns = ['remove', 'user'];
this.usersDatabase = new UsersDatabase$1();
this.users = [];
this.roleUsers = [];
this.roleForm = new FormGroup({
name: new FormControl(null, [Validators.required]),
description: new FormControl(null),
});
}
ngOnInit() {
this.usersDataSource = new UsersDataSource$1(this.usersDatabase);
this.authorizatorservice.getUsers(this.data.rootFirebasePath).then(users => {
if (users) {
this.users = users.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.roleUsers = this.users.filter(user => this.data && this.data.role && this.data.role.data.users.findIndex(usr => usr === user.id) > -1);
if (this.roleUsers) {
this.roleUsers = this.roleUsers.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.usersDatabase.dataChange.next(this.roleUsers);
}
}
});
if (this.data.role) {
this.roleForm.controls.name.setValue(this.data.role.data.name);
this.roleForm.controls.description.setValue(this.data.role.data.description);
}
}
onAddUserToRole() {
const existUser = this.roleUsers.findIndex(roleUser => roleUser.id === this.selectUser.value);
if (existUser === -1) {
this.roleUsers.push(this.users.find(user => user.id === this.selectUser.value));
this.roleUsers = this.roleUsers.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.usersDatabase.dataChange.next(this.roleUsers);
}
}
onRemoveUserFromRole(user) {
const userIndex = this.roleUsers.findIndex(roleUser => roleUser.id === user.id);
if (userIndex > -1) {
this.roleUsers.splice(userIndex, 1);
this.usersDatabase.dataChange.next(this.roleUsers);
}
}
onSubmitRole() {
if (this.roleForm.valid) {
const roleToAdd = {
id: this.data.role ? this.data.role.id : null,
data: {
name: this.roleForm.controls.name.value,
description: this.roleForm.controls.description.value,
users: this.roleUsers.map(user => user.id),
permissions: null
}
};
if (roleToAdd.id) {
this.authorizatorservice.updateRole(this.data.rootFirebasePath, roleToAdd).then(() => {
this.dialogRef.close(roleToAdd);
}).catch(error => {
this.roleForm.controls.name.setErrors({ defaulterror: true });
});
}
else {
this.authorizatorservice.addRole(this.data.rootFirebasePath, roleToAdd).then(() => {
this.dialogRef.close(roleToAdd);
}).catch(error => {
if (error.key === 'exists') {
this.roleForm.controls.name.setErrors({ exists: true });
}
else {
this.roleForm.controls.name.setErrors({ defaulterror: true });
}
});
}
}
}
};
UpsertRoleComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] },
{ type: AuthorizatorService },
{ type: MatDialogRef }
];
__decorate([
ViewChild('selectUser'),
__metadata("design:type", MatSelect)
], UpsertRoleComponent.prototype, "selectUser", void 0);
UpsertRoleComponent = __decorate([
Component({
selector: 'lib-upsert-role',
template: "<form [formGroup]=\"roleForm\" (ngSubmit)=\"onSubmitRole()\" method=\"post\">\n <h1 mat-dialog-title>{{data.role ? 'Edit Role' : 'Add Role'}}</h1>\n <div mat-dialog-content>\n <mat-form-field style=\"width: 100%;\">\n <input matInput cdkFocusInitial placeholder=\"Name\" formControlName=\"name\" maxlength=\"30\">\n <mat-error *ngIf=\"roleForm.controls['name'].hasError('required')\">Mandatory field</mat-error>\n <mat-error *ngIf=\"roleForm.controls['name'].hasError('exists')\">Email already exists</mat-error>\n <mat-error *ngIf=\"roleForm.controls['name'].hasError('defaulterror')\">Error updating role</mat-error>\n </mat-form-field>\n <mat-form-field style=\"width: 100%;\">\n <input matInput cdkFocusInitial placeholder=\"Description\" formControlName=\"description\" maxlength=\"150\">\n </mat-form-field>\n <table style=\"width: 100%;\">\n <tr>\n <th style=\"width: 100%;\">\n <mat-form-field style=\"width: 100%;\">\n <mat-label>User</mat-label>\n <mat-select #selectUser>\n <mat-option *ngFor=\"let user of users\" [value]=\"user.id\">\n {{user.data.name || user.data.email}}\n </mat-option>\n </mat-select>\n </mat-form-field>\n </th>\n <th>\n <button type=\"button\" [disabled]=\"!this.selectUser.value\" mat-raised-button (click)=\"onAddUserToRole()\">\n <mat-icon color=\"primary\">person_add</mat-icon> Add User\n </button>\n </th>\n </tr>\n </table>\n <table mat-table [dataSource]=\"usersDataSource\" style=\"width: 100%;\">\n \n <!-- Remove Column -->\n <ng-container matColumnDef=\"remove\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'icon-column'\"></th>\n <td mat-cell *matCellDef=\"let user\" [ngClass]=\"'icon-column'\">\n <button mat-icon-button (click)=\"onRemoveUserFromRole(user)\">\n <mat-icon color=\"primary\" aria-label=\"Remove user\">delete</mat-icon>\n </button>\n </td>\n </ng-container>\n \n <!-- User Column -->\n <ng-container matColumnDef=\"user\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'users-column'\"> User </th>\n <td mat-cell *matCellDef=\"let user\" [ngClass]=\"'users-column'\">\n <div>{{user.data.name}}</div>\n <div>{{user.data.email}}</div>\n </td>\n </ng-container>\n \n <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n </table>\n </div>\n <div mat-dialog-actions>\n <button mat-button [mat-dialog-close]>Close</button>\n <button mat-raised-button color=\"primary\" type=\"submit\" [disabled]=\"!roleForm.valid\">{{data.role ? 'Update' : 'Add'}}</button>\n </div>\n</form>\n ",
styles: [".mat-dialog-actions{-webkit-box-pack:end;justify-content:flex-end}"]
}),
__param(0, Inject(MAT_DIALOG_DATA)),
__metadata("design:paramtypes", [Object, AuthorizatorService,
MatDialogRef])
], UpsertRoleComponent);
let DeleteRoleWarningComponent = class DeleteRoleWarningComponent {
constructor(data) {
this.data = data;
}
ngOnInit() {
}
};
DeleteRoleWarningComponent.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] }
];
DeleteRoleWarningComponent = __decorate([
Component({
selector: 'lib-delete-role-warning',
template: "<h1 mat-dialog-title>Remove Role</h1>\n<div mat-dialog-content>\n <div>Are yo sure you want to remove role?</div>\n <div>{{data.data.name}}</div>\n</div>\n<div mat-dialog-actions>\n <button mat-button cdkFocusInitial [mat-dialog-close]>Close</button>\n <button mat-raised-button color=\"warn\" [mat-dialog-close]=\"true\">Remove</button>\n</div>",
styles: [".mat-dialog-actions{-webkit-box-pack:end;justify-content:flex-end}"]
}),
__param(0, Inject(MAT_DIALOG_DATA)),
__metadata("design:paramtypes", [Object])
], DeleteRoleWarningComponent);
class RolesDatabase {
constructor() {
this.dataChange = new BehaviorSubject([]);
}
get data() { return this.dataChange.value; }
}
class RolesDataSource extends DataSource {
constructor(rolesDatabase) {
super();
this.rolesDatabase = rolesDatabase;
}
connect() {
return this.rolesDatabase.dataChange;
}
disconnect() { }
}
let RolesComponent = class RolesComponent {
constructor(authorizatorservice, dialog, snackbar, progressbarservice) {
this.authorizatorservice = authorizatorservice;
this.dialog = dialog;
this.snackbar = snackbar;
this.progressbarservice = progressbarservice;
this.displayedColumns = ['remove', 'edit', 'role', 'permissions'];
this.rolesDatabase = new RolesDatabase();
this.roles = [];
}
ngOnInit() {
this.progressbarservice.showRolesWaitBar(true);
this.authorizatorservice.getRoles(this.rootFirebasePath).then(roles => {
if (roles) {
this.roles = roles.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.rolesDataSource = new RolesDataSource(this.rolesDatabase);
this.rolesDatabase.dataChange.next(roles);
this.progressbarservice.showRolesWaitBar(false);
}
}).catch(error => {
console.error(error);
}).finally(() => {
this.progressbarservice.showRolesWaitBar(false);
});
}
addRole() {
const dialogRef = this.dialog.open(UpsertRoleComponent, {
width: '95%',
maxWidth: '500px',
data: { role: null, rootFirebasePath: this.rootFirebasePath }
});
dialogRef.afterClosed().subscribe(roleAdded => {
if (roleAdded) {
this.roles.push(roleAdded);
this.roles = this.roles.sort((prev, curr) => {
if (prev.data.name > curr.data.name) {
return 1;
}
if (prev.data.name < curr.data.name) {
return -1;
}
return 0;
});
this.rolesDatabase.dataChange.next(this.roles);
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['success-bar'];
this.snackbar.open('Role added successfully', null, config);
}
});
}
editRole(inputRole) {
const dialogRef = this.dialog.open(UpsertRoleComponent, {
width: '95%',
maxWidth: '500px',
data: { role: inputRole, rootFirebasePath: this.rootFirebasePath }
});
dialogRef.afterClosed().subscribe(roleUpdated => {
if (roleUpdated) {
const roleUpdatedIndex = this.roles.findIndex(role => role.id === roleUpdated.id);
if (roleUpdatedIndex > -1) {
this.roles[roleUpdatedIndex].data = roleUpdated.data;
this.rolesDatabase.dataChange.next(this.roles);
}
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['success-bar'];
this.snackbar.open('Role updated successfully', null, config);
}
});
}
removeRole(role) {
const dialogRef = this.dialog.open(DeleteRoleWarningComponent, {
width: '300px',
data: role
});
dialogRef.afterClosed().subscribe(response => {
if (response) {
this.progressbarservice.showRolesWaitBar(true);
this.authorizatorservice.removeRole(this.rootFirebasePath, role.id).then(() => {
this.roles.splice(this.roles.findIndex(roleArr => roleArr.id === role.id), 1);
this.rolesDatabase.dataChange.next(this.roles);
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['success-bar'];
this.snackbar.open('Role removed successfully', null, config);
this.progressbarservice.showRolesWaitBar(false);
}).catch(error => {
const config = new MatSnackBarConfig();
config.duration = 3000;
config.panelClass = ['error-bar'];
this.snackbar.open(error.message, null, config);
});
}
});
}
setPermissions(roleInput) {
const dialogRef = this.dialog.open(PermissionManagerComponent, {
width: '95%',
maxWidth: '600px',
data: { rootFirebasePath: this.rootFirebasePath, role: roleInput }
});
}
};
RolesComponent.ctorParameters = () => [
{ type: AuthorizatorService },
{ type: MatDialog },
{ type: MatSnackBar },
{ type: ProgressbarService }
];
__decorate([
Input(),
__metadata("design:type", String)
], RolesComponent.prototype, "rootFirebasePath", void 0);
RolesComponent = __decorate([
Component({
selector: 'lib-roles',
template: "<div class=\"roles-container\">\n <button mat-raised-button (click)=\"addRole()\"><mat-icon color=\"primary\">group_add</mat-icon> Add Role</button>\n <table mat-table [dataSource]=\"rolesDataSource\" style=\"width: 100%;\">\n <!--- Note that these columns can be defined in any order.\n The actual rendered columns are set as a property on the row definition\" -->\n \n <!-- Remove Column -->\n <ng-container matColumnDef=\"remove\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'icon-column'\"></th>\n <td mat-cell *matCellDef=\"let role\" [ngClass]=\"'icon-column'\">\n <button mat-icon-button (click)=\"removeRole(role)\">\n <mat-icon color=\"primary\" aria-label=\"Remove role\">delete</mat-icon>\n </button>\n </td>\n </ng-container>\n\n <!-- Edit Column -->\n <ng-container matColumnDef=\"edit\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'icon-column'\"></th>\n <td mat-cell *matCellDef=\"let role\" [ngClass]=\"'icon-column'\">\n <button mat-icon-button (click)=\"editRole(role)\">\n <mat-icon color=\"primary\" aria-label=\"Edit role\">edit</mat-icon>\n </button>\n </td>\n </ng-container>\n \n <!-- Role Column -->\n <ng-container matColumnDef=\"role\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'roles-column'\"> User </th>\n <td mat-cell *matCellDef=\"let role\" [ngClass]=\"'roles-column'\">\n <div>{{role.data.name}}</div>\n <div>{{role.data.email}}</div>\n </td>\n </ng-container>\n \n <!-- Permissions Column -->\n <ng-container matColumnDef=\"permissions\">\n <th mat-header-cell *matHeaderCellDef [ngClass]=\"'permissions-column'\">Permissions</th>\n <td mat-cell *matCellDef=\"let role\" [ngClass]=\"'permissions-column'\">\n <button mat-button (click)=\"setPermissions(role)\">\n <mat-icon color=\"primary\" aria-label=\"Set permissions\">vpn_key</mat-icon>\n </button>\n </td>\n </ng-container>\n \n <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n </table>\n</div>\n ",
styles: [".icon-column{-webkit-box-flex:0;flex:0 0 50px}.permissions-column{-webkit-box-flex:0;flex:0 0 100px}.roles-column{-webkit-box-flex:0;flex:0 0 300px}.roles-container{width:470px;margin:auto;padding:20px}"]
}),
__metadata("design:paramtypes", [AuthorizatorService, MatDialog,
MatSnackBar,
ProgressbarService])
], RolesComponent);
var AngularFirebaseAuthorizatorModule_1;
let AngularFirebaseAuthorizatorModule = AngularFirebaseAuthorizatorModule_1 = class AngularFirebaseAuthorizatorModule {
static forRoot(authorizatorConfig) {
return {
ngModule: AngularFirebaseAuthorizatorModule_1,
providers: [
{
provide: AUTHORIZATOR_CONFIG,
useValue: authorizatorConfig
}
]
};
}
};
AngularFirebaseAuthorizatorModule = AngularFirebaseAuthorizatorModule_1 = __decorate([
NgModule({
declarations: [
PermissionManagerComponent, AngularFirebaseAuthotizatorComponent,
UsersComponent, UpsertUserComponent, DeleteUserWarningComponent,
RolesComponent, DeleteRoleWarningComponent, UpsertRoleComponent
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
MatGridListModule,
MatSlideToggleModule,
MatButtonToggleModule,
MatSelectModule,
MatIconModule,
MatTabsModule,
MatTableModule,
MatButtonModule,
MatDialogModule,
MatInputModule,
MatSnackBarModule,
MatProgressBarModule
],
exports: [AngularFirebaseAuthotizatorComponent],
providers: [AuthorizatorService, ProgressbarService],
entryComponents: [
UpsertUserComponent, DeleteUserWarningComponent,
UpsertRoleComponent, DeleteRoleWarningComponent,
PermissionManagerComponent
]
})
], AngularFirebaseAuthorizatorModule);
/*
* Public API Surface of angular-firebase-authorizator
*/
/**
* Generated bundle index. Do not edit.
*/
export { AngularFirebaseAuthorizatorModule, AngularFirebaseAuthotizatorComponent, AuthGuard, AuthorizatorService, Operation, AUTHORIZATOR_CONFIG as ɵa, ProgressbarService as ɵb, PermissionManagerComponent as ɵc, UsersComponent as ɵd, UpsertUserComponent as ɵe, DeleteUserWarningComponent as ɵf, RolesComponent as ɵg, DeleteRoleWarningComponent as ɵh, UpsertRoleComponent as ɵi };
//# sourceMappingURL=angular-firebase-authorizator.js.map