Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/api secruity config #145

Merged
merged 3 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {InitConfigService} from './services/init-config.service';
import {InitAuthConfigService} from './services/init-oauth-config.service';
import {SseService} from './services/sse.service';
import {IdentitiesService} from './services/identities.service';
import {ApiTokensService} from "./services/api-tokens.service";

@NgModule({
imports: [
Expand Down Expand Up @@ -67,7 +68,8 @@ import {IdentitiesService} from './services/identities.service';
InitConfigService,
InitAuthConfigService,
SseService,
IdentitiesService
IdentitiesService,
ApiTokensService
],
declarations: []
})
Expand Down
7 changes: 7 additions & 0 deletions src/app/core/models/api-token.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Audit} from './audit.model';

export interface ApiToken extends Audit {
id: number;
name: string;
token: string;
}
1 change: 1 addition & 0 deletions src/app/core/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './global-setting.model';
export * from './creation-accreditation-request.model';
export * from './accreditation-request.model';
export * from './response-accreditation-request.model';
export * from './api-token.model';
29 changes: 29 additions & 0 deletions src/app/core/services/api-tokens.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';

import {ApiService} from './api.service';
import {ApiToken} from '../models';
import {Page} from '../models/page.model';
import {Pageable} from '../models/pageable.model';

@Injectable()
export class ApiTokensService {
private apiName = '/api-tokens';
constructor(
private apiService: ApiService
) {
}

getAll(pageable: Pageable = new Pageable(0, 20)): Observable<Page<ApiToken>> {
return this.apiService.get(`${this.apiName}`, pageable);
}

addApiToken(apiToken: ApiToken): Observable<ApiToken> {
return this.apiService.put(`${this.apiName}`, apiToken);
}


deleteApiToken(apiTokenId: number): Observable<any> {
return this.apiService.delete(`${this.apiName}/${apiTokenId}`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{'PROFILE.SECURITY.DELETE_API_TOKEN_TITLE' | translate: {name: token.name} }}</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('cross-click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{{'PROFILE.SECURITY.DELETE_API_TOKEN_MSG' | translate : {name: token.name} }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="activeModal.dismiss('cancel')">{{'CANCEL' | translate}}</button>
<button type="button" class="btn btn-outline-dark" (click)="deleteToken()">{{'PROFILE.SECURITY.DELETE_API_TOKEN' | translate}}</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Component, OnInit} from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {ApiToken} from '../../core';
import {ApiTokensService} from '../../core/services/api-tokens.service';

@Component({
selector: 'app-token-naming-deletion',
templateUrl: './modal-token-deletion.component.html'
})
export class ModalTokenDeletionComponent {
token: ApiToken;

constructor(public activeModal: NgbActiveModal, private apiTokensService: ApiTokensService) {
}

deleteToken() {
this.apiTokensService.deleteApiToken(this.token.id).subscribe(
fileKind => {
this.activeModal.close(fileKind);
},
error => {
this.activeModal.dismiss(error);
}
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="modal-body">
{{'PROFILE.SECURITY.TOKEN_RESULT' | translate : {token: token.token} }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark"
(click)="activeModal.dismiss('cancel')">{{ 'CLOSE' | translate }}</button>
</div>
14 changes: 14 additions & 0 deletions src/app/profile/modal-token-result/modal-token-result.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {ApiToken} from '../../core';

@Component({
selector: 'app-modal-token-result',
templateUrl: './modal-token-result.component.html'
})
export class ModalTokenResultComponent {
token: ApiToken;

constructor(public activeModal: NgbActiveModal) {
}
}
26 changes: 26 additions & 0 deletions src/app/profile/modal-token/modal-token.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<form (ngSubmit)="tokenForm.form.valid && addToken()" #tokenForm="ngForm">
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{ 'PROFILE.SECURITY.NEW_API_TOKEN' | translate }}</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('cross-click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name">{{ 'PROFILE.SECURITY.NAME' | translate }}</label>
<div class="input-group">
<input required id="name" class="form-control" placeholder="{{ 'PROFILE.SECURITY.NAME' | translate }}" #name="ngModel"
name="name"
[(ngModel)]="token.name"
[ngClass]="{ 'is-invalid': tokenForm.submitted && name.invalid }">
<div *ngIf="tokenForm.submitted && name.invalid" class="invalid-feedback">
<div *ngIf="name.errors.required">{{ 'PROFILE.SECURITY.NAME' | translate }} requis</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="activeModal.dismiss('cancel')">{{ 'CANCEL' | translate }}</button>
<button type="submit" class="btn btn-outline-dark">{{ 'PROFILE.SECURITY.NEW_API_TOKEN_ACTION' | translate }}</button>
</div>
</form>
37 changes: 37 additions & 0 deletions src/app/profile/modal-token/modal-token.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {Component, OnInit} from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {ApiToken, Application} from '../../core';
import {FileKind} from '../../core/models/file-kind.model';
import {FileKindsService} from '../../core/services/file-kinds.service';
import {ApiTokensService} from "../../core/services/api-tokens.service";

@Component({
selector: 'app-modal-token',
templateUrl: './modal-token.component.html'
})
export class ModalTokenComponent {
token: ApiToken = {
id: undefined,
name: undefined,
createdDate: undefined,
token: undefined,
lastModifiedBy: undefined,
lastModifiedDate: undefined,
createdBy: undefined
};

constructor(public activeModal: NgbActiveModal, private apiTokensService: ApiTokensService) {
}

addToken() {
this.apiTokensService.addApiToken(this.token).subscribe(
fileKind => {
this.activeModal.close(fileKind);
},
error => {
this.activeModal.dismiss(error);
}
);

}
}
Loading