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 adding principal in work package create

Oliver Günther99b5601c383b
diff --git a/frontend/src/app/features/boards/add-list-modal/add-list-modal.component.ts b/frontend/src/app/features/boards/add-list-modal/add-list-modal.component.ts
index ae91c074bf1..4f42e5c482c 100644
--- a/frontend/src/app/features/boards/add-list-modal/add-list-modal.component.ts
+++ b/frontend/src/app/features/boards/add-list-modal/add-list-modal.component.ts
@@ -101,7 +101,7 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {
};
public referenceOutputs = {
- onCreate: (value:HalResource) => this.onNewActionCreated(value),
+ onAddNew: (value:HalResource) => this.onNewActionCreated(value),
onOpen: () => this.requests.input$.next(''),
onChange: (value:HalResource) => this.onModelChange(value),
onAfterViewInit: (component:CreateAutocompleterComponent) => component.focusInputField(),
diff --git a/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.ts
index 0d89e5bfabe..6c7d537b0c1 100644
--- a/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.ts
@@ -59,6 +59,11 @@ export interface CreateAutocompleterValueOption {
templateUrl: './create-autocompleter.component.html',
selector: 'create-autocompleter',
styleUrls: ['./create-autocompleter.component.sass'],
+ providers: [
+ // Provide a new version of the modal invite service,
+ // as otherwise the close event will be shared across all instances
+ OpInviteUserModalService,
+ ]
})
export class CreateAutocompleterComponent extends UntilDestroyedMixin implements AfterViewInit {
@Input() public availableValues:CreateAutocompleterValueOption[];
@@ -95,7 +100,7 @@ export class CreateAutocompleterComponent extends UntilDestroyedMixin implements
@Output() public onAfterViewInit = new EventEmitter<this>();
- @Output() public onAddNew = new EventEmitter<this>();
+ @Output() public onAddNew = new EventEmitter<HalResource>();
@ViewChild(NgSelectComponent) public ngSelectComponent:NgSelectComponent;
@@ -132,7 +137,7 @@ export class CreateAutocompleterComponent extends UntilDestroyedMixin implements
filter((user) => !!user),
)
.subscribe((user:HalResource) => {
- this.onChange.emit(user);
+ this.onAddNew.emit(user);
});
}
}
diff --git a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
index 31902d796e5..87ac83cd4ad 100644
--- a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
@@ -327,6 +327,13 @@ export class ResourceChangeset<T extends HalResource = HalResource> {
return this.cache[key] = request();
}
+ /**
+ * Invalidate a cache value
+ */
+ public invalidateCache(key:string) {
+ delete this.cache[key];
+ }
+
protected get minimalPayload() {
return { lockVersion: this.pristineResource.lockVersion, _links: {} };
}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
index 2802e3d9cde..c9ade5bc737 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
@@ -33,7 +33,7 @@ import {
} from '@angular/core';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { SelectAutocompleterRegisterService } from 'core-app/shared/components/fields/edit/field-types/select-edit-field/select-autocompleter-register.service';
-import { from } from 'rxjs';
+import { from, Observable } from 'rxjs';
import {
map,
tap,
@@ -75,6 +75,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
public referenceOutputs:{ [key:string]:Function } = {
onCreate: (newElement:HalResource) => this.onCreate(newElement),
onChange: (value:HalResource) => this.onChange(value),
+ onAddNew: (value:HalResource) => this.onNewValueAdded(value),
onKeydown: (event:JQuery.TriggeredEvent) => this.handler.handleUserKeydown(event, true),
onOpen: () => this.onOpen(),
onClose: () => this.onClose(),
@@ -87,14 +88,6 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
}
public set selectedOption(val:ValueOption|HalResource) {
- // The InviteUserModal gives us a resource that is not in availableOptions yet,
- // but we also don't want to wait for a refresh of the options every time we want to
- // select an option, so if we get a HalResource we trust it exists
- if (val instanceof HalResource) {
- this.value = val;
- return;
- }
-
const option = _.find(this.availableOptions, (o) => o.href === val.href);
// Special case 'null' value, which angular
@@ -103,7 +96,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
option.href = null;
}
- this.value = option;
+ this.value = option || val;
}
public showAddNewButton:boolean;
@@ -167,7 +160,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
this.addEmptyOption();
}
- protected loadValues(query?:string) {
+ protected loadValues(query?:string):Observable<HalResource[]> {
const { allowedValues } = this.schema;
if (Array.isArray(allowedValues)) {
@@ -253,6 +246,18 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
}
}
+ private async onNewValueAdded(value:HalResource|undefined|null) {
+ if (!value) {
+ return;
+ }
+
+ const cacheKey = this.schema.allowedValues.$link.href;
+ this.change.invalidateCache(cacheKey);
+ await this.loadValues().toPromise();
+
+ this.onChange(value);
+ }
+
private addEmptyOption() {
// Empty options are not available for required fields
if (this.isRequired()) {
diff --git a/spec/features/users/invite_user_modal/invite_user_modal_spec.rb b/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
index d72ab6466af..69ee34fc63e 100644
--- a/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
+++ b/spec/features/users/invite_user_modal/invite_user_modal_spec.rb
@@ -97,6 +97,38 @@ describe 'Invite user modal', type: :feature, js: true do
end
end
+ describe 'inviting a placeholder on a WP create', with_ee: %i[placeholder_users] do
+ let!(:principal) { create :placeholder_user, name: 'EXISTING PLACEHOLDER' }
+ let(:wp_page) { Pages::FullWorkPackageCreate.new(project: project) }
+ let(:assignee_field) { wp_page.edit_field :assignee }
+ let(:subject_field) { wp_page.edit_field :subject }
+ let!(:status) { FactoryBot.create :default_status }
+ let!(:priority) { FactoryBot.create :default_priority }
+ let(:permissions) { %i[view_work_packages add_work_packages edit_work_packages manage_members work_package_assigned] }
+
+ it 'selects the placeholder' do
+ wp_page.visit!
+ subject_field.expect_active!
+ subject_field.set_value 'foobar'
+ assignee_field.expect_active!
+
+ assignee_field.openSelectField
+ find('.ng-dropdown-footer button', text: 'Invite', wait: 10).click
+
+ modal.run_all_steps
+ expect(page).to have_selector('.ng-value-label', text: principal.name)
+
+ wp_page.save!
+ wp_page.expect_and_dismiss_toaster(message: 'Successful creation.')
+
+ assignee_field.expect_inactive!
+ assignee_field.expect_state_text principal
+
+ work_package = WorkPackage.last
+ expect(work_package.assigned_to).to eq principal
+ end
+ end
+
describe 'inviting a principal to a project' do
describe 'through the assignee field' do
let(:wp_page) { Pages::FullWorkPackage.new(work_package, project) }