Skip to content

Commit

Permalink
Update frontend/src/app/features/work-packages/components/wp-buttons/…
Browse files Browse the repository at this point in the history
…wp-create-button/wp-create-button.component.ts

Co-authored-by: Dombi Attila <[email protected]>
  • Loading branch information
oliverguenther and dombesz committed Apr 17, 2024
1 parent 4b1710c commit 75bbcbf
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
import { AuthorisationService } from 'core-app/core/model-auth/model-auth.service';
import { Observable } from 'rxjs';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { filter, take } from 'rxjs/operators';
import { take } from 'rxjs/operators';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';

@Component({
selector: 'wp-create-button',
Expand Down Expand Up @@ -63,33 +63,29 @@ export class WorkPackageCreateButtonComponent extends UntilDestroyedMixin implem
explanation: this.I18n.t('js.label_create_work_package'),
};

constructor(readonly $state:StateService,
constructor(
readonly $state:StateService,
readonly currentUser:CurrentUserService,
readonly currentProject:CurrentProjectService,
readonly authorisationService:AuthorisationService,
readonly transition:TransitionService,
readonly I18n:I18nService,
readonly cdRef:ChangeDetectorRef) {
readonly cdRef:ChangeDetectorRef,
) {
super();
}

ngOnInit() {
this.projectIdentifier = this.currentProject.identifier;

// Find the first permission that is allowed
this.authorisationService
.observeUntil(componentDestroyed(this))
this.currentUser
.hasCapabilities$('work_packages/create', this.currentProject.id)
.pipe(
filter((links) => !!links.work_package),
take(1),
)
.subscribe(() => {
this.allowed = !!this
.allowedWhen
.find((combined) => {
const [module, permission] = combined.split('.');
return this.authorisationService.can(module, permission);
});

.subscribe((allowed) => {
this.allowed = allowed;
this.updateDisabledState();
});

Expand Down

0 comments on commit 75bbcbf

Please sign in to comment.