Skip to content

Commit

Permalink
Merge pull request #87 from OS2iot/feature/1242_new-user-management-m…
Browse files Browse the repository at this point in the history
…ultiple-levels

New user management multiple levels
  • Loading branch information
AramAlsabti authored May 19, 2022
2 parents 73054c3 + 531c2c7 commit ba6273b
Show file tree
Hide file tree
Showing 164 changed files with 5,848 additions and 1,696 deletions.
1,587 changes: 719 additions & 868 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@angular/forms": "~9.1.11",
"@angular/localize": "^9.1.11",
"@angular/material": "^9.2.4",
"@angular/material-moment-adapter": "^9.2.4",
"@angular/platform-browser": "~9.1.11",
"@angular/platform-browser-dynamic": "~9.1.11",
"@angular/router": "~9.1.11",
Expand All @@ -34,6 +35,7 @@
"all": "0.0.0",
"animate.css": "^4.1.1",
"bootstrap": "5.0.0-alpha2",
"chart.js": "^3.7.1",
"file-saver": "^2.0.2",
"guid-typescript": "^1.0.9",
"jwt-decode": "^2.2.0",
Expand Down Expand Up @@ -62,7 +64,7 @@
"eslint": "^7.3.1",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma": "~5.0.9",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/admin/admin-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UsersComponent } from './users/users.component';
import { ApiKeyComponent } from './api-key/api-key.component';
import { ApiKeyListComponent } from './api-key/api-key-list/api-key-list.component';
import { ApiKeyEditComponent } from './api-key/api-key-edit/api-key-edit.component';
import { AcceptUserComponent } from './users/accept-user/accept-user.component';


