Skip to content

Commit

Permalink
Merge pull request #529 from xkureck/sponsorsFixAgain
Browse files Browse the repository at this point in the history
sponsored mebers & dashboard improvements
  • Loading branch information
xkureck authored Oct 29, 2020
2 parents 3841ccd + eb7e336 commit 733ee6b
Show file tree
Hide file tree
Showing 34 changed files with 1,174 additions and 1,011 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ <h1 mat-dialog-title>{{'DIALOGS.NOTIFICATIONS_ADD_EDIT_MAIL.TITLE_EDIT' | transl
matTooltip="{{'DIALOGS.NOTIFICATIONS_ADD_EDIT_MAIL.EDIT_HINT' | translate}}"
[matTooltipPosition]="'above'"
[matTooltipDisabled]="editAuth">
<button
mat-flat-button
*ngIf="!data.createMailNotification"
class="ml-2"
color="accent"
[disabled]="loading || !editAuth"
(click)="save()">
{{'DIALOGS.NOTIFICATIONS_ADD_EDIT_MAIL.SAVE_BUTTON' | translate}}
</button>
<button
mat-flat-button
*ngIf="!data.createMailNotification"
class="ml-2"
color="accent"
[disabled]="loading || !editAuth"
(click)="save()">
{{'DIALOGS.NOTIFICATIONS_ADD_EDIT_MAIL.SAVE_BUTTON' | translate}}
</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<div class="{{theme}}">
<h1 mat-dialog-title>{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1>
<h1 mat-dialog-title *ngIf="!this.successfullyCreated">{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1>

<div mat-dialog-content class="dialog-container">
<mat-spinner class="ml-auto mr-auto" *ngIf="loading"></mat-spinner>

<div mat-dialog-content class="dialog-container" *ngIf="!loading && !successfullyCreated">

<app-alert color="error" *ngIf="this.functionalityNotSupported">
{{'DIALOGS.CREATE_SPONSORED_MEMBER.FUNCTIONALITY_NOT_SUPPORTED' | translate}}
</app-alert>

<mat-form-field>
<label>
Expand Down Expand Up @@ -34,13 +40,33 @@ <h1 mat-dialog-title>{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1
</mat-form-field>

<mat-form-field>
<mat-select placeholder="{{'DIALOGS.CREATE_SPONSORED_MEMBER.NAMESPACE' | translate}}"
required
[formControl]="namespace">
<mat-option (onSelectionChange)="changeNamespace(namespc)" *ngFor="let namespc of namespaceOptions" [value]="namespc">
{{namespc}}
</mat-option>
</mat-select>
<mat-error *ngIf="namespace.invalid">
{{'DIALOGS.CREATE_SPONSORED_MEMBER.NAMESPACE_ERROR' | translate}}
</mat-error>
</mat-form-field>


<mat-form-field
matTooltip="{{'DIALOGS.CREATE_SPONSORED_MEMBER.LOGIN_DISABLED' | translate}}"
matTooltipPosition="left"
[matTooltipDisabled]="!login.disabled">
<label>
<input matInput [formControl]="login" required
<input matInput
[formControl]="login"
required
placeholder="{{'DIALOGS.CREATE_SPONSORED_MEMBER.LOGIN' | translate}}">
</label>
<mat-error *ngIf="login.invalid">{{'DIALOGS.CREATE_SPONSORED_MEMBER.LENGTH_ERROR' | translate}}</mat-error>
</mat-form-field>


<mat-form-field>
<label>
<input matInput [formControl]="password" required
Expand All @@ -55,17 +81,6 @@ <h1 mat-dialog-title>{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1
<!-- </label>-->
<!-- </mat-form-field>-->

<mat-form-field>
<mat-select placeholder="{{'DIALOGS.CREATE_SPONSORED_MEMBER.NAMESPACE' | translate}}" required [formControl]="namespace">
<mat-option (onSelectionChange)="namespace.setValue(namespc)" *ngFor="let namespc of namespaceOptions" [value]="namespc">
{{namespc}}
</mat-option>
</mat-select>
<mat-error *ngIf="namespace.invalid">
{{'DIALOGS.CREATE_SPONSORED_MEMBER.NAMESPACE_ERROR' | translate}}
</mat-error>
</mat-form-field>

<mat-form-field>
<label>
<input matInput required [formControl]="email"
Expand All @@ -76,7 +91,21 @@ <h1 mat-dialog-title>{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1

</div>

<div mat-dialog-actions>
<div mat-dialog-content class="dialog-container" *ngIf="!loading && successfullyCreated">

<div class="bigger-font mb-2">
<mat-icon class="mr-2 mb-2">done</mat-icon>
{{'DIALOGS.CREATE_SPONSORED_MEMBER.USER' | translate}}
{{this.createdMember.user | userFullName}}
{{'DIALOGS.CREATE_SPONSORED_MEMBER.WAS_CREATED' | translate}}
</div>
<div>{{'DIALOGS.CREATE_SPONSORED_MEMBER.LOGIN' | translate}}: {{this.loginThatWasSet}}</div>
<div>{{'DIALOGS.CREATE_SPONSORED_MEMBER.PASSWORD' | translate}}: {{this.password.value}} </div>
<app-alert color="warn">{{'DIALOGS.CREATE_SPONSORED_MEMBER.COPY_INFORMATION' | translate}}</app-alert>

</div>

<div mat-dialog-actions *ngIf="!successfullyCreated">
<button
(click)="onCancel()"
class="ml-auto"
Expand All @@ -92,4 +121,14 @@ <h1 mat-dialog-title>{{'DIALOGS.CREATE_SPONSORED_MEMBER.TITLE' | translate}}</h1
{{'DIALOGS.CREATE_SPONSORED_MEMBER.CREATE' | translate}}
</button>
</div>

<div mat-dialog-actions *ngIf="successfullyCreated">
<button
(click)="onCancel()"
class="ml-auto"
mat-flat-button>
{{'DIALOGS.CREATE_SPONSORED_MEMBER.OK' | translate}}
</button>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.bigger-font {
font-size: 1.5rem;
}

mat-icon {
color: #28a745;
font-size: 36px;
vertical-align: bottom;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import {
MembersManagerService,
UsersManagerService
MembersManagerService, RichMember
} from '@perun-web-apps/perun/openapi';
import { NotificatorService, StoreService } from '@perun-web-apps/perun/services';
import { TranslateService } from '@ngx-translate/core';
import { StoreService } from '@perun-web-apps/perun/services';
import { FormControl, Validators } from '@angular/forms';

export interface CreateSponsoredMemberDialogData {
Expand All @@ -23,6 +21,10 @@ export class CreateSponsoredMemberDialogComponent implements OnInit {

theme: string;
loading = false;
functionalityNotSupported = false;
loginThatWasSet = '';
successfullyCreated = false;
createdMember: RichMember;

namespaceOptions: string[] = [];

Expand All @@ -38,7 +40,7 @@ export class CreateSponsoredMemberDialogComponent implements OnInit {

password = new FormControl('', [Validators.required]);

namespace = new FormControl('', [Validators.required,]);
namespace = new FormControl('', [Validators.required]);

login = new FormControl('', [Validators.required]);

Expand All @@ -47,22 +49,26 @@ export class CreateSponsoredMemberDialogComponent implements OnInit {
constructor(private dialogRef: MatDialogRef<CreateSponsoredMemberDialogComponent>,
@Inject(MAT_DIALOG_DATA) private data: CreateSponsoredMemberDialogData,
private membersService: MembersManagerService,
private store: StoreService,
private notificator: NotificatorService,
private translate: TranslateService,
private usersService: UsersManagerService) {
private store: StoreService) {
}

ngOnInit(): void {
this.loading = true;
this.theme = this.data.theme;
this.parseNamespace();
if (this.namespaceOptions.length === 0) {
this.functionalityNotSupported = true;
}
this.loading = false;
}

parseNamespace(){
const namespaces = this.store.getLoginAttributeNames();
for(const namespace of namespaces){
//TODO get login_namespace_attributes when creating for other namespaces will be available, then delete
//TODO sponsor_namespace_attributes from configuration
const namespaces = this.store.get("sponsor_namespace_attributes");
for (const namespace of namespaces) {
const index = namespace.lastIndexOf(':');
if(index !== -1){
if (index !== -1) {
this.namespaceOptions.push(namespace.substring(index + 1, namespace.length));
}
}
Expand All @@ -78,17 +84,41 @@ export class CreateSponsoredMemberDialogComponent implements OnInit {
titleBefore: this.titleBefore,
namespace: this.namespace.value,
password: this.password.value,
sponsor: this.store.getPerunPrincipal().userId
}).subscribe(rm => {
this.usersService.reservePassword(this.login.value, this.namespace.value, this.password.value).subscribe(_ => {
this.notificator.showSuccess(this.translate.instant('DIALOGS.CREATE_SPONSORED_USER.SUCCESS'));
this.dialogRef.close(true);
}, () => this.loading = false);
}, () => this.loading = false);
sponsor: this.store.getPerunPrincipal().userId,
email: this.email.value
}).subscribe(richMember => {
this.successfullyCreated = true;
this.dialogRef.updateSize('600px');
this.createdMember = richMember;
if(!!richMember && !!richMember.userAttributes){
richMember.userAttributes
.filter(attr => attr.baseFriendlyName === 'login-namespace')
.filter(attr => attr.friendlyNameParameter === 'mu')
.filter(attr => attr.value !== null)
.forEach(attr => {
this.loginThatWasSet = attr.value.toString();
});
}
this.loading = false;
}, () => {
this.loading = false
});
}

onCancel() {
this.dialogRef.close();
if (this.successfullyCreated) {
this.dialogRef.close(true);
} else {
this.dialogRef.close();
}

}

changeNamespace(namespc: string) {
if (namespc === 'mu') {
this.login.disable();
} else {
this.login.enable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ <h1 mat-dialog-title>{{'DIALOGS.APPLICATION_FORM_EDIT_ITEM.TITLE' | translate}}


</div>
<div class="flex-grow-1"></div>
<div class="d-flex mt-auto" mat-dialog-actions>
<button
mat-flat-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ <h1 mat-dialog-title>{{'DIALOGS.EDIT_MEMBER_SPONSORS.TITLE' | translate}}</h1>
<ng-container matColumnDef="remove">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let sponsor">
<button
mat-icon-button
(click)="markSponsor(sponsor)">
<mat-icon *ngIf="!sponsorsToRemove.has(sponsor.user.id)" color="warn">clear</mat-icon>
<mat-icon *ngIf="sponsorsToRemove.has(sponsor.user.id)">settings_backup_restore</mat-icon>
</button>
<div
matTooltip="{{'DIALOGS.EDIT_MEMBER_SPONSORS.REMOVE_SPONSOR_DISABLED' | translate}}"
[matTooltipPosition]="'above'"
[matTooltipDisabled]="isAuthorized(sponsor)">
<button
mat-icon-button
class="btn-delete"
[disabled]="!isAuthorized(sponsor)"
(click)="markSponsor(sponsor)">
<mat-icon *ngIf="!sponsorsToRemove.has(sponsor.user.id)" class="icn-delete" color="warn">clear</mat-icon>
<mat-icon *ngIf="sponsorsToRemove.has(sponsor.user.id)">settings_backup_restore</mat-icon>
</button>
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns" class="font-weight-bolder"></tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.make-red {
background-color: #FFCDD2;
}

.btn-delete:disabled{
.icn-delete{
color: grey;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MembersManagerService, Sponsor, User } from '@perun-web-apps/perun/openapi';
import { Member, MembersManagerService, Sponsor } from '@perun-web-apps/perun/openapi';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { NotificatorService } from '@perun-web-apps/perun/services';
import { GuiAuthResolver, NotificatorService } from '@perun-web-apps/perun/services';
import { TranslateService } from '@ngx-translate/core';
import { MatTableDataSource } from '@angular/material/table';

export interface EditMemberSponsorsDialogComponent {
theme: string;
sponsors: Sponsor[];
member: number;
member: Member;
}

@Component({
Expand All @@ -22,6 +22,7 @@ export class EditMemberSponsorsDialogComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) private data: EditMemberSponsorsDialogComponent,
public memberService: MembersManagerService,
private notificator: NotificatorService,
private authResolver: GuiAuthResolver,
private translate: TranslateService) { }

theme: string;
Expand Down Expand Up @@ -54,7 +55,7 @@ export class EditMemberSponsorsDialogComponent implements OnInit {
}

const sponsorId = sponsorIds.pop();
this.memberService.removeSponsor(this.data.member, sponsorId).subscribe(() => {
this.memberService.removeSponsor(this.data.member.id, sponsorId).subscribe(() => {
this.removeSponsors(sponsorIds);
}, () => this.loading = false);
}
Expand All @@ -69,4 +70,8 @@ export class EditMemberSponsorsDialogComponent implements OnInit {
this.dialogRef.close(false);
}

isAuthorized(sponsor: Sponsor) {
return this.authResolver.isAuthorized('sponsored-removeSponsor_Member_User_policy', [this.data.member])
&& this.authResolver.isAuthorized('sponsor-removeSponsor_Member_User_policy', [sponsor.user]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<h1 mat-dialog-title>{{'DIALOGS.GENERATE_SPONSORED_MEMBERS.TITLE' | translate}}</h1>
<mat-spinner class="ml-auto mr-auto" *ngIf="loading"></mat-spinner>
<div *ngIf="!loading" mat-dialog-content class="dialog-container">
<app-alert color="error" *ngIf="this.functionalityNotSupported">
{{'DIALOGS.CREATE_SPONSORED_MEMBER.FUNCTIONALITY_NOT_SUPPORTED' | translate}}
</app-alert>
<mat-form-field>
<mat-select placeholder="{{'DIALOGS.GENERATE_SPONSORED_MEMBERS.NAMESPACE' | translate}}" required [formControl]="namespace">
<mat-option (onSelectionChange)="namespace.setValue(namespc)" *ngFor="let namespc of namespaceOptions" [value]="namespc">
Expand Down
Loading

0 comments on commit 733ee6b

Please sign in to comment.