Skip to content

Commit

Permalink
Merge pull request #5634 from deNBI/fix/comment_validity_plus_sensitive
Browse files Browse the repository at this point in the history
Fix/comment validity plus sensitive
  • Loading branch information
dweinholz authored Apr 19, 2023
2 parents 3f47040 + 9f39915 commit f1ce507
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ <h5>
</td>
</tr>
<tr *ngIf="application?.project_application_person_related_data">
<td>Nonsensitive Data</td>
<td>Personal data [Article 4 (1) GDPR] (e.g. name, e-mail)</td>
<td>
<p *ngIf="application?.project_application_nonsensitive_data">Yes</p>
<p *ngIf="!application?.project_application_nonsensitive_data">No</p>
</td>
</tr>
<tr *ngIf="application?.project_application_person_related_data">
<td>Sensitive Data</td>
<td>Sensitive Personal data [Articles 4 (13,14,15), 9 GDPR and Recital 51] </td>
<td>
<p *ngIf="application?.project_application_sensitive_data">Yes</p>
<p *ngIf="!application?.project_application_sensitive_data">No</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,13 @@ <h5 class="col-md-12 form-control-label">Resources</h5>
placeholder=""
[(ngModel)]="application.project_application_comment"
[ngClass]="{
'is-invalid': form.controls.project_application_comment?.invalid,
'is-valid': form.controls.project_application_comment?.valid
'is-invalid': form.controls.project_application_comment?.invalid || !checkValidityComment(),
'is-valid': form.controls.project_application_comment?.valid && checkValidityComment()
}"
></textarea>
<div id="project_application_comment_feedback" class="invalid-feedback" *ngIf="!checkValidityComment()">
Please provide a more detailed description. At least 50 characters must be entered.
</div>
<span class="help-block">Additional information you want to share?</span>
</div>
</div>
Expand Down Expand Up @@ -1728,7 +1731,9 @@ <h6><strong>Platforms</strong></h6>
application?.project_application_edam_terms.length === 0 ||
application?.project_application_edam_terms.length > 10 ||
(application?.flavors.length === 0 && !application?.project_application_openstack_project) ||
(!application?.dissemination?.isPlatformSelected() && application?.project_application_report_allowed)
(!application?.dissemination?.isPlatformSelected() &&
application?.project_application_report_allowed) ||
!checkValidityComment()
"
class="btn btn-sm btn-success"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent
}
}

checkValidityComment(): boolean {
if (this.extraResourceCommentRequired) {
if (this.application.project_application_comment?.length < 50) {
return false;
} else {
const regExp = /[a-zA-Z]/g;

return regExp.test(this.application.project_application_comment);
}
} else {
return true;
}
}

getUserinfo(): void {
this.userService.getUserInfo().subscribe((userinfo: Userinfo) => {
this.userinfo = userinfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,14 @@ <h6 class="col-md-8 form-control-label">
[required]="extraResourceCommentRequired"
[(ngModel)]="temp_project_modification.comment"
[ngClass]="{
'is-invalid': modificationForm.controls.project_application_renewal_comment?.invalid,
'is-valid': modificationForm.controls.project_application_renewal_comment?.valid
'is-invalid':
modificationForm.controls.project_application_renewal_comment?.invalid || !checkValidityComment(),
'is-valid': modificationForm.controls.project_application_renewal_comment?.valid && checkValidityComment()
}"
></textarea>
<div id="project_application_comment_feedback" class="invalid-feedback" *ngIf="!checkValidityComment()">
Please provide a more detailed description. At least 50 characters must be entered.
</div>
<span class="help-block">Additional information you want to share?</span>
</div>
</div>
Expand Down Expand Up @@ -698,7 +702,7 @@ <h6 class="col-md-8 form-control-label">
id="submit_modification_btn"
data-test-id="submit_modification_request_button"
(click)="bsModalRef.hide(); showSubmitModal(false)"
[disabled]="modificationForm.invalid || !min_vm"
[disabled]="modificationForm.invalid || !min_vm || !checkValidityComment()"
>
<i class="far fa-dot-circle"></i>
Submit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ export class ModificationRequestComponent implements OnInit, OnDestroy {
);
}

checkValidityComment(): boolean {
if (this.extraResourceCommentRequired) {
if (this.temp_project_modification.comment.length < 50) {
return false;
} else {
const regExp = /[a-zA-Z]/g;

return regExp.test(this.temp_project_modification.comment);
}
} else {
return true;
}
}

getFlavors(): void {
this.subscription.add(
this.flavorService
Expand Down Expand Up @@ -148,7 +162,6 @@ export class ModificationRequestComponent implements OnInit, OnDestroy {
flavor.counter = amount;
this.temp_project_modification.flavors.push(flavor);
}
console.log(this.temp_project_modification.flavors);
this.min_vm = this.project.project_application_openstack_project || this.temp_project_modification.flavors.length > 0;
this.temp_project_modification.calculateRamCores();
this.getExtraCredits();
Expand Down
209 changes: 104 additions & 105 deletions src/app/shared/shared_modules/public-key/public-key.component.ts
Original file line number Diff line number Diff line change
@@ -1,128 +1,127 @@
import {
Component, EventEmitter, Input, OnInit, Output,
Component, EventEmitter, Input, OnInit, Output,
} from '@angular/core';
import {ClipboardService} from 'ngx-clipboard';
import {saveAs} from 'file-saver';
import {BsModalService} from 'ngx-bootstrap/modal';
import {KeyService} from '../../../api-connector/key.service';
import {ApiSettings} from '../../../api-connector/api-settings.service';
import {Userinfo} from '../../../userinfo/userinfo.model';
import {IResponseTemplate} from '../../../api-connector/response-template';
import {AbstractBaseClass} from '../baseClass/abstract-base-class';
import {WIKI_GENERATE_KEYS} from '../../../../links/links';
import {NotificationModalComponent} from '../../modal/notification-modal';
import {BlacklistedResponse} from '../../../api-connector/response-interfaces';
import {CLOUD_PORTAL_SUPPORT_MAIL} from '../../../../links/links'
import { ClipboardService } from 'ngx-clipboard';
import { saveAs } from 'file-saver';
import { BsModalService } from 'ngx-bootstrap/modal';
import { KeyService } from '../../../api-connector/key.service';
import { ApiSettings } from '../../../api-connector/api-settings.service';
import { Userinfo } from '../../../userinfo/userinfo.model';
import { IResponseTemplate } from '../../../api-connector/response-template';
import { AbstractBaseClass } from '../baseClass/abstract-base-class';
import { WIKI_GENERATE_KEYS, CLOUD_PORTAL_SUPPORT_MAIL } from '../../../../links/links';
import { NotificationModalComponent } from '../../modal/notification-modal';
import { BlacklistedResponse } from '../../../api-connector/response-interfaces';

/**
* Public Key component.
*/
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[app-public-key]',
templateUrl: './public-key.component.html',
styleUrls: ['./public-key.component.scss'],
providers: [ApiSettings, KeyService],
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[app-public-key]',
templateUrl: './public-key.component.html',
styleUrls: ['./public-key.component.scss'],
providers: [ApiSettings, KeyService],
})
export class PublicKeyComponent extends AbstractBaseClass implements OnInit {
WIKI_GENERATE_KEYS: string = WIKI_GENERATE_KEYS;
public_key: string;
validated_key: boolean = false;
blocked_key: boolean = false;
current_key_blocked: boolean = false;
acknowledgement_given: boolean = false;
@Input() userinfo: Userinfo;
@Output() readonly currentKeyBlockedChanged: EventEmitter<boolean> = new EventEmitter();
CLOUD_PORTAL_SUPPORT_MAIL: string= CLOUD_PORTAL_SUPPORT_MAIL
WIKI_GENERATE_KEYS: string = WIKI_GENERATE_KEYS;
public_key: string;
validated_key: boolean = false;
blocked_key: boolean = false;
current_key_blocked: boolean = false;
acknowledgement_given: boolean = false;
@Input() userinfo: Userinfo;
@Output() readonly currentKeyBlockedChanged: EventEmitter<boolean> = new EventEmitter();
CLOUD_PORTAL_SUPPORT_MAIL: string = CLOUD_PORTAL_SUPPORT_MAIL;

constructor(
private keyService: KeyService,
private clipboardService: ClipboardService,
private modalService: BsModalService,
) {
super();
}
constructor(
private keyService: KeyService,
private clipboardService: ClipboardService,
private modalService: BsModalService,
) {
super();
}

ngOnInit() {
if (this.userinfo?.PublicKey) {
this.isCurrentKeyBlocked();
}
ngOnInit() {
if (this.userinfo?.PublicKey) {
this.isCurrentKeyBlocked();
}
}

downloadPem(data: string): void {
const blob: Blob = new Blob([data], {type: 'pem'});
const url: string = window.URL.createObjectURL(blob);
saveAs(url, `${this.userinfo.UserLogin}_ecdsa`);
}
downloadPem(data: string): void {
const blob: Blob = new Blob([data], { type: 'pem' });
const url: string = window.URL.createObjectURL(blob);
saveAs(url, `${this.userinfo.UserLogin}_ecdsa`);
}

generateKey(): void {
this.keyService.generateKey().subscribe((res: any): void => {
this.getUserPublicKey();
this.downloadPem(res['private_key']);
});
}
generateKey(): void {
this.keyService.generateKey().subscribe((res: any): void => {
this.getUserPublicKey();
this.downloadPem(res['private_key']);
});
}

isKeyBlocked(): void {
this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => {
this.blocked_key = res.blacklisted;
});
}
isKeyBlocked(): void {
this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => {
this.blocked_key = res.blacklisted;
});
}

isCurrentKeyBlocked(): void {
this.keyService.isBlocked(this.userinfo.PublicKey).subscribe((res: BlacklistedResponse) => {
this.current_key_blocked = res.blacklisted;
this.currentKeyBlockedChanged.emit(this.current_key_blocked);
});
}
isCurrentKeyBlocked(): void {
this.keyService.isBlocked(this.userinfo.PublicKey).subscribe((res: BlacklistedResponse) => {
this.current_key_blocked = res.blacklisted;
this.currentKeyBlockedChanged.emit(this.current_key_blocked);
});
}

validateKey(): void {
this.keyService.validateKey(this.public_key.trim()).subscribe(
(res: any) => {
this.validated_key = res['status'] === 'valid';
},
() => {
this.validated_key = false;
},
);
}
validateKey(): void {
this.keyService.validateKey(this.public_key.trim()).subscribe(
(res: any) => {
this.validated_key = res['status'] === 'valid';
},
() => {
this.validated_key = false;
},
);
}

importKey(): void {
const re: RegExp = /\+/gi;
importKey(): void {
const re: RegExp = /\+/gi;

this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({
next: (): void => {
this.getUserPublicKey();
const initialState = {
notificationModalTitle: 'Success',
notificationModalType: 'info',
notificationModalMessage: 'The new public key got successfully set',
};
this.modalService.show(NotificationModalComponent, {initialState});
},
error: (): any => {
const initialState = {
notificationModalTitle: 'Error',
notificationModalType: 'danger',
notificationModalMessage:
'We were not able successfully set a new public key. Please enter a valid public key!',
};
this.modalService.show(NotificationModalComponent, {initialState});
},
});
}
this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({
next: (): void => {
this.getUserPublicKey();
const initialState = {
notificationModalTitle: 'Success',
notificationModalType: 'info',
notificationModalMessage: 'The new public key got successfully set',
};
this.modalService.show(NotificationModalComponent, { initialState });
},
error: (): any => {
const initialState = {
notificationModalTitle: 'Error',
notificationModalType: 'danger',
notificationModalMessage:
'We were not able successfully set a new public key. Please enter a valid public key!',
};
this.modalService.show(NotificationModalComponent, { initialState });
},
});
}

copyToClipboard(text: string): void {
if (this.clipboardService.isSupported) {
this.clipboardService.copy(text);
} else {
super.copyToClipboard(text);
}
copyToClipboard(text: string): void {
if (this.clipboardService.isSupported) {
this.clipboardService.copy(text);
} else {
super.copyToClipboard(text);
}
}

getUserPublicKey(): void {
this.keyService.getKey().subscribe((key: IResponseTemplate): void => {
this.userinfo.PublicKey = key.value as string;
this.isKeyBlocked();
});
}
getUserPublicKey(): void {
this.keyService.getKey().subscribe((key: IResponseTemplate): void => {
this.userinfo.PublicKey = key.value as string;
this.isKeyBlocked();
});
}
}

0 comments on commit f1ce507

Please sign in to comment.