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

[#60652] Mandatory fields not visible during project creation

Dombi Attilaa0f723d7d818
diff --git a/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts b/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
index b7240765b93..b20ce6bb486 100644
--- a/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
+++ b/frontend/src/app/features/projects/components/copy-project/copy-project.component.ts
@@ -1,3 +1,31 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
import {
IDynamicFieldGroupConfig,
IOPFormlyFieldSettings,
@@ -8,11 +36,11 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
-import { Component, OnInit } from '@angular/core';
+import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { JobStatusModalService } from 'core-app/features/job-status/job-status-modal.service';
-
@Component({
+ changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './copy-project.component.html',
})
export class CopyProjectComponent extends UntilDestroyedMixin implements OnInit {
@@ -70,16 +98,16 @@ export class CopyProjectComponent extends UntilDestroyedMixin implements OnInit
.map((field) => ({ ...field, hide: this.isHiddenField(field.key) }));
}
- private isPrimaryAttribute(to?:IOPFormlyTemplateOptions):boolean {
- if (!to) {
+ private isPrimaryAttribute(templateOptions?:IOPFormlyTemplateOptions):boolean {
+ if (!templateOptions) {
return false;
}
- return (to.required
- && !to.hasDefault
- && to.payloadValue == null)
- || to.property === 'name'
- || to.property === 'parent';
+ const nameOrParent = ['name', 'parent'].includes(templateOptions.property as string);
+ const noPayload = templateOptions.payloadValue == null
+ || (templateOptions.payloadValue as { href?:string|null })?.href == null;
+
+ return (templateOptions.required && !templateOptions.hasDefault && noPayload) || nameOrParent;
}
private isMeta(property:string|undefined):boolean {
diff --git a/frontend/src/app/features/projects/components/new-project/new-project.component.ts b/frontend/src/app/features/projects/components/new-project/new-project.component.ts
index 6b84ad66866..f5b496b384a 100644
--- a/frontend/src/app/features/projects/components/new-project/new-project.component.ts
+++ b/frontend/src/app/features/projects/components/new-project/new-project.component.ts
@@ -1,6 +1,38 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { IDynamicFieldGroupConfig, IOPFormlyFieldSettings } from 'core-app/shared/components/dynamic-forms/typings';
+import {
+ IDynamicFieldGroupConfig,
+ IOPFormlyFieldSettings,
+ IOPFormlyTemplateOptions,
+} from 'core-app/shared/components/dynamic-forms/typings';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
@@ -20,6 +52,7 @@ export interface ProjectTemplateOption {
}
@Component({
+ changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './new-project.component.html',
styleUrls: ['./new-project.component.sass'],
})
@@ -89,11 +122,8 @@ export class NewProjectComponent extends UntilDestroyedMixin implements OnInit {
this.resourcePath = this.apiV3Service.projects.path;
this.fieldGroups = [{
name: this.text.advancedSettingsLabel,
- fieldsFilter: (field) => !['name', 'parent'].includes(field.templateOptions?.property as string)
- && !this.isMeta(field.templateOptions?.property)
- && !(field.templateOptions?.required
- && !field.templateOptions.hasDefault
- && field.templateOptions.payloadValue == null),
+ fieldsFilter: (field) => !this.isMeta(field.templateOptions?.property)
+ && !this.isPrimaryAttribute(field.templateOptions),
},
{
name: this.text.copySettingsLabel,
@@ -140,6 +170,18 @@ export class NewProjectComponent extends UntilDestroyedMixin implements OnInit {
return !!property && (property.startsWith('copy') || property === 'sendNotifications');
}
+ private isPrimaryAttribute(templateOptions?:IOPFormlyTemplateOptions):boolean {
+ if (!templateOptions) {
+ return false;
+ }
+
+ const nameOrParent = ['name', 'parent'].includes(templateOptions.property as string);
+ const noPayload = templateOptions.payloadValue == null
+ || (templateOptions.payloadValue as { href?:string|null })?.href == null;
+
+ return (templateOptions.required && !templateOptions.hasDefault && noPayload) || nameOrParent;
+ }
+
private setParentAsPayload(parentId:string) {
const href = this.apiV3Service.projects.id(parentId).path;
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index d9091f1fdf2..80786ce4f98 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -65,10 +67,10 @@ RSpec.describe "Projects copy", :js,
end
let!(:project_custom_field_section) { create(:project_custom_field_section, name: "Section A") }
let!(:project_custom_field) do
- create(:text_project_custom_field, is_required: true, project_custom_field_section:)
+ create(:text_project_custom_field, name: "Required Foo", is_required: true, project_custom_field_section:)
end
let!(:optional_project_custom_field) do
- create(:text_project_custom_field, is_required: false, project_custom_field_section:)
+ create(:text_project_custom_field, name: "Optional Foo", is_required: false, project_custom_field_section:)
end
let!(:optional_project_custom_field_with_default) do
create(:text_project_custom_field, is_required: false, default_value: "foo", project_custom_field_section:)
@@ -162,6 +164,34 @@ RSpec.describe "Projects copy", :js,
clear_performed_jobs
end
+ context "with optional and required custom fields" do
+ let!(:required_user_custom_field) do
+ create(:user_project_custom_field, name: "Required User",
+ is_required: true,
+ project_custom_field_section:)
+ end
+
+ before do
+ Pages::Projects::Settings::General.new(project).visit!
+
+ page.find_test_selector("project-settings-more-menu").click
+ page.find_test_selector("project-settings--copy").click
+ end
+
+ it "separates optional and required custom fields for new" do
+ expect(page).to have_content "Required Foo"
+ expect(page).to have_content "Required User"
+
+ click_on "Advanced settings"
+
+ within(".op-fieldset", match: :first) do
+ expect(page).to have_text "Optional Foo"
+ expect(page).to have_no_text "Required Foo"
+ expect(page).to have_no_text "Required User"
+ end
+ end
+ end
+
context "with correct project custom field activations" do
before do
Pages::Projects::Settings::General.new(project).visit!
@@ -475,7 +505,7 @@ RSpec.describe "Projects copy", :js,
# Using the db directly due to performance and clarity
copied_work_packages = copied_project.work_packages
- expect(copied_work_packages.length).to eql 1
+ expect(copied_work_packages.length).to be 1
copied_work_package = copied_work_packages[0]
@@ -491,7 +521,7 @@ RSpec.describe "Projects copy", :js,
expect(copied_work_package.custom_value_attributes).to eql(wp_custom_field.id => "Some wp cf text")
expect(copied_work_package.attachments.map(&:filename)).to eq ["work_package_attachment.pdf"]
- expect(ActionMailer::Base.deliveries.count).to eql(1)
+ expect(ActionMailer::Base.deliveries.count).to be(1)
expect(ActionMailer::Base.deliveries.last.subject).to eql("Created project Copied project")
expect(ActionMailer::Base.deliveries.last.to).to contain_exactly(user.mail)
end
diff --git a/spec/features/projects/create_spec.rb b/spec/features/projects/create_spec.rb
index 83802134296..a16213a8ca9 100644
--- a/spec/features/projects/create_spec.rb
+++ b/spec/features/projects/create_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -125,16 +127,27 @@ RSpec.describe "Projects", "creation",
project_custom_field_section:)
end
- it "separates optional and required custom fields for new" do
- visit new_project_path
+ context "with required custom fields" do
+ let!(:required_user_custom_field) do
+ create(:user_project_custom_field, name: "Required User",
+ is_for_all: true,
+ is_required: true,
+ project_custom_field_section:)
+ end
+
+ it "separates optional and required custom fields for new" do
+ visit new_project_path
- expect(page).to have_content "Required Foo"
+ expect(page).to have_content "Required Foo"
+ expect(page).to have_content "Required User"
- click_on "Advanced settings"
+ click_on "Advanced settings"
- within(".op-fieldset") do
- expect(page).to have_text "Optional Foo"
- expect(page).to have_no_text "Required Foo"
+ within(".op-fieldset") do
+ expect(page).to have_text "Optional Foo"
+ expect(page).to have_no_text "Required Foo"
+ expect(page).to have_no_text "Required User"
+ end
end
end