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

Ensure we reload values in select field when changeset updates

Oliver Günther42c33d16e81d
diff --git a/frontend/src/app/components/wp-edit/work-package-changeset.ts b/frontend/src/app/components/wp-edit/work-package-changeset.ts
index 9186a194c87..e758b237a40 100644
--- a/frontend/src/app/components/wp-edit/work-package-changeset.ts
+++ b/frontend/src/app/components/wp-edit/work-package-changeset.ts
@@ -10,7 +10,7 @@ export class WorkPackageChangeset extends ResourceChangeset<WorkPackageResource>
// when the work package is new. Otherwise, the save request afterwards
// will update the form automatically.
if (this.pristineResource.isNew && (key === 'project' || key === 'type')) {
- this.updateForm().then(() => this.push());
+ this.updateForm();
}
}
diff --git a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
index d164ef45c18..8d502a36d5a 100644
--- a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
@@ -60,6 +60,11 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
public appendTo:any = null;
private hiddenOverflowContainer = '.__hidden_overflow_container';
+ /** Remember the values loading promise which changes as soon as the changeset is updated
+ * (e.g., project or type is changed).
+ */
+ private valuesLoadingPromise:Promise<unknown>;
+
protected _autocompleterComponent:CreateAutocompleterComponent;
public referenceOutputs:{ [key:string]:Function } = {
@@ -76,6 +81,10 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
requiredPlaceholder: this.I18n.t('js.placeholders.selection'),
placeholder: this.I18n.t('js.placeholders.default')
};
+
+ this.valuesLoadingPromise = this.change.getForm().then(() => {
+ return this.initialValueLoading();
+ });
}
protected initialValueLoading() {
@@ -92,17 +101,13 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
super.ngOnInit();
this.appendTo = this.overflowingSelector;
- let loadingPromise = this.change.getForm().then(() => {
- return this.initialValueLoading();
- });
-
this.handler
.$onUserActivate
.pipe(
this.untilDestroyed()
)
.subscribe(() => {
- loadingPromise.then(() => {
+ this.valuesLoadingPromise.then(() => {
this._autocompleterComponent.openDirectly = true;
});
});
diff --git a/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts b/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts
index 32fe77abf47..cf1514690b8 100644
--- a/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts
+++ b/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts
@@ -26,12 +26,9 @@
// See docs/COPYRIGHT.rdoc for more details.
// ++
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {combine, deriveRaw, InputState, multiInput, MultiInputState, State, StatesGroup} from 'reactivestates';
import {map} from 'rxjs/operators';
import {Injectable, Injector} from '@angular/core';
-import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";
-import {SchemaCacheService} from "core-components/schemas/schema-cache.service";
import {Subject} from "rxjs";
import {FormResource} from "core-app/modules/hal/resources/form-resource";
import {ChangeMap} from "core-app/modules/fields/changeset/changeset";
@@ -204,7 +201,9 @@ export class HalResourceEditingService extends StateCacheService<ResourceChanges
if (changeset && !changeset.isEmpty()) {
return changeset;
}
- if (!changeset || resource.hasOwnProperty('lockVersion') && changeset.pristineResource.lockVersion < resource.lockVersion) {
+ if (!changeset ||
+ changeset.pristineResource !== resource ||
+ resource.hasOwnProperty('lockVersion') && changeset.pristineResource.lockVersion < resource.lockVersion) {
return this.edit<V, T>(resource);
}
diff --git a/spec/features/work_packages/new/new_work_package_spec.rb b/spec/features/work_packages/new/new_work_package_spec.rb
index 6513d0f5d78..063e06e0952 100644
--- a/spec/features/work_packages/new/new_work_package_spec.rb
+++ b/spec/features/work_packages/new/new_work_package_spec.rb
@@ -13,7 +13,13 @@ describe 'new work package', js: true do
FactoryBot.create(:project, types: types)
end
- let(:user) { FactoryBot.create :admin }
+ let(:permissions) { [:view_work_packages, :add_work_packages, :edit_work_packages] }
+ let(:user) do
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+
let(:work_packages_page) { WorkPackagesPage.new(project) }
let(:subject) { 'My subject' }
@@ -22,6 +28,7 @@ describe 'new work package', js: true do
let(:subject_field) { wp_page.edit_field :subject }
let(:description_field) { wp_page.edit_field :description }
let(:project_field) { wp_page.edit_field :project }
+ let(:assignee_field) { wp_page.edit_field :assignee }
let(:type_field) { wp_page.edit_field :type }
let(:notification) { PageObjects::Notifications.new(page) }
@@ -61,6 +68,12 @@ describe 'new work package', js: true do
project_field.set_value project
sleep 1
+
+ # Select self as assignee
+ assignee_field.openSelectField
+ assignee_field.set_value user.name
+
+ sleep 1
end
before do
@@ -291,6 +304,19 @@ describe 'new work package', js: true do
click_on 'Cancel'
end
+ it 'can save the work package with an assignee (Regression #32887)' do
+ create_work_package_globally(type_task, project.name)
+ expect(page).to have_selector(safeguard_selector, wait: 10)
+
+ wp_page.subject_field.set('new work package')
+ save_work_package!
+ wp_page.dismiss_notification!
+
+ assignee_field.expect_state_text user.name
+ wp = WorkPackage.last
+ expect(wp.assigned_to).to eq user
+ end
+
context 'with a project without type_bug' do
let!(:project_without_bug) do
FactoryBot.create(:project, name: 'Unrelated project', types: [type_task])