Skip to content

Commit

Permalink
Merge pull request #651 from xkureck/fixGroupObserver
Browse files Browse the repository at this point in the history
group observer role fixed
  • Loading branch information
xkureck authored Mar 22, 2021
2 parents 54c46f3 + 2822af3 commit 7f39580
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Component, HostBinding, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SelectionModel } from '@angular/cdk/collections';
import { GuiAuthResolver, StoreService } from '@perun-web-apps/perun/services';
import {
ApiRequestConfigurationService,
GuiAuthResolver,
NotificatorService,
StoreService
} from '@perun-web-apps/perun/services';
import { Urns } from '@perun-web-apps/perun/urns';
import { AddMemberDialogComponent } from '../../../../shared/components/dialogs/add-member-dialog/add-member-dialog.component';
import { MatDialog } from '@angular/material/dialog';
Expand Down Expand Up @@ -41,6 +46,8 @@ export class GroupMembersComponent implements OnInit {
private storeService: StoreService,
private membersManager: MembersManagerService,
private attributesManager: AttributesManagerService,
private apiRequest: ApiRequestConfigurationService,
private notificator: NotificatorService
) { }

group: RichGroup;
Expand Down Expand Up @@ -97,18 +104,7 @@ export class GroupMembersComponent implements OnInit {
this.route.parent.params.subscribe(parentParams => {
const groupId = parentParams['groupId'];
const voId = parentParams['voId'];

this.attributesManager.getVoAttributeByName(voId, "urn:perun:vo:attribute-def:def:blockManualMemberAdding").subscribe(attrValue => {
this.blockManualMemberAdding = attrValue.value !== null;
if (this.blockManualMemberAdding !== true) {
this.attributesManager.getGroupAttributeByName(groupId, "urn:perun:group:attribute-def:def:blockManualMemberAdding").subscribe(groupAttrValue => {
this.blockManualMemberAdding = groupAttrValue.value !== null;
this.loadPage(groupId);
});
} else {
this.loadPage(groupId);
}
});
this.isManualAddingBlocked(voId, groupId).then(() => this.loadPage(groupId));
});
}

Expand Down Expand Up @@ -264,4 +260,32 @@ export class GroupMembersComponent implements OnInit {
}
return '';
}

