diff --git a/frontend/src/app/core/services/permissions/permissions.service.spec.ts b/frontend/src/app/core/services/permissions/permissions.service.spec.ts deleted file mode 100644 index b61fd5bc14..0000000000 --- a/frontend/src/app/core/services/permissions/permissions.service.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { PermissionsService } from './permissions.service'; - -// TODO: Test this service -/*describe('PermissionsService', () => { - let service:PermissionsService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(PermissionsService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -});*/ diff --git a/frontend/src/app/core/services/permissions/permissions.service.ts b/frontend/src/app/core/services/permissions/permissions.service.ts deleted file mode 100644 index 66b80790be..0000000000 --- a/frontend/src/app/core/services/permissions/permissions.service.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Injectable } from '@angular/core'; -import { APIV3Service } from 'core-app/modules/apiv3/api-v3.service'; -import { Observable, of } from 'rxjs'; -import { CurrentProjectService } from 'core-components/projects/current-project.service'; -import { map, catchError } from 'rxjs/operators'; -import { FilterOperator } from 'core-components/api/api-v3/api-v3-filter-builder'; - -@Injectable({ - providedIn: 'root', -}) -export class PermissionsService { - constructor( - private apiV3Service:APIV3Service, - private currentProjectService:CurrentProjectService, - ) { } - - canInviteUsersToProject(projectId = this.currentProjectService.id!):Observable { - // TODO: Remove/Fix this typing issue - const filters:[string, FilterOperator, string[]][] = [['id', '=', [projectId]]]; - - return this.apiV3Service - .memberships - .available_projects - .list({ filters }) - .pipe( - map(collection => !!collection.elements.length), - catchError((error) => { - console.error(error); - return of(false); - }), - ); - } -} diff --git a/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts index dda4ac34c4..8f2ab0a72a 100644 --- a/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts +++ b/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts @@ -36,7 +36,6 @@ import { from } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { HalResourceNotificationService } from 'core-app/modules/hal/services/hal-resource-notification.service'; import { InjectField } from 'core-app/helpers/angular/inject-field.decorator'; -import { PermissionsService } from 'core-app/core/services/permissions/permissions.service'; import { CreateAutocompleterComponent } from "core-app/modules/autocompleter/create-autocompleter/create-autocompleter.component"; import { EditFormComponent } from "core-app/modules/fields/edit/edit-form/edit-form.component"; import { StateService } from "@uirouter/core"; @@ -53,7 +52,6 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn @InjectField() selectAutocompleterRegister:SelectAutocompleterRegisterService; @InjectField() halNotification:HalResourceNotificationService; @InjectField() halSorting:HalResourceSortingService; - @InjectField() permissionsService:PermissionsService; @InjectField() $state:StateService; @InjectField(EditFormComponent, null, InjectFlags.Optional) editFormComponent:EditFormComponent; diff --git a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html index 15a287dfcd..a398694ffb 100644 --- a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html +++ b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html @@ -2,7 +2,7 @@ class="op-select-footer--label" type="button" (click)="onAddNewClick($event)" - *ngIf="canInviteUsersToProject" + *ngIf="canInviteUsersToProject$ | async" > diff --git a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts index 44a246df5c..f56e721d55 100644 --- a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts +++ b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts @@ -1,7 +1,8 @@ -import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectorRef, Component } from '@angular/core'; import { NgSelectComponent } from "@ng-select/ng-select"; import { I18nService } from "core-app/modules/common/i18n/i18n.service"; -import { PermissionsService } from "core-app/core/services/permissions/permissions.service"; +import { CurrentUserService } from "core-app/modules/current-user/current-user.service"; +import { CurrentProjectService } from "core-app/components/projects/current-project.service"; import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/invite-user-modal.service"; @Component({ @@ -9,7 +10,7 @@ import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/inv templateUrl: './invite-user-button.component.html', styleUrls: ['./invite-user-button.component.sass'] }) -export class InviteUserButtonComponent implements OnInit { +export class InviteUserButtonComponent { /** This component does not provide an output, because both primary usecases were in places where the button was * destroyed before the modal closed, causing the data from the modal to never arrive at the parent. * If you want to do something with the output from the modal that is opened, use the OpInviteUserModalService @@ -18,25 +19,21 @@ export class InviteUserButtonComponent implements OnInit { text = { button: this.I18n.t('js.invite_user_modal.invite'), }; - canInviteUsersToProject:boolean; + + canInviteUsersToProject$ = this.currentUserService.hasCapabilities$( + 'memberships/create', + this.currentProjectService.id || undefined, + ); constructor( readonly I18n:I18nService, readonly opInviteUserModalService:OpInviteUserModalService, - readonly permissionsService:PermissionsService, + readonly currentUserService:CurrentUserService, + readonly currentProjectService:CurrentProjectService, readonly ngSelectComponent:NgSelectComponent, readonly changeDetectorRef:ChangeDetectorRef, ) {} - ngOnInit():void { - this.permissionsService - .canInviteUsersToProject() - .subscribe(canInviteUsersToProject => { - this.canInviteUsersToProject = canInviteUsersToProject; - this.changeDetectorRef.detectChanges(); - }); - } - onAddNewClick($event:Event) { $event.stopPropagation(); this.opInviteUserModalService.open(); diff --git a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts index bfd2efeef4..aa0a0ab393 100644 --- a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts +++ b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts @@ -5,6 +5,7 @@ import { TextFieldModule } from '@angular/cdk/text-field'; import { NgSelectModule } from "@ng-select/ng-select"; import { OpenprojectModalModule } from "core-app/modules/modal/modal.module"; import { OpenprojectCommonModule } from "core-app/modules/common/openproject-common.module"; +import { CurrentUserModule } from 'core-app/modules/current-user/current-user.module'; import { DynamicFormsModule } from "core-app/modules/common/dynamic-forms/dynamic-forms.module"; import { OpInviteUserModalAugmentService } from "core-app/modules/invite-user-modal/invite-user-modal-augment.service"; import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/invite-user-modal.service"; @@ -37,6 +38,7 @@ export function initializeServices(injector:Injector) { TextFieldModule, DynamicFormsModule, InviteUserButtonModule, + CurrentUserModule, ], exports: [ InviteUserButtonModule, diff --git a/frontend/src/app/modules/invite-user-modal/project-selection/project-allowed.validator.ts b/frontend/src/app/modules/invite-user-modal/project-selection/project-allowed.validator.ts index 5d3c7e2f2b..2119d179a6 100644 --- a/frontend/src/app/modules/invite-user-modal/project-selection/project-allowed.validator.ts +++ b/frontend/src/app/modules/invite-user-modal/project-selection/project-allowed.validator.ts @@ -5,7 +5,7 @@ import { catchError, map, take } from "rxjs/operators"; export const ProjectAllowedValidator = (currentUserService:CurrentUserService) => { return (control: AbstractControl) => { - return currentUserService.hasCapabilities$('memberships/update', control.value.idFromLink).pipe( + return currentUserService.hasCapabilities$('memberships/create', control.value.idFromLink).pipe( take(1), map(isAllowed => isAllowed ? null : { lackingPermission: true }), catchError(() => of(null))