Skip to content

Commit

Permalink
Remove and rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Elblinator committed Nov 21, 2024
1 parent 50584ed commit 7b6721d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CommitteeRepositoryService extends BaseRepository<ViewCommittee, Co
const viewModel = super.createViewModel(model);
viewModel.getViewUser = (id: Id): ViewUser => this.userRepo.getViewModel(id);
viewModel.canAccess = (): boolean =>
this.operator.hasCommitteePermissions(model.id, CML.can_manage) ||
this.operator.hasCommitteePermissionsOrOrgaPermissions(model.id, CML.can_manage) ||
this.operator.hasOrganizationPermissions(OML.can_manage_users) ||
this.operator.isInCommitteesNonAdminCheck(model);
return viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@if (meeting.isArchived) {
<mat-label class="archived-label">{{ 'Archived' | translate }}</mat-label>
}
<ng-container *osCmlPerms="CML.can_manage; committeeId: committee.id; nonAdminCheck: true">
<ng-container *osCmlPerms="CML.can_manage; committeeId: committee.id">
@if (isTemplateMeeting) {
<div class="template-indicator">
<mat-icon [matTooltip]="'Public template' | translate">star</mat-icon>
Expand Down Expand Up @@ -131,7 +131,10 @@

<mat-menu #meetingMenu="matMenu">
<ng-template matMenuContent>
@if (!meeting.isArchived && (meeting?.canBeEnteredBy(operator.user) || operator.isSuperAdmin)) {
@if (
!meeting.isArchived &&
(meeting?.canBeEnteredBy(operator.user) || operator.isSuperAdmin || operator.isOrgaManager)
) {
<a mat-menu-item [routerLink]="['meeting', 'edit', meeting.id]">
<mat-icon>edit</mat-icon>
<span>{{ 'Edit' | translate }}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<os-head-bar
[customMenu]="true"
[hasMainButton]="canManageMeetingsInCommittee"
[hasMainButton]="canManageCommitteeOrMeetingsInCommittee"
[mainActionTooltip]="'New meeting' | translate"
[nav]="false"
(mainEvent)="onCreateMeeting()"
Expand Down Expand Up @@ -105,7 +105,7 @@ <h1>
</os-committee-meta-info>
}
<!-- Member amount -->
@if (canManageCommittee) {
@if (canManageCommitteeOrMeetingsInCommittee) {
<os-committee-meta-info icon="engineering" title="{{ 'Committee admin' | translate }}">
@if (committee.getManagers(); as managers) {
<os-comma-separated-listing [list]="managers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ export class CommitteeDetailViewComponent extends BaseUiComponent {
public forwardingExpanded = false;
public requireDuplicateFrom = false;

public get canManageMeetingsInCommittee(): boolean {
return this.operator.hasCommitteePermissionsNonAdminCheck(this.committeeId, CML.can_manage);
}

public get canManageCommittee(): boolean {
return this.operator.hasCommitteePermissions(this.committeeId, CML.can_manage);
public get canManageCommitteeOrMeetingsInCommittee(): boolean {
return this.operator.hasCommitteePermissionsOrOrgaPermissions(this.committeeId, CML.can_manage);
}

public constructor(
Expand Down Expand Up @@ -90,7 +86,7 @@ export class CommitteeDetailViewComponent extends BaseUiComponent {

public canAccessCommittee(committee: Committee): boolean {
return (
this.operator.hasCommitteePermissions(committee.id, CML.can_manage) ||
this.operator.hasCommitteePermissionsOrOrgaPermissions(committee.id, CML.can_manage) ||
this.operator.isInCommittees(committee)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ <h2>{{ 'Meetings' | translate }}</h2>

<!-- Is Template -->
<span
*osCmlPerms="
CML.can_manage;
committeeId: meeting.committee_id;
nonAdminCheck: true;
and: meeting.isTemplate
"
*osCmlPerms="CML.can_manage; committeeId: meeting.committee_id; and: meeting.isTemplate"
class="icon-prefix"
>
<mat-icon [matTooltip]="'Public template' | translate">star</mat-icon>
Expand Down Expand Up @@ -181,7 +176,7 @@ <h2>{{ 'Meetings' | translate }}</h2>

<div *osScrollingTableCell="'menu'; row as meeting; config: { width: 40 }">
<button
*osCmlPerms="CML.can_manage; committeeId: meeting.committee?.id; nonAdminCheck: true"
*osCmlPerms="CML.can_manage; committeeId: meeting.committee?.id"
data-cy="meetingListSingleMenuTrigger"
mat-icon-button
[disabled]="isMultiSelect"
Expand Down
11 changes: 1 addition & 10 deletions client/src/app/site/services/operator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,16 +659,7 @@ export class OperatorService {
*
* @returns A boolean whether an operator's CML is high enough.
*/
public hasCommitteePermissions(committeeId: Id | null, ...permissionsToCheck: CML[]): boolean {
// If a user can manage an entire organization, they can also manage every committee.
// Regardless, if they have no CML.
if (this.isOrgaManager) {
return true;
}
return this.hasCommitteePermissionsNonAdminCheck(committeeId, ...permissionsToCheck);
}

public hasCommitteePermissionsNonAdminCheck(committeeId: Id | null, ...permissionsToCheck: CML[]): boolean {
public hasCommitteePermissionsOrOrgaPermissions(committeeId: Id | null, ...permissionsToCheck: CML[]): boolean {
// A superadmin and orgaadmin can do everything
if (this.isSuperAdmin || this.isOrgaManager) {
return true;
Expand Down
7 changes: 5 additions & 2 deletions client/src/app/site/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ export class UserService {
hasPerms = true;
}
if (!hasPerms && toCompare.collection === UserScope.COMMITTEE) {
hasPerms = hasPerms || this.operator.hasCommitteePermissions(toCompare.id, CML.can_manage);
hasPerms =
hasPerms ||
this.operator.hasCommitteePermissionsOrOrgaPermissions(toCompare.id, CML.can_manage);
}
if (!hasPerms && toCompare.collection === UserScope.MEETING) {
const committee_id = this.meetingRepo.getViewModel(toCompare.id)?.committee_id;
hasPerms =
hasPerms ||
this.operator.hasPermsInMeeting(toCompare.id, Permission.userCanManage) ||
(committee_id && this.operator.hasCommitteePermissions(committee_id, CML.can_manage));
(committee_id &&
this.operator.hasCommitteePermissionsOrOrgaPermissions(committee_id, CML.can_manage));
}
return hasPerms;
});
Expand Down
13 changes: 1 addition & 12 deletions client/src/app/ui/directives/perms/cml-perms.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ export class CmlPermsDirective extends BasePermsDirective<CML> {
this.setComplementCondition(value);
}

@Input()
public set osCmlPermsNonAdminCheck(value: boolean) {
this._checkNonAdmin = value;
this.updatePermission();
}

@Input()
public set osCmlPermsThen(template: TemplateRef<any>) {
this.setThenTemplate(template);
Expand All @@ -57,7 +51,6 @@ export class CmlPermsDirective extends BasePermsDirective<CML> {
}

private _committeeId: Id | undefined = undefined;
private _checkNonAdmin = false;
private _orOML: OML | undefined = undefined;

protected hasPermissions(): boolean {
Expand All @@ -67,10 +60,6 @@ export class CmlPermsDirective extends BasePermsDirective<CML> {
if (!this._committeeId) {
return false;
}
if (this._checkNonAdmin) {
return this.operator.hasCommitteePermissionsNonAdminCheck(this._committeeId, ...this.permissions);
} else {
return this.operator.hasCommitteePermissions(this._committeeId, ...this.permissions);
}
return this.operator.hasCommitteePermissionsOrOrgaPermissions(this._committeeId, ...this.permissions);
}
}

0 comments on commit 7b6721d

Please sign in to comment.