isManualAddingBlocked(voId: number, groupId: number): Promise<void> {
return new Promise((resolve, reject) => {
this.apiRequest.dontHandleErrorForNext();
this.attributesManager.getVoAttributeByName(voId, "urn:perun:vo:attribute-def:def:blockManualMemberAdding").subscribe(attrValue => {
this.blockManualMemberAdding = attrValue.value !== null;
if (this.blockManualMemberAdding !== true) {
this.apiRequest.dontHandleErrorForNext();
this.attributesManager.getGroupAttributeByName(groupId, "urn:perun:group:attribute-def:def:blockManualMemberAdding").subscribe(groupAttrValue => {
this.blockManualMemberAdding = groupAttrValue.value !== null;
resolve();
}, error => {
if (error.error.name !== 'PrivilegeException') {
this.notificator.showError(error);
}
resolve();
});
} else {
resolve();
}
}, error => {
if (error.error.name !== 'PrivilegeException') {
this.notificator.showError(error);
}
resolve();
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
MembersManagerService, RichMember, Sponsor,
UsersManagerService, Vo
} from '@perun-web-apps/perun/openapi';
import { GuiAuthResolver, StoreService } from '@perun-web-apps/perun/services';
import {
ApiRequestConfigurationService,
GuiAuthResolver,
NotificatorService,
StoreService
} from '@perun-web-apps/perun/services';
import { getDefaultDialogConfig, parseFullName, parseStatusColor, parseStatusIcon } from '@perun-web-apps/perun/utils';
import { Urns } from '@perun-web-apps/perun/urns';

Expand All @@ -34,7 +39,9 @@ export class MemberOverviewComponent implements OnInit {
private route: ActivatedRoute,
private dialog: MatDialog,
public authResolver: GuiAuthResolver,
private storeService: StoreService
private storeService: StoreService,
private apiRequest: ApiRequestConfigurationService,
private notificator: NotificatorService,
) {
}

Expand Down Expand Up @@ -193,13 +200,21 @@ export class MemberOverviewComponent implements OnInit {

private refreshData() {
this.loading = true;
this.attributesManager.getMemberAttributeByName(this.member.id, Urns.MEMBER_DEF_EXPIRATION).subscribe(attr => {
this.expirationAtt = attr;
this.expiration = !attr.value ? this.translate.instant('MEMBER_DETAIL.OVERVIEW.NEVER_EXPIRES') : attr.value;
this.membersService.getRichMemberWithAttributes(this.member.id).subscribe(member => {
this.member = member;
this.membersService.getRichMemberWithAttributes(this.member.id).subscribe(member => {
this.member = member;
this.apiRequest.dontHandleErrorForNext();
this.attributesManager.getMemberAttributeByName(this.member.id, Urns.MEMBER_DEF_EXPIRATION).subscribe(attr => {
this.expirationAtt = attr;
this.expiration = !attr.value ? this.translate.instant('MEMBER_DETAIL.OVERVIEW.NEVER_EXPIRES') : attr.value;
this.loading = false;
}, () => this.loading = false);
}, error => {
if (error.error.name !== 'PrivilegeException') {
this.notificator.showError(error);
} else {
this.membershipDataSource = new MatTableDataSource<string>(['Status']);
}
this.loading = false
});
}, () => this.loading = false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Component, HostBinding, OnInit } from '@angular/core';
import { SideMenuService } from '../../../../core/services/common/side-menu.service';
import { ActivatedRoute } from '@angular/router';
import { SelectionModel } from '@angular/cdk/collections';
import { GuiAuthResolver, NotificatorService, StoreService } from '@perun-web-apps/perun/services';
import {
ApiRequestConfigurationService,
GuiAuthResolver,
NotificatorService,
StoreService
} from '@perun-web-apps/perun/services';
import { TranslateService } from '@ngx-translate/core';
import { MatDialog } from '@angular/material/dialog';
import { RemoveMembersDialogComponent } from '../../../../shared/components/dialogs/remove-members-dialog/remove-members-dialog.component';
Expand Down Expand Up @@ -44,6 +49,7 @@ export class VoMembersComponent implements OnInit {
private authzService: GuiAuthResolver,
private storeService: StoreService,
private attributesManager: AttributesManagerService,
private apiRequest: ApiRequestConfigurationService,
) { }

vo: Vo;
Expand Down Expand Up @@ -87,9 +93,7 @@ export class VoMembersComponent implements OnInit {
this.route.parent.params.subscribe(parentParams => {
const voId = parentParams['voId'];

this.attributesManager.getVoAttributeByName(voId, "urn:perun:vo:attribute-def:def:blockManualMemberAdding").subscribe(attrValue => {
this.blockManualMemberAdding = attrValue.value !== null;

this.isManualAddingBlocked(voId).then(() => {
this.voService.getVoById(voId).subscribe(vo => {
this.vo = vo;
this.setAuthRights();
Expand Down Expand Up @@ -233,4 +237,19 @@ export class VoMembersComponent implements OnInit {
this.pageSize = event.pageSize;
this.tableConfigService.setTablePageSize(this.tableId, event.pageSize);
}

isManualAddingBlocked(voId: number): Promise<void> {
return new Promise((resolve, reject) => {
this.apiRequest.dontHandleErrorForNext();
this.attributesManager.getVoAttributeByName(voId, "urn:perun:vo:attribute-def:def:blockManualMemberAdding").subscribe(attrValue => {
this.blockManualMemberAdding = attrValue.value !== null;
resolve();
}, error => {
if (error.error.name !== 'PrivilegeException') {
this.notificator.showError(error);
}
resolve();
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<td *matCellDef="let group" class="wrap-content" mat-cell>
{{group | groupExpiration | parseDate}}
<button
*ngIf="canManageGroup(group)"
(click)="changeExpiration(group)"
(mouseenter)="disabledRouting = true"
(mouseleave)="disabledRouting = disableRouting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class GroupsListComponent implements OnInit, AfterViewInit, OnChanges {
@Output()
refreshTable = new EventEmitter<void>();

displayedColumns: string[] = ['select', 'id', 'recent', 'vo', 'name', 'description','expiration', 'menu'];
displayedColumns: string[] = ['select', 'id', 'recent', 'vo', 'name', 'description', 'expiration', 'menu'];
dataSource: MatTableDataSource<Group | RichGroup>;

exporting = false;
Expand Down Expand Up @@ -339,4 +339,8 @@ export class GroupsListComponent implements OnInit, AfterViewInit, OnChanges {
}
});
}

canManageGroup(group: Group): boolean {
return this.authResolver.isThisGroupAdmin(group.id) || this.authResolver.isThisVoAdmin(group.voId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class ChangeExpirationDialogComponent implements OnInit {
this.loading = false;
this.notificator.showSuccess(this.successMessage);
this.dialogRef.close(true);
});
}, () => this.loading = false);
} else {
this.attributesManagerService.setMemberAttribute({
member: this.data.memberId,
Expand All @@ -124,7 +124,7 @@ export class ChangeExpirationDialogComponent implements OnInit {
this.loading = false;
this.notificator.showSuccess(this.successMessage);
this.dialogRef.close(true);
});
}, () => this.loading = false);

}

Expand Down

0 comments on commit 7f39580

Please sign in to comment.