Skip to content
Snippets Groups Projects
Commit eb17629b authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Merge branch 'develop' into 'release/1.7.1'

Develop

See merge request !114
parents 3264c605 ddb43f42
No related branches found
No related tags found
4 merge requests!184Develop,!119Develop,!118Release/1.7.1,!114Develop
......@@ -25,6 +25,7 @@ export class LoginSuccessComponent implements OnInit {
if (refreshToken) {
this.authService.storeOidcToken(oidcToken);
}
this.authService.loadUser();
this.router.navigate(['/'])
})
......
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
import { AuthService } from '../auth/auth.service';
@Directive({
selector: '[rolesExcluded]'
})
export class RolesExcludedDirective {
private _excluded: Array<string> = [];
constructor(
private _templateRef: TemplateRef<any>,
private _viewContainer: ViewContainerRef,
private authService: AuthService
) {}
@Input() set rolesExcluded(excludedRoles: Array<string>) {
this._excluded = excludedRoles;
this.updateState();
}
private updateState() {
this._viewContainer.clear();
const hasExcludedRole = this._excluded.some(role => this.authService.hasRole(role));
if (!hasExcludedRole) {
// If user has exluded role hide the element
this._viewContainer.createEmbeddedView(this._templateRef);
}
}
}
\ No newline at end of file
......@@ -3,10 +3,7 @@ import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core';
class RoleState {
public allowed: Array<string> = new Array<string>();
public excluded: Array<string> = new Array<string>()
}
@Directive({
selector: '[roles]',
inputs: ['roles']
......@@ -15,8 +12,6 @@ export class RolesDirective {
private _allowed: Array<string> = new Array<string>();
private _excluded: Array<string> = new Array<string>();
constructor(private _templateRef: TemplateRef<any>,
private _viewContainer: ViewContainerRef,
private authService: AuthService) {
......@@ -26,53 +21,18 @@ export class RolesDirective {
@Input() set roles(allowedRoles: Array<string>) {
this._allowed = allowedRoles;
this.updateState({
allowed: this._allowed,
excluded: this._excluded
})
}
// Excluded roles have priority than allowed roles
// If user have excluded role template would not be shown
@Input() set rolesExcluded(excluded: Array<string>) {
this._excluded = excluded;
this.updateState({
allowed: this._allowed,
excluded: this._excluded
allowed: this._allowed
})
}
updateState(state: RoleState) {
this._viewContainer.clear();
let show: boolean = false;
let notAllowed: boolean = false;
const allowedRoles = state.allowed;
for (let exclude of state.excluded) {
if (this.authService.hasRole(exclude)) {
notAllowed = true;
break;
}
const hasAllowedRole = state.allowed.some(role => this.authService.hasRole(role));
if (hasAllowedRole) {
this._viewContainer.createEmbeddedView(this._templateRef);
}
if (notAllowed) {
this._viewContainer.clear();
} else {
for (let allowedRole of allowedRoles) {
if (this.authService.hasRole(allowedRole)) {
show = true;
break;
}
}
if (show) {
this._viewContainer.createEmbeddedView(this._templateRef);
} else {
this._viewContainer.clear();
}
}
}
}
......@@ -77,10 +77,13 @@
<li *roles="['ROLE_SYSTEM_ADMIN']"><a
[routerLink]="['/admin/users']">{{ 'NAVBAR.USERS' | translate }}</a>
</li>
<li *roles="['ROLE_DOMAIN_ADMIN', 'ROLE_GROUP_DOMAIN_ADMIN']" >
<a *rolesExcluded="['ROLE_SYSTEM_ADMIN']"
[routerLink]="['/domain/users']">{{ 'NAVBAR.DOMAIN_USERS' | translate }}</a>
<li *roles="['ROLE_DOMAIN_ADMIN', 'ROLE_GROUP_DOMAIN_ADMIN']">
<a *rolesExcluded="['ROLE_SYSTEM_ADMIN']"
[routerLink]="['/domain/users']">{{ 'NAVBAR.DOMAIN_USERS' | translate }}</a>
</li>
<li *roles="['ROLE_SYSTEM_ADMIN']"><a
[routerLink]="['/admin/languages']">{{ 'NAVBAR.LANGUAGES' | translate }}</a>
</li>
......
import {DefaultLogo} from '../directive/defaultlogo.directive';
import {RolesDirective} from '../directive/roles.directive';
import {NgModule} from '@angular/core';
import {NgModule, NO_ERRORS_SCHEMA} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {CommonModule, DatePipe} from '@angular/common';
......@@ -65,6 +65,7 @@ import { InputGroupModule } from 'primeng/inputgroup';
import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
import { ButtonModule } from 'primeng/button';
import { BrowserModule } from '@angular/platform-browser';
import { RolesExcludedDirective } from '../directive/roles-exluded.directive';
@NgModule({
......@@ -103,6 +104,7 @@ import { BrowserModule } from '@angular/platform-browser';
NavbarComponent,
DefaultLogo,
RolesDirective,
RolesExcludedDirective,
MinLengthDirective,
MaxLengthDirective,
SearchComponent,
......@@ -179,13 +181,16 @@ import { BrowserModule } from '@angular/platform-browser';
ModalTestInstanceComponent,
ModalNotificationSendComponent,
DomainRolesDirective,
RolesExcludedDirective,
SshKeysComponent,
ModalProvideSshKeyComponent,
PreferencesComponent,
SortableHeaderDirective,
DomainNamespaceAnnotationsComponent,
AccessTokensComponent
]
],
schemas: [NO_ERRORS_SCHEMA], // Dodanie schematu
})
export class SharedModule {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment