From cd70187c2fa2a5058690fde78dcdcb1c759c204e Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 20 Sep 2022 03:16:05 +0000 Subject: Introduces a UserQuery model for admin/users (#37674). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: https://svn.redmine.org/redmine/trunk@21823 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/context_menus_controller.rb | 10 +++++ app/controllers/queries_controller.rb | 4 ++ app/controllers/users_controller.rb | 65 ++++++++++++++--------------- 3 files changed, 45 insertions(+), 34 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb index f4ecb9547..d5b34ca40 100644 --- a/app/controllers/context_menus_controller.rb +++ b/app/controllers/context_menus_controller.rb @@ -108,4 +108,14 @@ class ContextMenusController < ApplicationController end render layout: false end + + def users + @users = User.where(id: params[:ids]).to_a + + (render_404; return) unless @users.present? + if @users.size == 1 + @user = @users.first + end + render layout: false + end end diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index d2fc5efb9..6b34913bc 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -177,6 +177,10 @@ class QueriesController < ApplicationController end end + def redirect_to_user_query(options) + redirect_to users_path(options) + end + # Returns the Query subclass, IssueQuery by default # for compatibility with previous behaviour def query_class diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 566423704..5cd9eb931 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -34,49 +34,46 @@ class UsersController < ApplicationController helper :principal_memberships helper :activities include ActivitiesHelper + helper :queries + include QueriesHelper + helper :user_queries + include UserQueriesHelper require_sudo_mode :create, :update, :destroy def index - sort_init 'login', 'asc' - sort_update %w(login firstname lastname admin created_on last_login_on) + use_session = !request.format.csv? + retrieve_query(UserQuery, use_session) - case params[:format] - when 'xml', 'json' - @offset, @limit = api_offset_and_limit - else - @limit = per_page_option - end - - @status = params[:status] || 1 + if @query.valid? + scope = @query.results_scope - scope = User.logged.status(@status).preload(:email_address) - scope = scope.like(params[:name]) if params[:name].present? - scope = scope.in_group(params[:group_id]) if params[:group_id].present? + @user_count = scope.count - if params[:twofa].present? - case params[:twofa].to_i - when 1 - scope = scope.where.not(twofa_scheme: nil) - when 0 - scope = scope.where(twofa_scheme: nil) - end - end - - @user_count = scope.count - @user_pages = Paginator.new @user_count, @limit, params['page'] - @offset ||= @user_pages.offset - @users = scope.order(sort_clause).limit(@limit).offset(@offset).to_a - - respond_to do |format| - format.html do - @groups = Group.givable.sort - render :layout => !request.xhr? + respond_to do |format| + format.html do + @limit = per_page_option + @user_pages = Paginator.new @user_count, @limit, params['page'] + @offset ||= @user_pages.offset + @users = scope.limit(@limit).offset(@offset).to_a + render :layout => !request.xhr? + end + format.csv do + # Export all entries + @entries = scope.to_a + send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'users.csv') + end + format.api do + @offset, @limit = api_offset_and_limit + @users = scope.limit(@limit).offset(@offset).to_a + end end - format.csv do - send_data(users_to_csv(scope.order(sort_clause)), :type => 'text/csv; header=present', :filename => 'users.csv') + else + respond_to do |format| + format.html {render :layout => !request.xhr?} + format.csv {head :unprocessable_entity} + format.api {render_validation_errors(@query)} end - format.api end end -- cgit v1.2.3