Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Clarify interface to get contextless actions

Oliver Günther7bde43fa78a5
diff --git a/frontend/src/app/core/current-user/current-user.service.ts b/frontend/src/app/core/current-user/current-user.service.ts
index 85dea4e81cb..e87611ecf10 100644
--- a/frontend/src/app/core/current-user/current-user.service.ts
+++ b/frontend/src/app/core/current-user/current-user.service.ts
@@ -75,7 +75,7 @@ export class CurrentUserService {
/**
* Returns the set of capabilities for the given context and/or actions
*/
- public capabilities$(actions:string[] = [], projectContext:string|null = null):Observable<ICapability[]> {
+ public capabilities$(actions:string[] = [], projectContext:string|null):Observable<ICapability[]> {
return this
.principalFilter$()
.pipe(
@@ -100,7 +100,7 @@ export class CurrentUserService {
* Returns an Observable<boolean> indicating whether the current user has the required capabilities
* in the provided context.
*/
- public hasCapabilities$(action:string|string[], projectContext = 'global'):Observable<boolean> {
+ public hasCapabilities$(action:string|string[], projectContext:string|null):Observable<boolean> {
const actions = _.castArray(action);
return this
.capabilities$(actions, projectContext)
@@ -117,7 +117,7 @@ export class CurrentUserService {
* Returns an Observable<boolean> indicating whether the current user
* has any of the required capabilities in the provided context.
*/
- public hasAnyCapabilityOf$(actions:string|string[], projectContext = 'global'):Observable<boolean> {
+ public hasAnyCapabilityOf$(actions:string|string[], projectContext:string|null):Observable<boolean> {
const actionsToFilter = _.castArray(actions);
return this
.capabilities$(actionsToFilter, projectContext)
diff --git a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts b/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts
index 8184b55872f..246e01500b9 100644
--- a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts
+++ b/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts
@@ -263,10 +263,10 @@ describe('Capabilities service', () => {
});
it('Should filter by context and all actions', () => {
- currentUser.hasCapabilities$('asdf/asdf').subscribe((hasCaps) => {
+ currentUser.hasCapabilities$('asdf/asdf', 'global').subscribe((hasCaps) => {
expect(hasCaps).toEqual(false);
});
- currentUser.hasCapabilities$('placeholder_users/read').subscribe((hasCaps) => {
+ currentUser.hasCapabilities$('placeholder_users/read', 'global').subscribe((hasCaps) => {
expect(hasCaps).toEqual(true);
});
currentUser.hasCapabilities$(['memberships/update', 'memberships/read'], '6').subscribe((hasCaps) => {
diff --git a/frontend/src/app/features/boards/board/board-list/board-inline-create.service.ts b/frontend/src/app/features/boards/board/board-list/board-inline-create.service.ts
index 1da0968e206..392e97201b9 100644
--- a/frontend/src/app/features/boards/board/board-list/board-inline-create.service.ts
+++ b/frontend/src/app/features/boards/board/board-list/board-inline-create.service.ts
@@ -42,7 +42,8 @@ import { Observable } from 'rxjs';
@Injectable()
export class BoardInlineCreateService extends WorkPackageInlineCreateService {
- constructor(readonly injector:Injector,
+ constructor(
+ readonly injector:Injector,
protected readonly querySpace:IsolatedQuerySpace,
protected readonly halResourceService:HalResourceService,
) {
diff --git a/frontend/src/app/features/boards/board/board-list/board-list.component.ts b/frontend/src/app/features/boards/board/board-list/board-list.component.ts
index ecbafa572cb..cb48b4400aa 100644
--- a/frontend/src/app/features/boards/board/board-list/board-list.component.ts
+++ b/frontend/src/app/features/boards/board/board-list/board-list.component.ts
@@ -36,9 +36,11 @@ import { CausedUpdatesService } from 'core-app/features/boards/board/caused-upda
import { BoardListMenuComponent } from 'core-app/features/boards/board/board-list/board-list-menu.component';
import { debugLog } from 'core-app/shared/helpers/debug_output';
import { WorkPackageCardDragAndDropService } from 'core-app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service';
-import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
import { BoardFiltersService } from 'core-app/features/boards/board/board-filter/board-filters.service';
-import { StateService, TransitionService } from '@uirouter/core';
+import {
+ StateService,
+ TransitionService,
+} from '@uirouter/core';
import { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';
import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';
import { BoardListCrossSelectionService } from 'core-app/features/boards/board/board-list/board-list-cross-selection.service';
@@ -46,7 +48,6 @@ import {
debounceTime,
filter,
map,
- retry,
take,
} from 'rxjs/operators';
import { ChangeItem } from 'core-app/shared/components/fields/changeset/changeset';
@@ -57,7 +58,10 @@ import { ApiV3Filter } from 'core-app/shared/helpers/api-v3/api-v3-filter-builde
import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
-import { HalEvent, HalEventsService } from 'core-app/features/hal/services/hal-events.service';
+import {
+ HalEvent,
+ HalEventsService,
+} from 'core-app/features/hal/services/hal-events.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
export interface DisabledButtonPlaceholder {
@@ -180,13 +184,15 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
// If this query space changes its focused or selected
// work packages, update the board cross selection
- this.wpViewSelectionService
+ this
+ .wpViewSelectionService
.updates$()
.pipe(
debounceTime(100),
this.untilDestroyed(),
- ).subscribe((selectionState) => {
- const selected = Object.keys(_.pickBy(selectionState.selected, (selected, _) => selected === true));
+ )
+ .subscribe((selectionState) => {
+ const selected = Object.keys(_.pickBy(selectionState.selected, (option, _) => option === true));
const focused = this.wpViewFocusService.focusedWorkPackage;
@@ -224,6 +230,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
.pipe(
this.untilDestroyed(),
)
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
.subscribe(async (query) => {
this.query = query;
this.canDragOutOf = !!this.query.updateOrderedWorkPackages;
@@ -322,7 +329,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
this.loadQuery(visibly);
}
- private async loadActionAttribute(query:QueryResource) {
+ private async loadActionAttribute(query:QueryResource):Promise<void> {
if (!this.board.isAction) {
this.actionResource = undefined;
this.headerComponent = undefined;
@@ -341,18 +348,21 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
}
// Load the resource
- actionService.getLoadedActionValue(query).then(async (resource) => {
- this.actionResource = resource;
- this.headerComponent = actionService.headerComponent();
- this.buttonPlaceholder = actionService.disabledAddButtonPlaceholder(resource);
- this.actionResourceClass = this.boardListActionColorClass(resource);
- this.canDragInto = actionService.dragIntoAllowed(query, resource);
-
- const canWriteAttribute = await actionService.canAddToQuery(query);
- const canAdd = await this.canAdd;
- this.showAddButton = this.canDragInto && canAdd && canWriteAttribute;
- this.cdRef.detectChanges();
- });
+ // eslint-disable-next-line consistent-return
+ return actionService
+ .getLoadedActionValue(query)
+ .then(async (resource) => {
+ this.actionResource = resource;
+ this.headerComponent = actionService.headerComponent();
+ this.buttonPlaceholder = actionService.disabledAddButtonPlaceholder(resource);
+ this.actionResourceClass = this.boardListActionColorClass(resource);
+ this.canDragInto = actionService.dragIntoAllowed(query, resource);
+
+ const canWriteAttribute = await actionService.canAddToQuery(query);
+ const canAdd = await this.canAdd;
+ this.showAddButton = this.canDragInto && canAdd && canWriteAttribute;
+ this.cdRef.detectChanges();
+ });
}
/**
@@ -409,7 +419,8 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
},
(error) => {
const userIsNotAllowedToSeeSubprojectError = 'urn:openproject-org:api:v3:errors:InvalidQuery';
- if(error.errorIdentifier === userIsNotAllowedToSeeSubprojectError) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (error.errorIdentifier === userIsNotAllowedToSeeSubprojectError) {
this.visibilityChange.emit(false);
}
this.loadingError = this.halNotification.retrieveErrorMessage(error);
@@ -462,7 +473,8 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
return !!current && (current === to || current === from);
}),
- ).subscribe((event) => {
+ )
+ .subscribe(() => {
this.updateQuery(true);
});
}
diff --git a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts b/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts
index a305bdba9f3..231529b0843 100644
--- a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts
+++ b/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts
@@ -54,7 +54,7 @@ export class BoardsMenuComponent extends UntilDestroyedMixin implements OnInit {
.currentUserService
.hasCapabilities$(
'boards/create',
- this.currentProject.id || undefined,
+ this.currentProject.id || null,
)
.pipe(this.untilDestroyed());
diff --git a/frontend/src/app/features/calendar/sidemenu/calendar-sidemenu.component.ts b/frontend/src/app/features/calendar/sidemenu/calendar-sidemenu.component.ts
index c88595bc7fe..34098361935 100644
--- a/frontend/src/app/features/calendar/sidemenu/calendar-sidemenu.component.ts
+++ b/frontend/src/app/features/calendar/sidemenu/calendar-sidemenu.component.ts
@@ -29,7 +29,7 @@ export class CalendarSidemenuComponent extends UntilDestroyedMixin {
.currentUserService
.hasCapabilities$(
'calendars/create',
- this.currentProjectService.id || undefined,
+ this.currentProjectService.id || null,
)
.pipe(this.untilDestroyed());
diff --git a/frontend/src/app/features/invite-user-modal/button/invite-user-button.component.ts b/frontend/src/app/features/invite-user-modal/button/invite-user-button.component.ts
index fff18d9fe1a..a662aa62173 100644
--- a/frontend/src/app/features/invite-user-modal/button/invite-user-button.component.ts
+++ b/frontend/src/app/features/invite-user-modal/button/invite-user-button.component.ts
@@ -43,7 +43,7 @@ export class InviteUserButtonComponent {
.currentUserService
.hasCapabilities$(
'memberships/create',
- this.projectId || undefined,
+ this.projectId || null,
);
}
diff --git a/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts b/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts
index 5b71dedd737..106293c3086 100644
--- a/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts
+++ b/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts
@@ -67,7 +67,7 @@ export class PrincipalSearchComponent extends UntilDestroyedMixin implements OnI
public canInviteByEmail$ = combineLatest(
this.items$,
this.input$,
- this.currentUserService.hasCapabilities$('users/create'),
+ this.currentUserService.hasCapabilities$('users/create', 'global'),
).pipe(
map(([elements, input, canCreateUsers]) => canCreateUsers
&& this.type === PrincipalType.User
@@ -79,7 +79,7 @@ export class PrincipalSearchComponent extends UntilDestroyedMixin implements OnI
public canCreateNewPlaceholder$ = combineLatest([
this.items$,
this.input$,
- this.currentUserService.hasCapabilities$('placeholder_users/create'),
+ this.currentUserService.hasCapabilities$('placeholder_users/create', 'global'),
])
.pipe(
map(([elements, input, hasCapability]) => {
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
index cc12247668d..e3c645941fd 100644
--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
@@ -110,7 +110,7 @@ export class ProjectSelectionComponent implements OnInit {
this
.currentUserService
- .capabilities$(['memberships/create'])
+ .capabilities$(['memberships/create'], null)
.pipe(
map((capabilities) => capabilities.filter((c) => c._links.action.href.endsWith('/memberships/create'))),
)
diff --git a/frontend/src/app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component.ts b/frontend/src/app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component.ts
index 22960f8ab80..a434c52cb8c 100644
--- a/frontend/src/app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component.ts
@@ -31,7 +31,7 @@ export class TeamPlannerSidemenuComponent extends UntilDestroyedMixin {
.currentUserService
.hasCapabilities$(
'team_planners/create',
- this.currentProjectService.id || undefined,
+ this.currentProjectService.id || null,
)
.pipe(
map((val) => val && !this.bannersService.eeShowBanners),
diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts
index 72f1d08da1b..b42ee79eeeb 100644
--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts
@@ -22,7 +22,11 @@ import { StateService } from '@uirouter/core';
import { States } from 'core-app/core/states/states.service';
import { WorkPackageViewOrderService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { filter, map, withLatestFrom } from 'rxjs/operators';
+import {
+ filter,
+ map,
+ withLatestFrom,
+} from 'rxjs/operators';
import { CausedUpdatesService } from 'core-app/features/boards/board/caused-updates/caused-updates.service';
import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';
import { CardViewHandlerRegistry } from 'core-app/features/work-packages/components/wp-card-view/event-handler/card-view-handler-registry';
@@ -35,13 +39,11 @@ import {
WorkPackageViewOutputs,
} from 'core-app/features/work-packages/routing/wp-view-base/event-handling/event-handler-registry';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
import { QueryColumn } from 'core-app/features/work-packages/components/wp-query/query-column';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
-import { combineLatest } from 'rxjs';
export type CardViewOrientation = 'horizontal'|'vertical';
diff --git a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
index 5636898b8cc..2ba9b0421cf 100644
--- a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
@@ -31,19 +31,16 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
+ EventEmitter,
HostListener,
Injector,
Input,
- EventEmitter,
OnInit,
Output,
} from '@angular/core';
import { AuthorisationService } from 'core-app/core/model-auth/model-auth.service';
import { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';
-import {
- filter,
- shareReplay,
-} from 'rxjs/operators';
+import { filter } from 'rxjs/operators';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -56,7 +53,6 @@ import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/r
import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
import { EditForm } from 'core-app/shared/components/fields/edit/edit-form/edit-form';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import {
inlineCreateCancelClassName,
diff --git a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.service.ts b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.service.ts
index d9c7bbeaf40..2b218df66f2 100644
--- a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.service.ts
@@ -92,7 +92,7 @@ export class WorkPackageInlineCreateService implements OnDestroy {
.currentUser
.hasCapabilities$(
['work_packages/create', 'work_packages/update'],
- projectId || 'global',
+ projectId || null,
);
}
diff --git a/frontend/src/app/features/work-packages/components/wp-relations/embedded/children/wp-children-inline-create.service.ts b/frontend/src/app/features/work-packages/components/wp-relations/embedded/children/wp-children-inline-create.service.ts
index 6954c83630b..240553d0392 100644
--- a/frontend/src/app/features/work-packages/components/wp-relations/embedded/children/wp-children-inline-create.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-relations/embedded/children/wp-children-inline-create.service.ts
@@ -90,7 +90,7 @@ export class WpChildrenInlineCreateService extends WorkPackageInlineCreateServic
}
public get canAddChild():boolean {
- return !!(this.schema && !this.schema.isMilestone && this.referenceTarget!.changeParent);
+ return !!(this.schema && !this.schema.isMilestone && this.referenceTarget?.changeParent);
}
/**
diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
index 222fb17cbf0..a383d3edf01 100644
--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
@@ -71,7 +71,7 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {
public textFieldFocused = false;
- public canCreateNewProjects$ = this.currentUserService.hasCapabilities$('projects/create');
+ public canCreateNewProjects$ = this.currentUserService.hasCapabilities$('projects/create', 'global');
public projects$ = combineLatest([
this.searchableProjectListService.allProjects$,