Skip to content

Commit

Permalink
ctx/ou names in grant list
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmfrank committed Jul 25, 2018
1 parent a3daf6e commit ab6b46a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/app/base/common/http-error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export class HttpErrorInterceptor implements HttpInterceptor {
catchError((err: HttpErrorResponse) => {
if (err.error instanceof Error) {
this.messages.error(`${err.status}, ` + err.error.message);
} else if (err.error instanceof Object) {
this.messages.error(`${err.status}, ERROR: ` + JSON.stringify(err.error));
} else {
// this.messages.error(`${err.status}, ERROR: ` + JSON.stringify(err.error));
this.messages.error(`${err.status}: ` + err.error);
}
return empty();
Expand Down
5 changes: 3 additions & 2 deletions src/app/base/services/elastic-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export class ElasticGuard implements CanActivate {
}

getThePermission(): boolean {
const phrase = prompt('not even roland is allowd 2 do that!');
if (phrase === environment.elastic_admin) {
const phrase = prompt('not even roland is allowd 2 do that !\nwho do you think you are ?');
const answer = prompt('you think you\'re ' + phrase + ' ?\nbut can you guess my name ?')
if (answer === environment.elastic_admin) {
return true;
} else {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/app/users/grants/grants.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ export class GrantsComponent implements OnInit, OnDestroy {
if (this.selectedGrants.length > 0) {
this.usersService.addGrants(this.selectedUser, this.selectedGrants, this.token).subscribe(user => {
this.selectedUser = user;
if (this.selectedUser.grantList) {
this.selectedUser.grantList.forEach(grant => this.usersService.addNamesOfGrantRefs(grant));
}
this.selectedUserChange.emit(this.selectedUser);
this.messageService.success('added Grants to ' + this.selectedUser.loginname);
this.selectedGrants = null;
Expand Down
12 changes: 10 additions & 2 deletions src/app/users/services/user-details-resolver.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Router, Resolve, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { first } from 'rxjs/operators';
import { first, map } from 'rxjs/operators';

import { UsersService } from './users.service';
import { User, Grant, BasicRO } from '../../base/common/model';
Expand All @@ -24,9 +24,17 @@ export class UserDetailsResolverService implements Resolve<User> {
return of(user);
} else {
const token = route.queryParams['token'];
let user: User;
return this.userSvc.get(url, id, token)
.pipe(
first()
first(),
map((response) => {
user = response;
if (user.grantList) {
user.grantList.forEach(grant => this.userSvc.addNamesOfGrantRefs(grant));
}
return user;
})
);
}
}
Expand Down
26 changes: 25 additions & 1 deletion src/app/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

import { User, Grant } from '../../base/common/model';
import { MessagesService } from '../../base/services/messages.service';
import { PubmanRestService } from '../../base/services/pubman-rest.service';
import { environment } from '../../../environments/environment';

Expand All @@ -11,10 +12,14 @@ import { environment } from '../../../environments/environment';
export class UsersService extends PubmanRestService {

usersUrl: string = environment.rest_url + environment.rest_users;
ous_url = environment.rest_url + environment.rest_ous;
ctxs_url = environment.rest_url + environment.rest_contexts;

users: User[] = [];
user: User;

constructor(httpc: HttpClient) {
constructor(httpc: HttpClient,
private messageService: MessagesService) {
super(httpc);
}

Expand Down Expand Up @@ -53,4 +58,23 @@ export class UsersService extends PubmanRestService {
return this.getResource('PUT', userUrl, headers, body);
}

addNamesOfGrantRefs(grant) {
const ref = grant.objectRef;
if (ref === undefined) {
} else {
if (ref.startsWith('ou')) {
this.get(this.ous_url, ref, null)
.subscribe(ou => {
grant.ctxTitle = ou.metadata.name;
});
} else {
if (ref.startsWith('ctx')) {
this.get(this.ctxs_url, ref, null)
.subscribe(ctx => {
grant.ctxTitle = ctx.name;
});
}
}
}
}
}
9 changes: 5 additions & 4 deletions src/app/users/user-details/user-details.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,23 @@ <h4 class="card-title">{{selected.loginname}}</h4>
<label for="addGrantButton" class="col-2 col-form-label col-form-label-sm">grants</label>
<div class="col-10 text-right">
<ul class="list-group">
<li class="list-group-item-primary list-group-item-action py-0 d-flex flex-sm-row no-gutters align-items-center" *ngFor="let usergrant of selected.grantList" (click)="goToRef(usergrant)">
<!--<div class="row">-->
<li class="list-group-item-primary list-group-item-action py-0 align-items-center" *ngFor="let usergrant of selected.grantList" (click)="goToRef(usergrant)">
<div class="row">
<span class="col-3 text-left text-truncate">
<label class="col-form-label-sm p-0 ml-2" [innerHtml]="usergrant.role"></label>
</span>
<span class="col-6 text-left text-truncate">
<label class="col-form-label-sm p-0" [innerHtml]="usergrant.ctxTitle"></label>
</span>
<span class="col-2 text-left">
<label class="col-form-label-sm p-0" [innerHtml]="usergrant.objectRef" (mouseover)="viewRefTitle(usergrant)" data-toggle="tooltip" data-placement="right" title="{{ctxTitle}}"></label>
<!--<label class="col-form-label-sm p-0" [innerHtml]="usergrant.objectRef" (mouseover)="viewRefTitle(usergrant)" data-toggle="tooltip" data-placement="right" title="{{ctxTitle}}"></label>-->
<label class="col-form-label-sm p-0" [innerHtml]="usergrant.objectRef"></label>
</span>
<span class="col-1">
<input type="button" class="btn btn-outline-primary btn-sm" (click)="deleteGrant(usergrant); $event.stopPropagation()" name="deleteGrant"
value="x" />
</span>
<!--</div>-->
</div>
</li>
</ul>
</div>
Expand Down
37 changes: 6 additions & 31 deletions src/app/users/user-details/user-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export class UserDetailsComponent implements OnInit, OnDestroy {
});

this.selected = this.route.snapshot.data['user'];
if (this.selected.grantList) {
this.selected.grantList.forEach(grant => this.addTitles2GrantRefs(grant));
}

if (this.route.snapshot.queryParams['admin']) {
this.isAdmin = this.route.snapshot.queryParams['admin'];
}
Expand Down Expand Up @@ -116,32 +114,6 @@ export class UserDetailsComponent implements OnInit, OnDestroy {
}
}

addTitles2GrantRefs(grant) {
const ref = grant.objectRef;
if (ref === undefined) {
} else {
if (ref.startsWith('ou')) {
this.usersService.get(this.ous_url, ref, null)
.subscribe(ou => {
grant.ctxTitle = ou.metadata.name;
},
(err) => {
this.messageService.error(JSON.stringify(err));
});
} else {
if (ref.startsWith('ctx')) {
this.usersService.get(this.ctxs_url, ref, null)
.subscribe(ctx => {
grant.ctxTitle = ctx.name;
},
(err) => {
this.messageService.error(JSON.stringify(err));
});
}
}
}
}

viewRefTitle(grant) {
const ref = grant.objectRef;
if (ref === undefined) {
Expand Down Expand Up @@ -220,8 +192,8 @@ export class UserDetailsComponent implements OnInit, OnDestroy {

save(user2save) {
this.selected = user2save;
if (this.selected.loginname.startsWith('new ')) {
this.messageService.warning('loginname MUST NOT be new <something>');
if (this.selected.loginname.includes(' ')) {
this.messageService.warning('loginname MUST NOT contain spaces');
return;
}
if (this.selected.name == null) {
Expand Down Expand Up @@ -280,6 +252,9 @@ export class UserDetailsComponent implements OnInit, OnDestroy {
removeGrants() {
this.usersService.removeGrants(this.selected, this.selectedGrants, this.token).subscribe(user => {
this.selected = user;
if (this.selected.grantList) {
this.selected.grantList.forEach(grant => this.usersService.addNamesOfGrantRefs(grant));
}
this.messageService.success('removed Grants from ' + this.selected.loginname);
this.selectedGrants = null;
this.grants2remove = false;
Expand Down
Binary file removed src/assets/mpdl.jpg
Binary file not shown.

0 comments on commit ab6b46a

Please sign in to comment.