const adminRoutes: Routes = [
Expand All @@ -32,6 +33,7 @@ const adminRoutes: Routes = [
{ path: 'new-user', component: UserEditComponent },
{ path: ':user-id', component: UserDetailComponent },
{ path: ':user-id/edit-user', component: UserEditComponent },
{ path: 'accept-user/:user-id/:org-id', component: AcceptUserComponent }
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { ApiKeyComponent } from './api-key/api-key.component';
import { ApiKeyListComponent } from './api-key/api-key-list/api-key-list.component';
import { ApiKeyTableComponent } from './api-key/api-key-list/api-key-table/api-key-table.component';
import { ApiKeyEditComponent } from './api-key/api-key-edit/api-key-edit.component';
import { AwaitingUsersTableComponent } from './users/user-list/awaiting-users-table/awaiting-users-table.component';
import { AcceptUserComponent } from './users/accept-user/accept-user.component';

@NgModule({
declarations: [
Expand All @@ -54,6 +56,8 @@ import { ApiKeyEditComponent } from './api-key/api-key-edit/api-key-edit.compone
ApiKeyListComponent,
ApiKeyTableComponent,
ApiKeyEditComponent,
AwaitingUsersTableComponent,
AcceptUserComponent,
],
imports: [
AdminRoutingModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" [pageSize]="pageSize" [length]="resultsLength" showFirstLastButtons>
<mat-paginator [pageSizeOptions]="[25, 50, 100]" [pageSize]="pageSize" [length]="resultsLength" showFirstLastButtons>
</mat-paginator>
</div>
32 changes: 20 additions & 12 deletions src/app/admin/organisation/organisation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import {
} from './organisation.model';
import { map, shareReplay } from 'rxjs/operators';
import { UserMinimalService } from '../users/user-minimal.service';
import { UpdateUserOrgsDto } from '../users/user.model';

@Injectable({
providedIn: 'root',
})
export class OrganisationService {
URL = 'organization';
URLMINIMAL = 'organization/minimal';
URLMINIMAL_NEWKOMBIT = 'kombitCreation/minimal';

constructor(
private restService: RestService,
private userMinimalService: UserMinimalService) { }
private userMinimalService: UserMinimalService
) {}

post(body: Organisation): Observable<OrganisationResponse> {
return this.restService.post(this.URL, body);
Expand All @@ -32,27 +35,32 @@ export class OrganisationService {
}

getOne(id: number): Observable<OrganisationResponse> {
return this.restService.get(this.URL, {}, id)
.pipe(
map(
(response: OrganisationResponse) => {
response.createdByName = this.userMinimalService.getUserNameFrom(response.createdBy);
response.updatedByName = this.userMinimalService.getUserNameFrom(response.updatedBy);
return response;
}
)
);
return this.restService.get(this.URL, {}, id).pipe(
map((response: OrganisationResponse) => {
response.createdByName = this.userMinimalService.getUserNameFrom(
response.createdBy
);
response.updatedByName = this.userMinimalService.getUserNameFrom(
response.updatedBy
);
return response;
})
);
}

getMinimal(): Observable<OrganisationGetMinimalResponse> {
return this.restService.get(this.URLMINIMAL, {}).pipe(shareReplay(1));
}

getMinimalNoPerm(): Observable<OrganisationGetMinimalResponse> {
return this.restService.get(this.URLMINIMAL_NEWKOMBIT, {}).pipe(shareReplay(1));
}

getMultiple(
limit: number = 1000,
offset: number = 0,
orderByColumn?: string,
orderByDirection?: string,
orderByDirection?: string
): Observable<OrganisationGetManyResponse> {
return this.restService.get(this.URL, {
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class=" jumbotron">
<h3>{{'PERMISSION.DETAIL.HEADLINE' | translate}}</h3>
<app-general-details [data]="permission"></app-general-details>
<p><strong>{{'PERMISSION.DETAIL.TYPE' | translate}}</strong>{{permission.type}}</p>
<p><strong>{{'PERMISSION.DETAIL.TYPE' | translate}}</strong>{{permission.type | translatePermissions}}</p>
<p><strong>{{'PERMISSION.DETAIL.ORG' | translate}}</strong>
{{permission.organization?.name}}
</p>
Expand All @@ -26,18 +26,15 @@ <h3>
</div>
</div>
</div>
<div class="row">
<div class="row" *ngIf="showApplicationTable">
<div class="col-12">
<div class="jumbotron">
<h3>
{{ 'PERMISSION.DETAIL.APPLICATIONS' | translate }}
</h3>

<app-applications-table *ngIf="permission.type == 'Read'" [permissionId]="id">
</app-applications-table>
<app-applications-table *ngIf="permission.type == 'OrganizationApplicationAdmin'" [organizationId]="permission.organization?.id">
</app-applications-table>
<app-applications-table *ngIf="permission.type == 'GlobalAdmin'"></app-applications-table>
<app-applications-table *ngIf="!isApplicationAdmin()" [permissionId]="id" [organizationId]="permission.organization?.id"></app-applications-table>
<app-applications-table *ngIf="isApplicationAdmin()"></app-applications-table>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { PermissionService } from '@app/admin/permission/permission.service';
import { Subscription } from 'rxjs';
import { PermissionResponse } from '../permission.model';
import { PermissionResponse, PermissionType } from '../permission.model';
import { BackButton } from '@shared/models/back-button.model';
import { QuickActionButton } from '@shared/models/quick-action-button.model';
import { UserResponse } from '@app/admin/users/user.model';
Expand Down Expand Up @@ -46,6 +46,7 @@ export class PermissionDetailComponent implements OnInit, OnChanges {
users: UserResponse[];
dropdownButton: DropdownButton;
canEdit: boolean;
showApplicationTable = false;

constructor(
public translate: TranslateService,
Expand Down Expand Up @@ -87,6 +88,12 @@ export class PermissionDetailComponent implements OnInit, OnChanges {
.subscribe((response) => {
this.permission = response;
this.users = response.users;
this.showApplicationTable = this.meService.hasPermissions(
response,
PermissionType.Read,
PermissionType.OrganizationApplicationAdmin,
PermissionType.GlobalAdmin
);
this.isLoadingResults = false;
});
}
Expand All @@ -107,4 +114,13 @@ export class PermissionDetailComponent implements OnInit, OnChanges {
this.router.navigate(['edit-permission'], { relativeTo: this.route });
}

isApplicationAdmin () {
if (this.permission) {
if (this.permission.type.some(perm => perm.type === PermissionType.OrganizationApplicationAdmin)) {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@

<div class="form-group mt-3 col-12">
<label class="form-label" for="level">{{'PERMISSION.EDIT.TYPE' | translate}}</label>*
<select id="level" class="form-select" name="level" [(ngModel)]="permission.level" required
[value]="permission.organizationId" [disabled]="isEditMode"
[ngClass]="{'is-invalid' : formFailedSubmit && errorFields.includes('organizationId'), 'is-valid' : formFailedSubmit && !errorFields.includes('organizationId')}"
placeholder="'PERMISSION.EDIT.TYPE-PLACEHOLDER' | translate">
<option *ngFor="let level of allowedLevels()" [value]="level" [selected]="level === permission.level">
{{level}}</option>
</select>
<mat-select id="level" class="form-control" name="level"
required
[formControl]="permissionLevelsCtrl"
[(value)]="permission.levels"
[ngClass]="{'is-invalid' : formFailedSubmit && errorFields.includes('level'), 'is-valid' : formFailedSubmit && !errorFields.includes('level')}"
[placeholder]="'PERMISSION.EDIT.TYPE-PLACEHOLDER' | translate"
[compareWith]="compareLevels"
[multiple]="true">
<mat-option *ngFor="let level of allowedLevels" [value]="level">
{{'PERMISSION-TYPE.' + level.type | translate}}
</mat-option>
</mat-select>
</div>

<div class="form-group mt-3 col-12">
Expand All @@ -43,7 +48,7 @@
</mat-form-field>
</div>

<div *ngIf="permission.level != 'GlobalAdmin'">
<div *ngIf="isNotGlobalAdmin">
<div class="form-group mt-3 col-12">
<label class="form-label" for="name">{{'PERMISSION.EDIT.ORG' | translate}}</label>*
<select id="organizationId" class="form-select" name="organizationId"
Expand Down Expand Up @@ -89,4 +94,4 @@
<button (click)="routeBack()" class="btn btn-secondary" type="button">{{ 'GEN.CANCEL' | translate}}</button>
<button class="btn btn-primary ml-2" type="submit">{{ 'PERMISSION.SAVE' | translate}}</button>
</div>
</form>
</form>
Loading

0 comments on commit ba6273b

Please sign in to comment.