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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
treat nil value as non false
ulfertsf8b28b300c82
diff --git a/app/models/queries/filters/strategies/boolean_list_strict.rb b/app/models/queries/filters/strategies/boolean_list_strict.rbnew file mode 100644index 00000000000..bbd3894a60a--- /dev/null+++ b/app/models/queries/filters/strategies/boolean_list_strict.rb@@ -0,0 +1,40 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Queries::Filters::Strategies+ class BooleanListStrict < BooleanList+ def operator_map+ super_value = super.dup+ super_value['='] = ::Queries::Operators::BooleanEqualsStrict++ super_value+ end+ end+enddiff --git a/app/models/queries/notifications/filters/read_ian_filter.rb b/app/models/queries/notifications/filters/read_ian_filter.rbindex 75649638a39..4749e940862 100644--- a/app/models/queries/notifications/filters/read_ian_filter.rb+++ b/app/models/queries/notifications/filters/read_ian_filter.rb@@ -34,4 +34,8 @@ class Queries::Notifications::Filters::ReadIanFilter < Queries::Notifications::Fdef self.key:read_ianend++ def type_strategy+ @type_strategy ||= ::Queries::Filters::Strategies::BooleanListStrict.new self+ endenddiff --git a/app/models/queries/operators/boolean_equals_strict.rb b/app/models/queries/operators/boolean_equals_strict.rbnew file mode 100644index 00000000000..00dbe690922--- /dev/null+++ b/app/models/queries/operators/boolean_equals_strict.rb@@ -0,0 +1,40 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Queries::Operators+ class BooleanEqualsStrict < Base+ label 'equals'+ set_symbol '='++ def self.sql_for_field(values, db_table, db_field)+ "#{db_table}.#{db_field} IN (#{values.map { |val| "'#{connection.quote_string(val)}'" }.join(',')})"+ end+ end+enddiff --git a/spec/models/queries/notifications/filters/read_ian_filter_spec.rb b/spec/models/queries/notifications/filters/read_ian_filter_spec.rbnew file mode 100644index 00000000000..20ab746d38d--- /dev/null+++ b/spec/models/queries/notifications/filters/read_ian_filter_spec.rb@@ -0,0 +1,46 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe Queries::Notifications::Filters::ReadIanFilter, type: :model do+ it_behaves_like 'basic query filter' do+ let(:type) { :list }+ let(:class_key) { :read_ian }++ describe '#available_operators' do+ it 'supports = and !' do+ expect(instance.available_operators)+ .to eql [Queries::Operators::BooleanEqualsStrict,+ Queries::Operators::BooleanNotEquals]+ end+ end++ it_behaves_like 'non ar filter'+ end+enddiff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rbindex fcdc4ade67b..f8f1c6d4364 100644--- a/spec/requests/api/v3/notifications/index_resource_spec.rb+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb@@ -32,7 +32,8 @@ require 'rack/test'describe ::API::V3::Notifications::NotificationsAPI,'index',- type: :request do+ type: :request,+ content_type: :json doinclude API::V3::Utilities::PathHelper@@ -40,16 +41,21 @@ describe ::API::V3::Notifications::NotificationsAPI,shared_let(:notification1) { FactoryBot.create :notification, recipient: recipient }shared_let(:notification2) { FactoryBot.create :notification, recipient: recipient }+ let(:notifications) { [notification1, notification2] }++ let(:filters) { nil }+let(:send_request) do- header "Content-Type", "application/json"- get api_v3_paths.notifications+ get api_v3_paths.path_for :notifications, filters: filtersendlet(:parsed_response) { JSON.parse(last_response.body) }-before do+ notifications+login_as current_user+send_requestend@@ -57,6 +63,30 @@ describe ::API::V3::Notifications::NotificationsAPI,let(:current_user) { recipient }it_behaves_like 'API V3 collection response', 2, 2, 'Notification'++ context 'with a readIAN filter' do+ let(:nil_notification) { FactoryBot.create :notification, recipient: recipient, read_ian: nil }++ let(:notifications) { [notification1, notification2, nil_notification] }++ let(:filters) do+ [+ {+ 'readIAN' => {+ 'operator' => '=',+ 'values' => ['f']++ }+ }+ ]+ end++ context 'with the filter being set to false' do+ it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do+ let(:elements) { [notification2, notification1] }+ end+ end+ endenddescribe 'admin user' do@@ -71,7 +101,7 @@ describe ::API::V3::Notifications::NotificationsAPI,it_behaves_like 'API V3 collection response', 0, 0, 'Notification'end- describe 'as any user' do+ describe 'as an anyonymous user' dolet(:current_user) { User.anonymous }it 'returns a 403 response' dodiff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rbindex 143debd7c59..fbae2e2a8b1 100644--- a/spec/requests/api/v3/support/api_v3_collection_response.rb+++ b/spec/requests/api/v3/support/api_v3_collection_response.rb@@ -30,6 +30,10 @@ require 'spec_helper'shared_examples_for 'API V3 collection response' do |total, count, type|subject { last_response.body }+ # If an array of elements is provided, those elements are expected+ # to be embedded in the _embedded/elements section in the order provided.+ # Only the id of the element is checked for.+ let(:elements) { nil }# Allow input to pass a proc to avoid counting before the example# context@@ -60,6 +64,10 @@ shared_examples_for 'API V3 collection response' do |total, count, type|if type && count_number > 0expect(subject).to be_json_eql(type.to_json).at_path('_embedded/elements/0/_type')end++ elements&.each_with_index do |element, index|+ expect(subject).to be_json_eql(element.id.to_json).at_path("_embedded/elements/#{index}/id")+ endendendend