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

[34840] Unclear error message when subproject column for action board cannot be displayed due to missing permissions (handling this bug in another way) (#8852)

Behrokh Satarnejad55fa5a18030b
diff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts
index b9970d0ad46..c4397e34de1 100644
--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts
+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts
@@ -1,5 +1,5 @@
import {Component, ElementRef, Injector, OnInit, QueryList, ViewChild, ViewChildren} from "@angular/core";
-import {Observable, Subscription} from "rxjs";
+import {forkJoin, Observable, of, Subscription} from "rxjs";
import {QueryResource} from "core-app/modules/hal/resources/query-resource";
import {BoardListComponent} from "core-app/modules/boards/board/board-list/board-list.component";
import {StateService} from "@uirouter/core";
@@ -19,9 +19,10 @@ import {BoardPartitionedPageComponent} from "core-app/modules/boards/board/board
import {AddListModalComponent} from "core-app/modules/boards/board/add-list-modal/add-list-modal.component";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {BoardListCrossSelectionService} from "core-app/modules/boards/board/board-list/board-list-cross-selection.service";
-import {filter} from "rxjs/operators";
+import {catchError, filter, map, switchMap, tap} from "rxjs/operators";
import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";
import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";
+import { WorkPackageStatesInitializationService } from 'core-app/components/wp-list/wp-states-initialization.service';
@Component({
templateUrl: './board-list-container.component.html',
@@ -66,6 +67,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements
trackByQueryId = (index:number, widget:GridWidgetResource) => widget.options.queryId;
board$:Observable<Board>;
+ boardWidgets:GridWidgetResource[] = [];
private currentQueryUpdatedMonitoring:Subscription;
@@ -82,30 +84,27 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements
readonly Boards:BoardService,
readonly Banner:BannersService,
readonly boardListCrossSelectionService:BoardListCrossSelectionService,
+ readonly wpStatesInitialization:WorkPackageStatesInitializationService,
readonly Drag:DragAndDropService,
+ readonly apiv3Service:APIV3Service,
readonly QueryUpdated:QueryUpdatedService) {
super();
}
ngOnInit():void {
const id:string = this.state.params.board_id.toString();
-
this.board$ = this
.apiV3Service
.boards
.id(id)
- .requireAndStream();
+ .requireAndStream()
+ .pipe(
+ this.setAllowedBoardWidgets,
+ tap(board => this.setupQueryUpdatedMonitoring(board))
+ );
this.Boards.currentBoard$.next(id);
- this.board$
- .pipe(
- this.untilDestroyed()
- )
- .subscribe(board => {
- this.setupQueryUpdatedMonitoring(board);
- });
-
this.boardListCrossSelectionService
.selections()
.pipe(
@@ -118,6 +117,43 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements
});
}
+ setAllowedBoardWidgets = (boardObservable:Observable<Board>) => {
+ // The grid config could have widgets that the user is not allowed to
+ // see, so we filter out those that rise an access error.
+ return boardObservable
+ .pipe(
+ switchMap(
+ board => this.getAllowedBoardWidgets(board).pipe(map(allowedBoardWidgets => ({board, allowedBoardWidgets}))),
+ ),
+ map(result => {
+ this.boardWidgets = result.allowedBoardWidgets;
+ return result.board;
+ })
+ );
+ }
+
+ getAllowedBoardWidgets(board:Board) {
+ if (board.queries.length) {
+ const queryRequests$ = board.queries.map(query => this.apiv3Service.queries
+ .find({filters: JSON.stringify(query.options.filters)} , query.options.queryId as string)
+ .pipe(
+ map(() => query),
+ catchError(error => {
+ const userIsNotAllowedToSeeSubprojectError = 'urn:openproject-org:api:v3:errors:InvalidQuery';
+ const result = error.errorIdentifier === userIsNotAllowedToSeeSubprojectError ? null : query;
+
+ return of(result);
+ })
+ )
+ );
+
+ return forkJoin([...queryRequests$])
+ .pipe(map(boardWidgets => boardWidgets.filter(boardWidget => !!boardWidget) as GridWidgetResource[]));
+ } else {
+ return of([]);
+ }
+ }
+
moveList(board:Board, event:CdkDragDrop<GridWidgetResource[]>) {
moveItemInArray(board.queries, event.previousIndex, event.currentIndex);
this.saveBoard(board);
@@ -210,4 +246,4 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements
.filter(value => value !== undefined);
}
-}
\ No newline at end of file
+}
diff --git a/modules/boards/spec/features/action_boards/subproject_board_spec.rb b/modules/boards/spec/features/action_boards/subproject_board_spec.rb
index 562e2342946..1e24d32f40d 100644
--- a/modules/boards/spec/features/action_boards/subproject_board_spec.rb
+++ b/modules/boards/spec/features/action_boards/subproject_board_spec.rb
@@ -171,8 +171,11 @@ describe 'Subproject action board', type: :feature, js: true do
login_as only_parent_user
board_page.visit!
- # We will see an error for the two boards pages
- expect(page).to have_selector('.notification-box.-error', count: 2)
+ # Not allowed subproject lists should not rise error and
+ # should not be shown
+ expect(page).to have_no_selector('.notification-box.-error')
+ board_page.expect_no_list 'Child 1'
+ board_page.expect_no_list 'Child 2'
end
end
end