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

Fix/34840 filter out not allowed board lists (#8983)

Aleix Suau8dd5ebfc9fe3
diff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.html b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.html
index d02d9341960..e12a60e5f31 100644
--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.html
+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.html
@@ -8,19 +8,19 @@
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="moveList(board, $event)"
>
- <div *ngFor="let queryWidget of board.queries; trackBy:trackByQueryId"
+ <div *ngFor="let boardWidget of boardWidgets; trackBy:trackByQueryId"
class="boards-list--item"
wp-isolated-query-space
cdkDrag
vsDragScroll
- [cdkDragData]="queryWidget"
+ [cdkDragData]="boardWidget"
[vsDragScrollContainer]="_container">
<span *ngIf="board.editable"
class="boards-list-item-handle icon icon-drag-handle"
cdkDragHandle></span>
- <board-list [resource]="queryWidget"
+ <board-list [resource]="boardWidget"
[board]="board"
- (onRemove)="removeList(board, queryWidget)">
+ (onRemove)="removeList(board, boardWidget)">
</board-list>
</div>
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..d0840422713 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,44 @@ 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), pageSize: 0}, 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 +247,4 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implements
.filter(value => value !== undefined);
}
-}
\ No newline at end of file
+}
diff --git a/modules/boards/spec/factories/board_factory.rb b/modules/boards/spec/factories/board_factory.rb
index 2436831a5ca..ac2cb60a98f 100644
--- a/modules/boards/spec/factories/board_factory.rb
+++ b/modules/boards/spec/factories/board_factory.rb
@@ -65,4 +65,37 @@ FactoryBot.define do
end
end
end
+
+ factory :subproject_board, class: Boards::Grid do
+ project
+ name { 'My board' }
+ row_count { 1 }
+ column_count { 4 }
+
+ transient do
+ projects_columns { [FactoryBot.create(:project)] }
+ end
+
+ callback(:after_build) do |board, evaluator| # this is also done after :create
+ evaluator.projects_columns.each do |project|
+
+ query = Query.new_default(name: project.name, project: board.project, is_public: true).tap do |q|
+ q.sort_criteria = [[:manual_sorting, 'asc']]
+ q.add_filter('only_subproject_id', '=', [project.id.to_s])
+ q.save!
+ end
+
+ filters = [{ "onlySubproject" => { "operator" => "=", "values" => [project.id.to_s] } }]
+
+ board.widgets << FactoryBot.create(:grid_widget,
+ identifier: 'work_package_query',
+ start_row: 1,
+ end_row: 2,
+ start_column: 1,
+ end_column: 1,
+ options: { 'queryId' => query.id,
+ 'filters' => filters })
+ end
+ end
+ end
end
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 12df4cf6c85..b302b0afdc8 100644
--- a/modules/boards/spec/features/action_boards/subproject_board_spec.rb
+++ b/modules/boards/spec/features/action_boards/subproject_board_spec.rb
@@ -61,9 +61,9 @@ describe 'Subproject action board', type: :feature, js: true do
before do
with_enterprise_token :board_view
- project
subproject1
subproject2
+ project.reload
login_as(user)
end
@@ -172,13 +172,47 @@ describe 'Subproject action board', type: :feature, js: true do
subjects = WorkPackage.where(id: second.ordered_work_packages.pluck(:work_package_id)).pluck(:subject, :project_id)
expect(subjects).to match_array [['Task 1', subproject2.id]]
+ end
+ end
+
+ context 'with permissions in only one subproject' do
+ let(:user) do
+ FactoryBot.create(:user,
+ # The membership in subproject2 gets removed later on
+ member_in_projects: [project, subproject1, subproject2],
+ member_through_role: role)
+ end
- # Trying to access the same board as a different user
- login_as only_parent_user
+ let!(:board) do
+ FactoryBot.create(:subproject_board,
+ project: project,
+ projects_columns: [subproject1, subproject2])
+ end
+
+ let(:board_page) { Pages::Board.new(board) }
+ let!(:invisible_work_package) do
+ FactoryBot.create :work_package, project: subproject2, status: open_status
+ end
+
+ before do
+ # The membership needs to first be present in order to create the board
+ # which is created as the current_user, in this case :user.
+ # After setup, we do not want to have the user to have the permissions within the project any more
+ # as this is the goal of the test.
+ Member.where(project: subproject2, principal: user).destroy_all
+ end
+
+ it 'displays only the columns for the projects in which the current user has permission' do
board_page.visit!
- # We will see an error for the two boards pages
- expect(page).to have_selector('.notification-box.-error', count: 2)
+ board_page.expect_card subproject1.name, work_package.subject
+
+ # No error is to be displayed as erroneous columns are filtered out
+ expect(page).not_to have_selector('.notification-box.-error')
+ board_page.expect_no_list(subproject2.name)
+
+ expect(page)
+ .to have_no_content invisible_work_package.subject
end
end
end