Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Let the filter bar and saved views work without a project
Guido Boyke5ecb2a7c82a6
diff --git a/app/components/neo_filter_bar_component.html.erb b/app/components/neo_filter_bar_component.html.erbindex 3f63d7b..f8657a4 100644--- a/app/components/neo_filter_bar_component.html.erb+++ b/app/components/neo_filter_bar_component.html.erb@@ -26,7 +26,7 @@data-filter-bar-labels-value="<%= filter_bar_labels_json %>"data-filter-bar-operator-labels-value="<%= operator_labels_json %>"data-filter-bar-save-url-value="<%= save_smart_folder_path %>"- data-filter-bar-project-id-value="<%= project.id %>"+ data-filter-bar-project-id-value="<%= project&.id %>"data-filter-bar-save-labels-value="<%= save_labels_json %>"data-filter-bar-search-mode-value="<%= search_mode %>"data-filter-bar-smart-folder-id-value="<%= active_smart_folder&.id %>"diff --git a/app/components/neo_filter_bar_component.rb b/app/components/neo_filter_bar_component.rbindex a1c5880..b60a4b0 100644--- a/app/components/neo_filter_bar_component.rb+++ b/app/components/neo_filter_bar_component.rb@@ -39,8 +39,8 @@ class NeoFilterBarComponent < ViewComponent::Baseall_items_label:,smart_folder_context_type:,smart_folder_return_to:,- project:,organisation:,+ project: nil,active_smart_folder: nil,active_view_permissions: {},dissolver_result: nil,@@ -79,6 +79,9 @@ class NeoFilterBarComponent < ViewComponent::Base@current_user_id = current_user_id@search_value = search_value@search_mode = search_mode || 'content'+ # The list's project; nil on a list of the whole organisation ("Alle+ # Meetings"). Then no URL of the bar names a project, and a view saved from+ # it belongs to the organisation-wide list.@project = project@organisation = organisation@builtin_views = Array(builtin_views)@@ -386,7 +389,7 @@ class NeoFilterBarComponent < ViewComponent::Basedef new_smart_folder_urlhelpers.new_organisation_smart_folder_path(organisation,- project_id: project.id,+ project_id: project&.id,context_type: smart_folder_context_type,modal: true,return_to: smart_folder_return_to,@@ -413,7 +416,7 @@ class NeoFilterBarComponent < ViewComponent::Base# The way that does not overwrite a view somebody else uses (20a, § 4).# Anyone who may see a folder may copy it; the copy belongs to them.duplicate_url: helpers.clone_organisation_smart_folder_path(organisation, active_smart_folder),- expert_url: helpers.edit_organisation_smart_folder_path(organisation, active_smart_folder, modal: true, return_to: smart_folder_return_to, project_id: project.id, list_context: return_params.presence),+ expert_url: helpers.edit_organisation_smart_folder_path(organisation, active_smart_folder, modal: true, return_to: smart_folder_return_to, project_id: project&.id, list_context: return_params.presence),delete_url: (helpers.organisation_smart_folder_path(organisation, active_smart_folder) if active_view_permissions[:delete])}elsediff --git a/app/controllers/organisations/smart_folders_controller.rb b/app/controllers/organisations/smart_folders_controller.rbindex d614699..24c7b0f 100644--- a/app/controllers/organisations/smart_folders_controller.rb+++ b/app/controllers/organisations/smart_folders_controller.rb@@ -187,21 +187,27 @@ class Organisations::SmartFoldersController < Organisations::BaseController# Quick-updates an existing SmartFolder's rules from ad-hoc filter params.# Called via PATCH from the filter bar "save changes" action. An org-wide- # folder has no project of its own; the list the bar sits on sends its- # project_id, which supplies the attribute definitions for the conversion.+ # ticket or knowledge folder has no project of its own; the list the bar sits+ # on sends its project_id, which supplies the attribute definitions for the+ # conversion. A meeting folder needs none: its conditions are no custom+ # attributes, and its own project (or none, "Alle Meetings") is its list.# Only Meeting folders support an empty set as an unfiltered view. Other# targets keep the existing guard because their empty rule tree matches nothing.def update_from_filtersauthorize @smart_folder, :update?- project = @smart_folder.project || selectable_projects.find_by(id: params[:project_id])- filter_params = project ? sanitized_filter_params(project) : {}+ project = if meeting_folder_context?+ @smart_folder.project+ else+ @smart_folder.project || selectable_projects.find_by(id: params[:project_id])+ end+ filter_params = project || meeting_folder_context? ? sanitized_filter_params(project) : {}# A type condition (S7) names the folder's target, which is immutable: it# cannot become a rule of this folder. Refused loudly rather than sliced# away by the sanitizer, or the bar would record the condition as saved.# The bar offers "Als neue Ansicht" for that case, where the type becomes# the new folder's target.- if project.nil? || invalid_filter_update?(filter_params) || filter_carries_type_condition?+ if (project.nil? && !meeting_folder_context?) || invalid_filter_update?(filter_params) || filter_carries_type_condition?error = t('flash.smart_folders.update_from_filters_error', default: 'Fehler beim Speichern des Filters.')return respond_to do |format|format.json { render json: { success: false, error: error }, status: :unprocessable_content }@@ -212,6 +218,7 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerresult = Actors::SaveSmartFolderFromFilters.call(smart_folder: @smart_folder,project: project,+ organisation: @current_organisation,current_user: current_user,filter_params: filter_params,operator_params: sanitized_operator_params,@@ -222,7 +229,7 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerrespond_to do |format|format.json { render json: { success: true }, status: :ok }format.html do- redirect_to filter_save_return_path(project.id, smart_folder_id: @smart_folder.id), notice: t('flash.smart_folders.updated_from_filters', default: 'Filter wurde gespeichert.')+ redirect_to filter_save_return_path(project&.id, smart_folder_id: @smart_folder.id), notice: t('flash.smart_folders.updated_from_filters', default: 'Filter wurde gespeichert.')endendelse@@ -276,33 +283,38 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerrender json: { success: true, columns: @smart_folder.ordered_columns }, status: :okend- # Converts ad-hoc list filters (tickets or knowledge) into a persisted SmartFolder.- # The saved folder follows the source list's active type filter via+ # Converts ad-hoc list filters (tickets, knowledge or meetings) into a persisted+ # SmartFolder. The saved folder follows the source list's active type filter via# params[:target_object_type] (PE-B); params[:return_to] picks the redirect target.+ # A meeting list without a project ("Alle Meetings") sends no project_id: its+ # view belongs to no project and shows only there.def create_from_filters@smart_folder = SmartFolder.new(organisation: @current_organisation)authorize @smart_folder, :create?@smart_folder.target_object_type = filter_save_target_object_type- project = selectable_projects(area: meeting_folder_context? ? :meetings : nil).find(params[:project_id])+ project = filter_save_projectfilter_params = sanitized_filter_params(project)# A folder without rules matches nothing, for good (SmartFolderQueryBuilder# answers [] on empty rule groups). A type condition alone (S7) arrives as# an empty set, because the bar turns it into the target, not a rule.if filter_params.values.all?(&:blank?) || (meeting_folder_context? && rejected_filter_params?(filter_params))- redirect_to filter_save_return_path(project.id), alert: t('flash.smart_folders.create_from_filters_error')+ redirect_to filter_save_return_path(project&.id), alert: t('flash.smart_folders.create_from_filters_error')returnend# A new ticket view starts with the reader's base view columns of the project# ("Alle Tickets" is the template, plan D6) and stands alone from then on.+ # A view without a project has no base view to start from (columns come with+ # PR 2 of doc/meetings_uebersicht_vereinheitlichen_plan.md).target = filter_save_target_object_typeview_type = target == 'Meeting' ? 'meetings' : 'tickets'- base_columns = ViewConfiguration.for_user_project(current_user, project, view_type)- inherited = base_columns.ordered_columns if target.in?(%w[Ticket All Meeting])+ base_columns = ViewConfiguration.for_user_project(current_user, project, view_type) if project+ inherited = base_columns.ordered_columns if base_columns && target.in?(%w[Ticket All Meeting])result = Actors::SaveSmartFolderFromFilters.call(project: project,+ organisation: @current_organisation,current_user: current_user,filter_params: filter_params,operator_params: sanitized_operator_params,@@ -315,12 +327,12 @@ class Organisations::SmartFoldersController < Organisations::BaseController)if result.success?- redirect_to filter_save_return_path(project.id, smart_folder_id: result.resource.id),+ redirect_to filter_save_return_path(project&.id, smart_folder_id: result.resource.id),notice: t('flash.smart_folders.created_from_filters')else# Too many conditions is the one refusal the reader can fix, so it says so.alert = result.code == :rule_tree_too_large ? result.errors.to_sentence : t('flash.smart_folders.create_from_filters_error')- redirect_to filter_save_return_path(project.id), alert: alert+ redirect_to filter_save_return_path(project&.id), alert: alertendend@@ -585,7 +597,8 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerMeetings::ListState.extract(context).merge(context.permit(:meeting_id, :new).to_h)end- # Redirect target after saving the filter: back to the source page.+ # Redirect target after saving the filter: back to the source page. A meeting+ # view without a project belongs to "Alle Meetings" and goes back there.def filter_save_return_path(project_id, smart_folder_id: nil)shared = {organisation_id: @current_organisation.id,@@ -594,7 +607,8 @@ class Organisations::SmartFoldersController < Organisations::BaseController}.compactif params[:return_to] == 'meetings' || @smart_folder&.target_object_type == 'Meeting' && params[:return_to] != 'knowledge'- organisation_project_meetings_path(**meeting_return_context.except('smart_folder_id', 'filter', 'filter_op', 'filter_drop', 'participant').symbolize_keys.merge(shared))+ context = meeting_return_context.except('smart_folder_id', 'filter', 'filter_op', 'filter_drop', 'participant').symbolize_keys+ project_id ? organisation_project_meetings_path(**context.merge(shared)) : organisation_meetings_path(**context.merge(shared))elsif params[:return_to] == 'knowledge'organisation_project_knowledge_index_path(**shared)else@@ -610,16 +624,18 @@ class Organisations::SmartFoldersController < Organisations::BaseController# definition for create and update, the HTML redirect AND the Turbo Stream# (@modal_redirect_url in the stream templates), so the four cannot drift.def save_success_redirect_path+ # A meeting view goes back to the list it belongs to, and its own project+ # decides which one: that project's page, or "Alle Meetings" without one.+ return filter_save_return_path(@smart_folder.project_id, smart_folder_id: @smart_folder.id) if @smart_folder.target_object_type == 'Meeting' && params[:return_to] == 'meetings'+project_id = @smart_folder.project&.id || params[:project_id]- unless project_id.present? && %w[notes tickets knowledge meetings].include?(params[:return_to])+ unless project_id.present? && %w[notes tickets knowledge].include?(params[:return_to])return organisation_smart_folder_path(@current_organisation, @smart_folder) if @smart_folder.target_object_type == 'Meeting'return organisation_smart_folders_path(organisation_id: @current_organisation.id)endcase params[:return_to]- when 'meetings'- filter_save_return_path(project_id, smart_folder_id: @smart_folder.id)when 'notes'organisation_project_notes_path(organisation_id: @current_organisation.id, project_id: project_id)when 'knowledge'@@ -647,7 +663,11 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerdef available_field_optionstarget_type = @smart_folder&.target_object_type || params[:context_type] || 'All'- project = @smart_folder&.project || filter_builder_projects.find_by(id: params[:project_id])+ # A meeting view's project is one the reader may read meetings in; a reader+ # without ticket access there still has the project (and with it no field+ # "Projekt", SmartFolderRule::field_config without_project_only).+ projects = meeting_folder_context? ? selectable_projects(area: :meetings) : filter_builder_projects+ project = @smart_folder&.project || projects.find_by(id: params[:project_id])helpers.available_field_options(target_type, @current_organisation, project: project, accessible_project_ids: filter_builder_projects.ids)@@ -700,12 +720,27 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerempty && params[:clear_filters] != '1'end+ # Refused as a whole: a key the list does not know, or a project the reader+ # cannot read. A rule on such a project would match nothing for the reader, but+ # it would store the project's name (SmartFolderRule#display_value) and name the+ # project in the view to everybody it is shared with.def rejected_filter_params?(filters)raw = params[:filter]return false if raw.nil?return true unless raw.is_a?(ActionController::Parameters)+ return true if raw.keys.any? { |key| !filters.key?(key) }++ (Array(filters['project']) - selectable_projects(area: :meetings).ids.map(&:to_s)).any?+ end++ # The project a view saved from the filter bar belongs to: the list's own. A+ # meeting list without a project ("Alle Meetings") sends none, and its view+ # belongs to the organisation. Every other list names its project, and an+ # unknown or unreadable one is a 404 as before.+ def filter_save_project+ return nil if meeting_folder_context? && params[:project_id].blank?- raw.keys.any? { |key| !filters.key?(key) }+ selectable_projects(area: meeting_folder_context? ? :meetings : nil).find(params[:project_id])enddef sanitized_filter_params(project)@@ -713,7 +748,7 @@ class Organisations::SmartFoldersController < Organisations::BaseControllerreturn {} unless raw.respond_to?(:to_unsafe_h)allowed_keys = if meeting_folder_context?- %w[participant creator occurred_at created_at updated_at]+ %w[participant creator project occurred_at created_at updated_at]elseAdHocToSmartFolderService::SPECIAL_FIELDS + project.ticket_attribute_definitions.active.pluck(:name)enddiff --git a/app/helpers/smart_folder_helper.rb b/app/helpers/smart_folder_helper.rbindex 9beef2f..5c889b7 100644--- a/app/helpers/smart_folder_helper.rb+++ b/app/helpers/smart_folder_helper.rb@@ -36,6 +36,7 @@ module SmartFolderHelperfield_config.each do |field, config|# Check whether the field is applicable to the object typenext if (config[:applicable_types] & target_types).empty?+ next if config[:without_project_only] && projectoption = {value: field,diff --git a/app/javascript/lib/filter_bar/save_row.js b/app/javascript/lib/filter_bar/save_row.jsindex b3fc1bc..5d776cb 100644--- a/app/javascript/lib/filter_bar/save_row.js+++ b/app/javascript/lib/filter_bar/save_row.js@@ -58,7 +58,7 @@ export function buildNamingRowHtml({ saveUrl, projectId, filters, operators, sugreturn `<form class="${ROW}" method="post" action="${escapeAttr(saveUrl)}" data-turbo="false" data-fb-naming><input type="hidden" name="authenticity_token" value="${escapeAttr(getCSRFToken())}">- <input type="hidden" name="project_id" value="${escapeAttr(projectId)}">+ ${projectId ? `<input type="hidden" name="project_id" value="${escapeAttr(projectId)}">` : ''}${buildFilterHiddenFields(filters, operators)}${buildSortHiddenFields()}${hidden}diff --git a/app/models/smart_folder_rule.rb b/app/models/smart_folder_rule.rbindex 37967e1..a5c370b 100644--- a/app/models/smart_folder_rule.rb+++ b/app/models/smart_folder_rule.rb@@ -80,6 +80,22 @@ class SmartFolderRule < ApplicationRecorddescription: 'Teilnehmer',icon: 'people'},+ # The organisation-wide meetings list ("Alle Meetings") narrows by project.+ # without_project_only: a view of one project has its project already, so+ # the expert filter offers the field only on a view without one. One rule+ # per project, like creator: several values in OR are one group each.+ 'project' => {+ applicable_types: %w[Meeting],+ operators: [EQUALS, NOT_EQUALS],+ filter_class: 'AssociationFilter',+ field_map: { 'Meeting' => 'project_id' },+ value_type: :reference,+ value_required: true,+ reference_model: 'Project',+ without_project_only: true,+ description: 'Projekt',+ icon: 'folder'+ },'occurred_at' => {applicable_types: %w[Meeting],operators: [EQUALS, NOT_EQUALS, BEFORE, AFTER, BETWEEN, WITHIN_DAYS, IN_THE_LAST_DAYS, *SmartFolders::DatePresets::KEYS],diff --git a/app/services/actors/save_smart_folder_from_filters.rb b/app/services/actors/save_smart_folder_from_filters.rbindex cec1274..0c39098 100644--- a/app/services/actors/save_smart_folder_from_filters.rb+++ b/app/services/actors/save_smart_folder_from_filters.rb@@ -13,11 +13,14 @@ module Actors# columns: the ordered column list a NEW folder starts with (doc/spaltenwahl_plan.md,# D6); nil leaves it following the reader's base view. Ignored on update, the# save row has its own endpoint for a folder's columns.+ # project: nil for a view of a list of the whole organisation ("Alle Meetings");+ # the folder then belongs to no project, and organisation names its owner.def initialize(project:, current_user:, filter_params:, operator_params:, name:,- smart_folder: nil, sort_column: nil, sort_direction: nil,- target_object_type: 'Ticket', columns: nil, pinned_columns: nil)+ organisation: project&.organisation, smart_folder: nil, sort_column: nil,+ sort_direction: nil, target_object_type: 'Ticket', columns: nil, pinned_columns: nil)super()@project = project+ @organisation = organisation@current_user = current_user@filter_params = filter_params@operator_params = operator_params@@ -60,6 +63,7 @@ module Actorsdef convert_filtersAdHocToSmartFolderService.call(project: @project,+ organisation: @organisation,filter_params: @filter_params,operator_params: @operator_params,target_object_type: @smart_folder&.target_object_type || @target_object_type@@ -88,10 +92,11 @@ module Actorsenddef create_folder- folder = @project.smart_folders.new(+ folder = SmartFolder.new(+ project: @project,name: @name,user: @current_user,- organisation: @project.organisation,+ organisation: @organisation,target_object_type: @target_object_type,sort_column: @sort_column,sort_direction: @sort_directiondiff --git a/app/services/ad_hoc_filter_service.rb b/app/services/ad_hoc_filter_service.rbindex d164a32..19cec9f 100644--- a/app/services/ad_hoc_filter_service.rb+++ b/app/services/ad_hoc_filter_service.rb@@ -20,7 +20,9 @@ class AdHocFilterService# The bar's categories that are not custom attributes. AdHocToSmartFolderService reads this list,# and through it SmartFoldersController#sanitized_filter_params: a new category is added here only.SPECIAL_FIELDS = %w[assignee tag creator created_at updated_at due_date waiting blocking].freeze- MEETING_FIELDS = %w[participant occurred_at].freeze+ # project: the organisation-wide meetings list only ("Alle Meetings"). It narrows+ # an already policy-scoped relation, so an id the reader cannot read matches nothing.+ MEETING_FIELDS = %w[participant occurred_at project].freezeVALID_OPERATORS = %w[or and not].freezeDEFAULT_OPERATOR = 'or'@@ -90,6 +92,8 @@ class AdHocFilterServicecase keywhen 'participant', 'occurred_at'klass == Meeting || klass.column_names.include?('custom_attributes')+ when 'project'+ klass == Meetingwhen 'assignee', *Tickets::WaitingStateFilter::STATESklass == Ticketwhen 'tag'@@ -221,6 +225,17 @@ class AdHocFilterServiceMeetings::ParticipantFilter.call(query, filter_params['participant'], operator: operator_for('participant'))end+ def apply_project_filter(query)+ project_ids = Array(filter_params['project']).grep(String).reject(&:blank?)+ return query if project_ids.empty?++ if operator_for('project') == 'not'+ query.where.not(project_id: project_ids)+ else+ query.where(project_id: project_ids)+ end+ end+def apply_occurred_at_filter(query)apply_date_filter(query, :occurred_at)enddiff --git a/app/services/ad_hoc_to_smart_folder_service.rb b/app/services/ad_hoc_to_smart_folder_service.rbindex 727bbf4..486ab7e 100644--- a/app/services/ad_hoc_to_smart_folder_service.rb+++ b/app/services/ad_hoc_to_smart_folder_service.rb@@ -32,7 +32,7 @@ class AdHocToSmartFolderService# a copy: two copies meant every new category had to be added twice, and one# forgotten copy dropped the condition silently on save (plan §9, option A).SPECIAL_FIELDS = AdHocFilterService::SPECIAL_FIELDS- MEETING_FIELDS = %w[participant occurred_at].freeze+ MEETING_FIELDS = AdHocFilterService::MEETING_FIELDS# The conditions would exceed SmartFolder::MAX_RULE_GROUPS or# MAX_RULES_PER_GROUP. Raised before the cross product is built; the message@@ -41,14 +41,18 @@ class AdHocToSmartFolderServiceConversion = Struct.new(:rules_by_group, :field_config_map, :preloaded_references, :warnings, keyword_init: true)- def self.call(project:, filter_params:, operator_params: {}, target_object_type: 'Ticket')- new(project: project, filter_params: filter_params, operator_params: operator_params, target_object_type: target_object_type).convert+ # project: nil on a list of the whole organisation (a meetings view of+ # "Alle Meetings"); the organisation then has to be named.+ def self.call(project:, filter_params:, operator_params: {}, target_object_type: 'Ticket', organisation: project&.organisation)+ new(project: project, filter_params: filter_params, operator_params: operator_params,+ target_object_type: target_object_type, organisation: organisation).convertend- attr_reader :project, :filter_params, :operator_params, :warnings+ attr_reader :project, :organisation, :filter_params, :operator_params, :warnings- def initialize(project:, filter_params:, operator_params: {}, target_object_type: 'Ticket')+ def initialize(project:, filter_params:, operator_params: {}, target_object_type: 'Ticket', organisation: project&.organisation)@project = project+ @organisation = organisation@filter_params = filter_params.presence || {}@operator_params = operator_params.presence || {}@target_object_type = target_object_type@@ -60,7 +64,7 @@ class AdHocToSmartFolderServicerules_by_group = build_rules_for_groupsConversion.new(rules_by_group: rules_by_group,- field_config_map: SmartFolderRule.field_config_with_custom_attributes(project.organisation, project),+ field_config_map: SmartFolderRule.field_config_with_custom_attributes(organisation, project),preloaded_references: preload_references(rules_by_group),warnings: warnings)@@ -136,6 +140,7 @@ class AdHocToSmartFolderServicewhen 'assignee' then convert_assignee(values)when 'tag' then convert_tag(values)when 'creator' then convert_creator(values)+ when 'project' then convert_reference('project', values)when 'participant' then [{ field: key, operator: { 'and' => HAS_ALL_OF, 'not' => NOT_HAS }.fetch(operator_for(key), HAS_ANY_OF), value: values.to_json }]when 'created_at', 'updated_at', 'occurred_at' then convert_date(key, values)when 'due_date' then convert_due_date(values)@@ -145,22 +150,22 @@ class AdHocToSmartFolderServiceenddef convert_assignee(values)- convert_user_reference('assignee', values)+ convert_reference('assignee', values)enddef convert_creator(values)- convert_user_reference('creator', values)+ convert_reference('creator', values)end- # Shared conversion for user reference fields (assignee, creator):+ # Shared conversion for reference fields (assignee, creator, project):# NOT -> not_equals rules in one group; OR with multiple values ->- # one group per user (alternatives).- def convert_user_reference(field, values)+ # one group per record (alternatives).+ def convert_reference(field, values)case operator_for(field)when 'not'- values.map { |uid| { field: field, operator: NOT_EQUALS, value: uid } }+ values.map { |id| { field: field, operator: NOT_EQUALS, value: id } }else # 'or'- alternatives(values.map { |uid| { field: field, operator: EQUALS, value: uid } })+ alternatives(values.map { |id| { field: field, operator: EQUALS, value: id } })endend@@ -278,7 +283,7 @@ class AdHocToSmartFolderService.map { |r| r[:value] }.compact.uniqreturn nil if user_ids.empty?- users_by_id = project.organisation.users.where(id: user_ids).index_by { |u| u.id.to_s }+ users_by_id = organisation.users.where(id: user_ids).index_by { |u| u.id.to_s }{ 'User' => users_by_id }enddiff --git a/app/services/smart_folder_dissolver.rb b/app/services/smart_folder_dissolver.rbindex 3a6b938..403a24f 100644--- a/app/services/smart_folder_dissolver.rb+++ b/app/services/smart_folder_dissolver.rb@@ -4,7 +4,7 @@# into ad-hoc filter chips for the unified filter bar.## "Dissolvable" means all rules use fields/operators that have ad-hoc filter equivalents:-# - assignee/creator (equals/not_equals)+# - assignee/creator/project (equals/not_equals)# - custom_* select/multiselect (equals/in_list/not_in_list/not_equals)# - tag (has/not_has/has_any_of/has_all_of)# - created_at/updated_at with a date preset operator (SmartFolders::DatePresets),@@ -31,7 +31,7 @@ class SmartFolderDissolverend# Fields that can be dissolved into ad-hoc filters- DISSOLVABLE_FIELDS = %w[assignee creator tag created_at updated_at occurred_at participant waiting blocking].freeze+ DISSOLVABLE_FIELDS = %w[assignee creator project tag created_at updated_at occurred_at participant waiting blocking].freeze# Operators supported for dissolution per fieldDISSOLVABLE_OPERATORS = {@@ -39,6 +39,7 @@ class SmartFolderDissolver'occurred_at' => [IN_THE_LAST_DAYS, *SmartFolders::DatePresets::KEYS],'assignee' => [EQUALS, NOT_EQUALS],'creator' => [EQUALS, NOT_EQUALS],+ 'project' => [EQUALS, NOT_EQUALS],'tag' => [HAS, NOT_HAS, HAS_ANY_OF, HAS_ALL_OF],'created_at' => [IN_THE_LAST_DAYS, *SmartFolders::DatePresets::KEYS],'updated_at' => [IN_THE_LAST_DAYS, *SmartFolders::DatePresets::KEYS],@@ -46,9 +47,9 @@ class SmartFolderDissolver'blocking' => [IS, IS_NOT]}.freeze- # User-reference fields whose multi-group OR pattern (one equals rule per+ # Reference fields whose multi-group OR pattern (one equals rule per# group, possibly as a cross product of multiple fields) is dissolvable- OR_MULTI_FIELDS = %w[assignee creator].freeze+ OR_MULTI_FIELDS = %w[assignee creator project].freeze# The built-in date fields; their presets are the operators (SmartFolders::DatePresets)DATE_FIELDS = %w[created_at updated_at occurred_at].freeze@@ -283,8 +284,8 @@ class SmartFolderDissolverreturn nil unless allowed_ops&.include?(rule.operator)case rule.field- when 'assignee', 'creator'- convert_user_reference_rule(rule)+ when *OR_MULTI_FIELDS+ convert_reference_rule(rule)when 'participant'op = { NOT_EQUALS => 'not', NOT_HAS => 'not', HAS_ALL_OF => 'and' }[rule.operator]{ key: 'participant', values: Meetings::ParticipantFilter.rule_values(rule.value), operator: op }@@ -304,7 +305,7 @@ class SmartFolderDissolver{ key: rule.field, values: [Tickets::WaitingStateFilter::FLAG_VALUE], operator: present ? nil : 'not' }end- def convert_user_reference_rule(rule)+ def convert_reference_rule(rule)case rule.operatorwhen EQUALS{ key: rule.field, values: [rule.value], operator: nil }@@ -340,7 +341,7 @@ class SmartFolderDissolverdef convert_multi_value_field(field, operator, values)case field- when 'assignee', 'creator'+ when *OR_MULTI_FIELDScase operatorwhen EQUALS{ key: field, values: values, operator: nil }diff --git a/spec/javascript/lib/filter_bar/save_row.test.js b/spec/javascript/lib/filter_bar/save_row.test.jsnew file mode 100644index 0000000..89ad835--- /dev/null+++ b/spec/javascript/lib/filter_bar/save_row.test.js@@ -0,0 +1,40 @@+// What: the naming form of the save row (lib/filter_bar/save_row.js).+// Type: node:test unit spec.+// Why: a list of the whole organisation ("Alle Meetings") has no project. Its+// form must not post an empty project_id: the server reads a present+// project_id as "this project", and the new view belongs to no project.+import { test } from "node:test"+import assert from "node:assert/strict"++// The HTML encoder allocates a div on import; the CSRF token is read from a meta tag.+globalThis.document = {+ querySelector: () => null,+ createElement: () => {+ let text = ""+ return {+ set textContent(v) { text = String(v) },+ get innerHTML() { return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") }+ }+ }+}+globalThis.window = { location: { search: "" } }++const { buildNamingRowHtml } = await import("../../../../app/javascript/lib/filter_bar/save_row.js")++const build = (projectId) => buildNamingRowHtml({+ saveUrl: "/org/1/smart_folders/create_from_filters",+ projectId,+ filters: { participant: ["anna"] },+ operators: {},+ suggestion: "Anna"+})++test("a list of one project posts its project_id", () => {+ assert.match(build("p-1"), /<input type="hidden" name="project_id" value="p-1">/)+})++test("a list without a project posts no project_id at all", () => {+ for (const projectId of ["", null, undefined]) {+ assert.doesNotMatch(build(projectId), /name="project_id"/)+ }+})