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

[34063] Prevent child to be moved into its own column

Oliver Günthere5c40d030bd0
diff --git a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts
index 41e76950aa4..20f9176b9e6 100644
--- a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts
+++ b/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts
@@ -224,10 +224,10 @@ export abstract class BoardActionService {
assignToWorkPackage(changeset:WorkPackageChangeset, query:QueryResource) {
// Ensure attribute remains writable in the form
if (!changeset.isWritable(this.filterName)) {
- throw this.I18n.t(
+ throw new Error(this.I18n.t(
'js.boards.error_attribute_not_writable',
{ attribute: changeset.humanName(this.filterName) }
- );
+ ));
}
new WorkPackageFilterValues(this.injector, query.filters)
diff --git a/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
index deb08eebc50..5b0d833f2ce 100644
--- a/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
+++ b/frontend/src/app/modules/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
@@ -6,13 +6,15 @@ import {Observable} from "rxjs";
import {map} from "rxjs/operators";
import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";
import {SubtasksBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/subtasks/subtasks-board-header.component";
+import {QueryResource} from "core-app/modules/hal/resources/query-resource";
+import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";
@Injectable()
export class BoardSubtasksActionService extends BoardActionService {
filterName = 'parent';
text = this.I18n.t('js.boards.board_type.action_by_attribute',
- { attribute: this.I18n.t('js.boards.board_type.action_type.subtasks')}) ;
+ { attribute: this.I18n.t('js.boards.board_type.action_type.subtasks') });
description = this.I18n.t('js.boards.board_type.action_text_subtasks');
@@ -32,6 +34,17 @@ export class BoardSubtasksActionService extends BoardActionService {
return !!workPackage.changeParent;
}
+ assignToWorkPackage(changeset:WorkPackageChangeset, query:QueryResource) {
+ const parentId = this.getActionValueId(query)?.toString();
+
+ // Disable dragging a work package into its own column
+ if (parentId === changeset.id) {
+ throw new Error(this.I18n.t('js.boards.error_cannot_move_into_self'));
+ }
+
+ super.assignToWorkPackage(changeset, query);
+ }
+
protected loadValues(matching?:string):Observable<HalResource[]> {
let filters = new ApiV3FilterBuilder();
filters.add('is_milestone', '=', false);
diff --git a/frontend/src/app/modules/fields/changeset/resource-changeset.ts b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
index 790a5551a3d..1436fdca088 100644
--- a/frontend/src/app/modules/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/modules/fields/changeset/resource-changeset.ts
@@ -158,7 +158,7 @@ export class ResourceChangeset<T extends HalResource = HalResource> {
* Return the ID of the resource we're editing
*/
public get id():string {
- return this.pristineResource.id as string;
+ return this.pristineResource.id!.toString();
}
/**
diff --git a/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts b/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts
index 0b17510b276..7a03ddd8df1 100644
--- a/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts
+++ b/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts
@@ -89,6 +89,11 @@ export class HalResourceNotificationService {
return;
}
+ if (response instanceof Error) {
+ this.NotificationsService.addError(response.message);
+ return;
+ }
+
this.showGeneralError(errorBody || response);
}
diff --git a/modules/boards/config/locales/js-en.yml b/modules/boards/config/locales/js-en.yml
index 70366152de8..78748912fa5 100644
--- a/modules/boards/config/locales/js-en.yml
+++ b/modules/boards/config/locales/js-en.yml
@@ -32,6 +32,7 @@ en:
error_attribute_not_writable: "Cannot move the work package, %{attribute} is not writable."
error_loading_the_list: "Error loading the list: %{error_message}"
error_permission_missing: "The permission to create public queries is missing"
+ error_cannot_move_into_self: "You can not move a work package into its own column."
click_to_remove_list: "Click to remove this list"
board_type:
text: 'Board type'
diff --git a/modules/boards/spec/features/action_boards/subtasks_board_spec.rb b/modules/boards/spec/features/action_boards/subtasks_board_spec.rb
index 7e04776f80f..a2c4cdfb7af 100644
--- a/modules/boards/spec/features/action_boards/subtasks_board_spec.rb
+++ b/modules/boards/spec/features/action_boards/subtasks_board_spec.rb
@@ -155,5 +155,25 @@ describe 'Subtasks action board', type: :feature, js: true do
board_page.expect_card('Parent WP', 'Second child', present: true)
board_page.expect_card('Other WP', 'Second child', present: false)
end
+
+ it 'prevents adding a work package to its own column' do
+ board_index.visit!
+ board_page = board_index.create_board action: :Children, expect_empty: true
+ board_page.add_list option: 'Parent WP'
+ board_page.expect_list 'Parent WP'
+ board_page.expect_card 'Parent WP', 'Child'
+
+ board_page.add_list option: 'Child WP'
+ board_page.expect_list 'Child WP'
+
+ # Try to move child to itself
+ board_page.move_card(0, from: 'Parent WP', to: 'Child WP')
+
+ board_page.expect_and_dismiss_notification type: :error,
+ message: I18n.t('js.boards.error_cannot_move_into_self')
+
+ child.reload
+ expect(child.parent).to eq parent
+ end
end
end