Skip to content

Commit

Permalink
Merge branch 'main' into 1046-replace-tinymce
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored Jul 15, 2024
2 parents 426c89e + 0772be9 commit 9252b1c
Show file tree
Hide file tree
Showing 28 changed files with 321 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ describe(`GetUserScopePresenterService`, () => {
8: { title: `superadmin` }
};

function getExpectedCompareResult(key1: keyof typeof scopeMap, key2: keyof typeof scopeMap): number {
return key1 > key2 ? 1 : -1;
}

const testScopes: { [key in keyof typeof scopeMap]: any } = {
2: {
collection: UserScope.MEETING,
Expand Down Expand Up @@ -81,40 +77,4 @@ describe(`GetUserScopePresenterService`, () => {
it(`should correctly call get_user_scope`, async () => {
expect(await service.call({ user_ids: [2, 3, 5, 6, 7, 8] })).toEqual(testScopes);
});

for (const key of Object.keys(scopeMap).map(x => +x as keyof typeof scopeMap)) {
const otherKeys: (keyof typeof scopeMap)[] = Object.keys(scopeMap)
.map(key => +key as keyof typeof scopeMap)
.filter(otherKey => otherKey !== key);
it(`test compareScope with oml comparison for ${scopeMap[key].title}`, async () => {
expect(await service.compareScope(testScopes[key], testScopes[otherKeys[0]], true)).toBe(
getExpectedCompareResult(key, otherKeys[0])
);
expect(await service.compareScope(testScopes[key], testScopes[otherKeys[1]], true)).toBe(
getExpectedCompareResult(key, otherKeys[1])
);
expect(await service.compareScope(testScopes[key], testScopes[otherKeys[2]], true)).toBe(
getExpectedCompareResult(key, otherKeys[2])
);
expect(await service.compareScope(testScopes[key], testScopes[otherKeys[3]], true)).toBe(
getExpectedCompareResult(key, otherKeys[3])
);
expect(await service.compareScope(testScopes[key], testScopes[otherKeys[4]], true)).toBe(
getExpectedCompareResult(key, otherKeys[4])
);
expect(await service.compareScope(testScopes[key], testScopes[key], true)).toBe(0);
expect(await service.compareScope(testScopes[key], { ...testScopes[key], id: 9 }, true)).toBe(0);
});
}

it(`test compareScope with default settings`, async () => {
expect(await service.compareScope(testScopes[2], testScopes[3])).toBe(-1);
expect(await service.compareScope(testScopes[2], testScopes[5])).toBe(-1);
expect(await service.compareScope(testScopes[3], testScopes[5])).toBe(-1);
expect(await service.compareScope(testScopes[3], testScopes[2])).toBe(1);
expect(await service.compareScope(testScopes[5], testScopes[2])).toBe(1);
expect(await service.compareScope(testScopes[5], testScopes[3])).toBe(1);
expect(await service.compareScope(testScopes[7], testScopes[6])).toBe(0);
expect(await service.compareScope(testScopes[6], testScopes[6])).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface GetUserScopeIdentifiedScope {
collection: UserScope;
id: Id;
user_oml: OML | ``;
committee_ids: number[];
}

export interface GetUserScopePresenterResult {
Expand All @@ -29,40 +30,4 @@ export class GetUserScopePresenterService {
public async call(payload: GetUserScopePresenterPayload): Promise<GetUserScopePresenterResult> {
return await this.presenter.call(Presenter.GET_USER_SCOPE, payload);
}

/**
* Compares two scopes and returns a number depending on the result.
* `0` means it is equal, `1` means it is higher, `-1` means it is lower.
*
* @param scope A first scope
* @param toCompare A scope to compare with the first scope
* @param compareOml Whether the OML differences between the scopes should be taken into account
* @returns The result of the comparison
*/
public compareScope(
scope: GetUserScopeIdentifiedScope,
toCompare: GetUserScopeIdentifiedScope,
compareOml = false
): number {
if (scope.collection === toCompare.collection && (compareOml ? scope.user_oml === toCompare.user_oml : true)) {
return 0;
}
if (compareOml) {
if (scope.user_oml !== `` || toCompare.user_oml !== ``) {
return scope.user_oml !== `` &&
(toCompare.user_oml === `` ||
(scope.user_oml === OML.superadmin && toCompare.user_oml !== OML.superadmin) ||
(scope.user_oml === OML.can_manage_organization && toCompare.user_oml === OML.can_manage_users))
? 1
: -1;
}
}
if (scope.collection === UserScope.ORGANIZATION) {
return 1;
}
if (scope.collection === UserScope.COMMITTEE && toCompare.collection === UserScope.MEETING) {
return 1;
}
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ng-container *ngTemplateOutlet="editTemplate; context: { form: personalInfoForm }"></ng-container>
</mat-card-content>
</mat-card>
@if (editView) {
@if (editView && useAdditionalEditTemplate) {
<mat-card class="os-card">
<mat-card-content>
<ng-container *ngTemplateOutlet="editView; context: { form: personalInfoForm }"></ng-container>
Expand All @@ -16,7 +16,7 @@
}
@if (!useMatcard) {
<ng-container *ngTemplateOutlet="editTemplate; context: { form: personalInfoForm }"></ng-container>
@if (editView) {
@if (editView && useAdditionalEditTemplate) {
<ng-container
[ngTemplateOutlet]="editView"
[ngTemplateOutletContext]="{ form: personalInfoForm }"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class UserDetailViewComponent extends BaseUiComponent implements OnInit,
@Input()
public useMatcard = true;

@Input()
public useAdditionalEditTemplate = true;

@Input()
public set additionalFormControls(controls: any) {
this._additionalFormControls = controls;
Expand Down Expand Up @@ -344,7 +347,12 @@ export class UserDetailViewComponent extends BaseUiComponent implements OnInit,
};
}

private getChangedValues(data: { [key: string]: any }): { [key: string]: any } {
private getChangedValues(formData: { [key: string]: any }): { [key: string]: any } {
const data = this.useAdditionalEditTemplate
? formData
: Object.keys(formData).mapToObject(key =>
Object.keys(this._additionalFormControls ?? {}).includes(key) ? {} : { [key]: formData[key] }
);
const newData = {};
if (this.user) {
Object.keys(data).forEach(key => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { OML } from 'src/app/domain/definitions/organization-permission';
import { Permission } from 'src/app/domain/definitions/permission';
import { BaseMeetingComponent } from 'src/app/site/pages/meetings/base/base-meeting.component';
import { ViewGroup } from 'src/app/site/pages/meetings/pages/participants';
import { ParticipantControllerService } from 'src/app/site/pages/meetings/pages/participants/services/common/participant-controller.service';
import {
MEETING_RELATED_FORM_CONTROLS,
ParticipantControllerService
} from 'src/app/site/pages/meetings/pages/participants/services/common/participant-controller.service';
import { PERSONAL_FORM_CONTROLS, ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { OrganizationSettingsService } from 'src/app/site/pages/organization/services/organization-settings.service';
import { OperatorService } from 'src/app/site/services/operator.service';
Expand Down Expand Up @@ -72,7 +75,9 @@ export class ParticipantDetailViewComponent extends BaseMeetingComponent {
if (this._isUserInScope || (this.newUser && canUpdateUsers)) {
return true;
} else if (canUpdateUsers) {
return controlName === `is_present` ? this.operator.hasPerms(Permission.userCanManagePresence) : true;
return controlName === `is_present`
? this.operator.hasPerms(Permission.userCanManagePresence)
: MEETING_RELATED_FORM_CONTROLS.includes(controlName);
} else {
return PERSONAL_FORM_CONTROLS.includes(controlName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ParticipantControllerService } from 'src/app/site/pages/meetings/pages/
import { MeetingSettingsService } from 'src/app/site/pages/meetings/services/meeting-settings.service';
import { ViewMeetingUser } from 'src/app/site/pages/meetings/view-models/view-meeting-user';
import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { UserService } from 'src/app/site/services/user.service';
import { BaseUiComponent } from 'src/app/ui/base/base-ui-component';

import { StructureLevelControllerService } from '../../../../../structure-levels/services/structure-level-controller.service';
Expand All @@ -32,18 +31,13 @@ export class ParticipantListInfoDialogComponent extends BaseUiComponent implemen
return this._otherParticipantsSubject;
}

public get isUserInScope(): boolean {
return this._isUserInScope;
}

public get showVoteDelegations(): boolean {
return this._voteDelegationEnabled;
}

public structureLevelObservable: Observable<ViewStructureLevel[]>;

private readonly _otherParticipantsSubject = new BehaviorSubject<ViewMeetingUser[]>([]);
private _isUserInScope = true;
private _currentUser: ViewUser | null = null;
private _voteDelegationEnabled = false;

Expand All @@ -53,7 +47,6 @@ export class ParticipantListInfoDialogComponent extends BaseUiComponent implemen
private userSortService: ParticipantListSortService,
private groupRepo: GroupControllerService,
private structureLevelRepo: StructureLevelControllerService,
private userService: UserService,
private meetingSettings: MeetingSettingsService
) {
super();
Expand All @@ -62,7 +55,6 @@ export class ParticipantListInfoDialogComponent extends BaseUiComponent implemen
public ngOnInit(): void {
this.userSortService.initSorting();
this._currentUser = this.participantRepo.getViewModel(this.infoDialog.id);
this.updateIsUserInScope();
this.structureLevelObservable = this.structureLevelRepo.getViewModelListObservable();
this.subscriptions.push(
this.participantRepo
Expand All @@ -84,8 +76,4 @@ export class ParticipantListInfoDialogComponent extends BaseUiComponent implemen
this.userSortService.exitSortService();
super.ngOnDestroy();
}

private async updateIsUserInScope(): Promise<void> {
this._isUserInScope = await this.userService.isUserInSameScope(this.infoDialog.id);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@for (entry of menuEntries; track entry) {
<span>
<a
*osOmlPerms="entry.permission!"
*osOmlPerms="entry.permission!; allowCommitteeAdmin: entry.optionalCML === CML.can_manage"
class="management-router-link foreground-icon"
mat-menu-item
routerLinkActive="foreground-active"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Component } from '@angular/core';
import { OML } from 'src/app/domain/definitions/organization-permission';
import { CML, OML } from 'src/app/domain/definitions/organization-permission';
import { BaseMenuEntry, getCustomStyleForEntry } from 'src/app/site/base/base-menu-entry';
import { MainMenuService } from 'src/app/site/pages/meetings/services/main-menu.service';
import { AuthService } from 'src/app/site/services/auth.service';
import { ViewPortService } from 'src/app/site/services/view-port.service';

interface OrgaMenuEntry extends BaseMenuEntry<OML> {}
interface OrgaMenuEntry extends BaseMenuEntry<OML> {
optionalCML?: CML;
}

@Component({
selector: `os-organization-navigation`,
templateUrl: `./organization-navigation.component.html`,
styleUrls: [`./organization-navigation.component.scss`]
})
export class OrganizationNavigationComponent {
public CML = CML;

public menuEntries: OrgaMenuEntry[] = [
{
route: `/`,
Expand All @@ -39,6 +43,7 @@ export class OrganizationNavigationComponent {
displayName: `Accounts`,
icon: `group`,
permission: OML.can_manage_users,
optionalCML: CML.can_manage,
weight: 300
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { OML } from '../../../domain/definitions/organization-permission';
import { CML, OML } from '../../../domain/definitions/organization-permission';
import { AuthGuard } from '../../guards/auth.guard';
import { PermissionGuard } from '../../guards/permission.guard';
import { OrganizationNavigationWrapperComponent } from './modules/navigation/organization-navigation-wrapper/organization-navigation-wrapper.component';
Expand Down Expand Up @@ -31,7 +31,7 @@ const routes: Routes = [
{
path: `accounts`,
loadChildren: () => import(`./pages/accounts/accounts.module`).then(m => m.AccountsModule),
data: { omlPermissions: [OML.can_manage_users] },
data: { omlPermissions: [OML.can_manage_users], optionalCmlPermissions: [CML.can_manage] },
canLoad: [PermissionGuard]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ const routes: Routes = [
loadChildren: () => import(`./pages/account-list/account-list.module`).then(m => m.AccountListModule)
},
{
path: `meeting/:id`,
loadChildren: () => import(`./pages/account-list/account-list.module`).then(m => m.AccountListModule)
path: `meeting/:meetingId`,
children: [
{
path: ``,
pathMatch: `full`,
loadChildren: () =>
import(`./pages/account-list/account-list.module`).then(m => m.AccountListModule)
},
{
path: `:id`,
loadChildren: () =>
import(`./pages/account-detail/account-detail.module`).then(m => m.AccountDetailModule)
}
]
},
{
path: `create`,
Expand Down
Loading

0 comments on commit 9252b1c

Please sign in to comment.