fixes filtering members by group (#5800)
additionally fixes: * with "all" selected, all members are shown, not only those being active, invited or registered * with "locked" selected, locked users are now displayed. * the Project#members_principals associations lacked the `references` method which lead to the users table being undefined in the resulting query. In order to achive the bug fixes, the member filtering is now based on the query engine also used for users, queries, work_packages, ... As a lot of the members filters are very similar to user filters (in fact, a lot of the members filter work on the users model), those filters are shared via modules. [ci skip]pull/5809/head
parent
4551860fdc
commit
daa1a4d4b7
@ -0,0 +1,70 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Shared::GroupFilter |
||||
def self.included(base) |
||||
base.include(InstanceMethods) |
||||
base.extend(ClassMethods) |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def allowed_values |
||||
@allowed_values ||= begin |
||||
::Group.pluck(:id).map { |g| [g, g.to_s] } |
||||
end |
||||
end |
||||
|
||||
def available? |
||||
::Group.exists? |
||||
end |
||||
|
||||
def type |
||||
:list_optional |
||||
end |
||||
|
||||
def human_name |
||||
I18n.t('query_fields.member_of_group') |
||||
end |
||||
|
||||
def joins |
||||
:groups |
||||
end |
||||
|
||||
def where |
||||
operator_strategy.sql_for_field(values, 'groups_users', 'id') |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def key |
||||
:group |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,56 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Shared::ProjectFilter |
||||
def self.included(base) |
||||
base.include(InstanceMethods) |
||||
base.extend(ClassMethods) |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def type |
||||
:list_optional |
||||
end |
||||
|
||||
def type_strategy |
||||
# Instead of getting the IDs of all the projects a user is allowed |
||||
# to see we only check that the value is an integer. Non valid ids |
||||
# will then simply create an empty result but will not cause any |
||||
# harm. |
||||
@type_strategy ||= ::Queries::Filters::Strategies::IntegerListOptional.new(self) |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def key |
||||
:project_id |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,56 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Shared::UserBlockedFilter |
||||
def self.included(base) |
||||
base.include(InstanceMethods) |
||||
base.extend(ClassMethods) |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def allowed_values |
||||
[[I18n.t(:status_blocked), :blocked]] |
||||
end |
||||
|
||||
def type |
||||
:list |
||||
end |
||||
|
||||
def where |
||||
User.blocked_condition(operator == '=') |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def self.key |
||||
:blocked |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,89 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Shared::UserNameFilter |
||||
def self.included(base) |
||||
base.include(InstanceMethods) |
||||
base.extend(ClassMethods) |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def type |
||||
:string |
||||
end |
||||
|
||||
def self.key |
||||
:name |
||||
end |
||||
|
||||
def where |
||||
case operator |
||||
when '=' |
||||
["#{sql_concat_name} IN (?)", sql_value] |
||||
when '!' |
||||
["#{sql_concat_name} NOT IN (?)", sql_value] |
||||
when '~' |
||||
["#{sql_concat_name} LIKE ?", "%#{sql_value}%"] |
||||
when '!~' |
||||
["#{sql_concat_name} NOT LIKE ?", "%#{sql_value}%"] |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def sql_value |
||||
case operator |
||||
when '=', '!' |
||||
values.map { |val| self.class.connection.quote_string(val.downcase) }.join(',') |
||||
when '~', '!~' |
||||
values.first.downcase |
||||
end |
||||
end |
||||
|
||||
def sql_concat_name |
||||
case Setting.user_format |
||||
when :firstname_lastname, :lastname_coma_firstname |
||||
"LOWER(CONCAT(users.firstname, CONCAT(' ', users.lastname)))" |
||||
when :firstname |
||||
'LOWER(users.firstname)' |
||||
when :lastname_firstname |
||||
"LOWER(CONCAT(users.lastname, CONCAT(' ', users.firstname)))" |
||||
when :username |
||||
"LOWER(users.login)" |
||||
end |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def key |
||||
:name |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,67 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Shared::UserStatusFilter |
||||
def self.included(base) |
||||
base.include(InstanceMethods) |
||||
base.extend(ClassMethods) |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def allowed_values |
||||
Principal::STATUSES.keys.map do |key| |
||||
[I18n.t(:"status_#{key}"), key] |
||||
end |
||||
end |
||||
|
||||
def type |
||||
:list |
||||
end |
||||
|
||||
def status_values |
||||
values.map { |value| Principal::STATUSES[value.to_sym] } |
||||
end |
||||
|
||||
def where |
||||
case operator |
||||
when "=" |
||||
["users.status IN (?)", status_values.join(", ")] |
||||
when "!" |
||||
["users.status NOT IN (?)", status_values.join(", ")] |
||||
end |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def self.key |
||||
:status |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,41 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Members |
||||
query = Queries::Members::MemberQuery |
||||
filter_ns = Queries::Members::Filters |
||||
|
||||
Queries::Register.filter query, filter_ns::NameFilter |
||||
Queries::Register.filter query, filter_ns::ProjectFilter |
||||
Queries::Register.filter query, filter_ns::StatusFilter |
||||
Queries::Register.filter query, filter_ns::BlockedFilter |
||||
Queries::Register.filter query, filter_ns::GroupFilter |
||||
Queries::Register.filter query, filter_ns::RoleFilter |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::BlockedFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::UserBlockedFilter |
||||
|
||||
def joins |
||||
:principal |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::GroupFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::GroupFilter |
||||
|
||||
def joins |
||||
{ user: :groups } |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::MemberFilter < Queries::Filters::Base |
||||
self.model = Member |
||||
|
||||
def human_name |
||||
Member.human_attribute_name(name) |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::NameFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::UserNameFilter |
||||
|
||||
def joins |
||||
:principal |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::ProjectFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::ProjectFilter |
||||
end |
@ -0,0 +1,53 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::RoleFilter < Queries::Members::Filters::MemberFilter |
||||
def allowed_values |
||||
@allowed_values ||= begin |
||||
Role.pluck(:name, :id).map { |name, id| [name, id] } |
||||
end |
||||
end |
||||
|
||||
def type |
||||
:list_optional |
||||
end |
||||
|
||||
def self.key |
||||
:role_id |
||||
end |
||||
|
||||
def joins |
||||
:member_roles |
||||
end |
||||
|
||||
def where |
||||
operator_strategy.sql_for_field(values, 'member_roles', 'role_id') |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::Filters::StatusFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::UserStatusFilter |
||||
|
||||
def joins |
||||
:principal |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Members::MemberQuery < Queries::BaseQuery |
||||
def self.model |
||||
Member |
||||
end |
||||
|
||||
def default_scope |
||||
Member.all |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::Users::Filters::BlockedFilter < Queries::Members::Filters::MemberFilter |
||||
include Queries::Filters::Shared::UserBlockedFilter |
||||
end |
@ -0,0 +1,46 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::BlockedFilter, type: :model do |
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :blocked } |
||||
let(:type) { :list } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is a list of the possible values' do |
||||
expected = [[I18n.t(:status_blocked), :blocked]] |
||||
|
||||
expect(instance.allowed_values).to match_array(expected) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::GroupFilter, type: :model do |
||||
let(:group1) { FactoryGirl.build_stubbed(:group) } |
||||
let(:group2) { FactoryGirl.build_stubbed(:group) } |
||||
|
||||
before do |
||||
allow(Group) |
||||
.to receive(:pluck) |
||||
.with(:id) |
||||
.and_return([group1.id, group2.id]) |
||||
end |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :group } |
||||
let(:type) { :list_optional } |
||||
let(:name) { I18n.t('query_fields.member_of_group') } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is a list of the possible values' do |
||||
expected = [[group1.id, group1.id.to_s], [group2.id, group2.id.to_s]] |
||||
|
||||
expect(instance.allowed_values).to match_array(expected) |
||||
end |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'list_optional query filter' do |
||||
let(:attribute) { :id } |
||||
let(:model) { Member.joins(user: :groups) } |
||||
let(:valid_values) { [group1.id.to_s] } |
||||
let(:expected_table_name) { 'groups_users' } |
||||
end |
||||
end |
@ -0,0 +1,97 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::NameFilter, type: :model do |
||||
include_context 'filter tests' |
||||
let(:values) { ['A name'] } |
||||
let(:model) { Member.joins(:principal) } |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :name } |
||||
let(:type) { :string } |
||||
let(:model) { Member.joins(:principal) } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is nil' do |
||||
expect(instance.allowed_values).to be_nil |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#scope' do |
||||
before do |
||||
allow(Setting) |
||||
.to receive(:user_format) |
||||
.and_return(:firstname) |
||||
end |
||||
|
||||
context 'for "="' do |
||||
let(:operator) { '=' } |
||||
|
||||
it 'is the same as handwriting the query' do |
||||
expected = model.where("LOWER(users.firstname) IN ('#{values.first.downcase}')") |
||||
|
||||
expect(instance.scope.to_sql).to eql expected.to_sql |
||||
end |
||||
end |
||||
|
||||
context 'for "!"' do |
||||
let(:operator) { '!' } |
||||
|
||||
it 'is the same as handwriting the query' do |
||||
expected = model.where("LOWER(users.firstname) NOT IN ('#{values.first.downcase}')") |
||||
|
||||
expect(instance.scope.to_sql).to eql expected.to_sql |
||||
end |
||||
end |
||||
|
||||
context 'for "~"' do |
||||
let(:operator) { '~' } |
||||
|
||||
it 'is the same as handwriting the query' do |
||||
expected = model.where("LOWER(users.firstname) LIKE '%#{values.first.downcase}%'") |
||||
|
||||
expect(instance.scope.to_sql).to eql expected.to_sql |
||||
end |
||||
end |
||||
|
||||
context 'for "!~"' do |
||||
let(:operator) { '!~' } |
||||
|
||||
it 'is the same as handwriting the query' do |
||||
expected = model.where("LOWER(users.firstname) NOT LIKE '%#{values.first.downcase}%'") |
||||
|
||||
expect(instance.scope.to_sql).to eql expected.to_sql |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,44 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::ProjectFilter, type: :model do |
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :project_id } |
||||
let(:type) { :list_optional } |
||||
end |
||||
|
||||
it_behaves_like 'list_optional query filter' do |
||||
let(:attribute) { :project_id } |
||||
let(:model) { Member } |
||||
let(:valid_values) { ['1'] } |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::RoleFilter, type: :model do |
||||
let(:role1) { FactoryGirl.build_stubbed(:role) } |
||||
let(:role2) { FactoryGirl.build_stubbed(:role) } |
||||
|
||||
before do |
||||
allow(Role) |
||||
.to receive(:pluck) |
||||
.with(:name, :id) |
||||
.and_return([[role1.name, role1.id], [role2.name, role2.id]]) |
||||
end |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :role_id } |
||||
let(:type) { :list_optional } |
||||
let(:name) { Member.human_attribute_name(:role) } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is a list of the possible values' do |
||||
expected = [[role1.name, role1.id], [role2.name, role2.id]] |
||||
|
||||
expect(instance.allowed_values).to match_array(expected) |
||||
end |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'list_optional query filter' do |
||||
let(:attribute) { :role_id } |
||||
let(:model) { Member } |
||||
let(:joins) { :member_roles } |
||||
let(:valid_values) { [role1.id.to_s] } |
||||
end |
||||
end |
@ -0,0 +1,48 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Members::Filters::StatusFilter, type: :model do |
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :status } |
||||
let(:type) { :list } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is a list of the possible values' do |
||||
expected = Principal::STATUSES.keys.map do |key| |
||||
[I18n.t(:"status_#{key}"), key] |
||||
end |
||||
|
||||
expect(instance.allowed_values).to match_array(expected) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue