Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/46309 Custom field no longer added to all projects when added to a type #17044

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

ulferts
Copy link
Contributor

@ulferts ulferts commented Oct 25, 2024

Ticket

https://community.openproject.org/wp/46309

What are you trying to accomplish?

Adding a custom field to a type no longer adds it to all the projects the type is active in.

When adding a project to a type, though, will add all custom fields to the project.

Merge checklist

  • Added/updated tests

@ulferts ulferts force-pushed the feature/46309-custom-field-no-longer-added-to-all-projects-when-added-to-a-type branch from 1a3a5bd to 2472544 Compare October 25, 2024 13:49
Comment on lines +168 to +182
type.custom_field_ids = type
.attribute_groups
.flat_map(&:members)
.select { CustomField.custom_field_attribute? _1 }
.map { _1.gsub(/^custom_field_/, "").to_i }
.uniq
end

def active_custom_field_ids
@active_custom_field_ids ||= begin
active_cf_ids = []

type.attribute_groups.each do |group|
group.members.each do |attribute|
if CustomField.custom_field_attribute? attribute
active_cf_ids << attribute.gsub(/^custom_field_/, "").to_i
end
end
end
active_cf_ids.uniq
end
end
def set_active_custom_fields_for_project_ids(project_ids)
new_project_ids_to_activate_cfs = project_ids.reject(&:empty?).map(&:to_i) - type.project_ids

def set_active_custom_fields_for_projects(projects, custom_field_ids)
values = projects
values = Project
.where(id: new_project_ids_to_activate_cfs)
.to_a
.product(custom_field_ids)
.product(type.custom_field_ids)
Copy link
Contributor Author

@ulferts ulferts Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code's functionality wasn't changed. It was just cleaned up after having less callers.

@ulferts ulferts marked this pull request as ready for review October 25, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant