added login filter; fixed status filter

pull/5129/head
Markus Kahl 8 years ago committed by Oliver Günther
parent b2fc1d1ee9
commit 7ba5b261a6
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 1
      app/models/queries/users.rb
  2. 38
      app/models/queries/users/filters/login_filter.rb
  3. 13
      app/models/queries/users/filters/status_filter.rb
  4. 1
      doc/apiv3/endpoints/users.apib
  5. 6
      spec/models/queries/users/filters/status_filter_spec.rb
  6. 2
      spec/models/queries/users/user_query_spec.rb
  7. 90
      spec/requests/api/v3/user/filters_spec.rb

@ -31,6 +31,7 @@ module Queries::Users
Queries::Register.filter Queries::Users::UserQuery, Queries::Users::Filters::NameFilter
Queries::Register.filter Queries::Users::UserQuery, Queries::Users::Filters::GroupFilter
Queries::Register.filter Queries::Users::UserQuery, Queries::Users::Filters::StatusFilter
Queries::Register.filter Queries::Users::UserQuery, Queries::Users::Filters::LoginFilter
Queries::Register.order Queries::Users::UserQuery, Queries::Users::Orders::DefaultOrder
Queries::Register.order Queries::Users::UserQuery, Queries::Users::Orders::NameOrder

@ -0,0 +1,38 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 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-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 doc/COPYRIGHT.rdoc for more details.
#++
class Queries::Users::Filters::LoginFilter < Queries::Users::Filters::UserFilter
def type
:string
end
def self.key
:login
end
end

@ -41,4 +41,17 @@ class Queries::Users::Filters::StatusFilter < Queries::Users::Filters::UserFilte
def self.key
:status
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

@ -409,6 +409,7 @@ Lists users. Only administrators have permission to do this.
+ status: Status the user has
+ group: Name of the group in which to-be-listed users are members.
+ name: Filter users in whose first or last names, or email addresses the given string occurs.
+ login: User's login
+ sortBy (optional, string, `[["status", "asc"]]`) ... JSON specifying sort criteria.
Accepts the same format as returned by the [queries](#queries) endpoint.

@ -44,10 +44,4 @@ describe Queries::Users::Filters::StatusFilter, type: :model do
end
end
end
it_behaves_like 'list query filter' do
let(:attribute) { :status }
let(:model) { User }
let(:valid_values) { [Principal::STATUSES.keys.first] }
end
end

@ -78,7 +78,7 @@ describe Queries::Users::UserQuery, type: :model do
describe '#results' do
it 'is the same as handwriting the query' do
expected = base_scope.merge(User.where(["users.status IN (?)", "active"]))
expected = base_scope.merge(User.where(["users.status IN (?)", "1"]))
expect(instance.results.to_sql).to eql expected.to_sql
end

@ -0,0 +1,90 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 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-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 doc/COPYRIGHT.rdoc for more details.
require 'spec_helper'
describe 'GET /api/v3/users', type: :request do
let!(:users) do
[
FactoryGirl.create(:admin, login: 'admin', status: Principal::STATUSES[:active]),
FactoryGirl.create(:user, login: 'h.wurst', status: Principal::STATUSES[:active]),
FactoryGirl.create(:user, login: 'h.heine', status: Principal::STATUSES[:locked]),
FactoryGirl.create(:user, login: 'm.mario', status: Principal::STATUSES[:active])
]
end
before do
login_as users.first
end
def filter_users(name, operator, values)
filter = {
name => {
"operator" => operator,
"values" => Array(values)
}
}
params = {
filters: [filter].to_json
}
get "/api/v3/users", params: params
json = JSON.parse response.body
Array(Hash(json).dig("_embedded", "elements")).map { |e| e["login"] }
end
describe 'status filter' do
it '=' do
expect(filter_users("status", "=", :active)).to eq ["admin", "h.wurst", "m.mario"]
end
it '!' do
expect(filter_users("status", "!", :active)).to eq ["h.heine"]
end
end
describe 'login filter' do
it '=' do
expect(filter_users("login", "=", "admin")).to eq ["admin"]
end
it '!' do
expect(filter_users("login", "!", "admin")).to eq ["h.wurst", "h.heine", "m.mario"]
end
it '~' do
expect(filter_users("login", "~", "h.")).to eq ["h.wurst", "h.heine"]
end
it '!~' do
expect(filter_users("login", "!~", "h.")).to eq ["admin", "m.mario"]
end
end
end
Loading…
Cancel
Save