Skip to content

Commit

Permalink
Move admin users list to its own controller
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Dec 10, 2024
1 parent 7b05c1c commit 507c395
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Rails/ReflectionClassName:
Rails/SkipsModelValidations:
Exclude:
- 'db/migrate/*.rb'
- 'app/controllers/users_controller.rb'
- 'app/controllers/users/lists_controller.rb'

Style/Documentation:
Enabled: false
Expand Down
3 changes: 2 additions & 1 deletion app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def initialize(user)
can [:hide, :unhide], [DiaryEntry, DiaryComment]
can [:index, :show, :resolve, :ignore, :reopen], Issue
can :create, IssueComment
can [:set_status, :destroy, :index], User
can [:set_status, :destroy], User
can [:show, :update], :users_list
can [:create, :destroy], UserRole
end
end
Expand Down
41 changes: 41 additions & 0 deletions app/controllers/users/lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Users
class ListsController < ApplicationController
include PaginationMethods

layout "site"

before_action :authorize_web
before_action :set_locale
before_action :check_database_readable

authorize_resource :class => :users_list

##
# display a list of users matching specified criteria
def show
@params = params.permit(:status, :ip, :before, :after)

users = User.all
users = users.where(:status => @params[:status]) if @params[:status]
users = users.where(:creation_address => @params[:ip]) if @params[:ip]

@users_count = users.limit(501).count
@users_count = I18n.t("count.at_least_pattern", :count => 500) if @users_count > 500

@users, @newer_users_id, @older_users_id = get_page_items(users, :limit => 50)

render :partial => "page" if turbo_frame_request_id == "pagination"
end

##
# update status of selected users
def update
ids = params[:user].keys.collect(&:to_i)

User.where(:id => ids).update_all(:status => "confirmed") if params[:confirm]
User.where(:id => ids).update_all(:status => "deleted") if params[:hide]

redirect_to url_for(params.permit(:status, :ip, :before, :after))
end
end
end
27 changes: 0 additions & 27 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class UsersController < ApplicationController
include EmailMethods
include SessionMethods
include UserMethods
include PaginationMethods

layout "site"

Expand All @@ -21,32 +20,6 @@ class UsersController < ApplicationController
allow_thirdparty_images :only => :show
allow_social_login :only => :new

##
# display a list of users matching specified criteria
def index
if request.post?
ids = params[:user].keys.collect(&:to_i)

User.where(:id => ids).update_all(:status => "confirmed") if params[:confirm]
User.where(:id => ids).update_all(:status => "deleted") if params[:hide]

redirect_to url_for(:status => params[:status], :ip => params[:ip], :page => params[:page])
else
@params = params.permit(:status, :ip, :before, :after)

users = User.all
users = users.where(:status => @params[:status]) if @params[:status]
users = users.where(:creation_address => @params[:ip]) if @params[:ip]

@users_count = users.limit(501).count
@users_count = I18n.t("count.at_least_pattern", :count => 500) if @users_count > 500

@users, @newer_users_id, @older_users_id = get_page_items(users, :limit => 50)

render :partial => "page" if turbo_frame_request_id == "pagination"
end
end

def show
@user = User.find_by(:display_name => params[:display_name])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<%= form_tag do %>
<%= form_tag @params, :method => :put do %>
<div class="row">
<div class="col">
<%= render "shared/pagination",
:translation_scope => "shared.pagination.users",
:newer_id => @newer_users_id,
:older_id => @older_users_id %>
</div>
Expand All @@ -24,12 +25,13 @@
</td>
</tr>
</thead>
<%= render @users %>
<%= render :partial => "user", :collection => @users %>
</table>

<div class="row">
<div class="col">
<%= render "shared/pagination",
:translation_scope => "shared.pagination.users",
:newer_id => @newer_users_id,
:older_id => @older_users_id %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<td>
<p>
<% if user.creation_address %>
<%= t "users.index.summary_html",
<%= t ".summary_html",
:name => link_to(user.display_name, user),
:ip_address => link_to(user.creation_address, :ip => user.creation_address),
:date => l(user.created_at, :format => :friendly) %>
<% else %>
<%= t "users.index.summary_no_ip_html",
<%= t ".summary_no_ip_html",
:name => link_to(user.display_name, user),
:date => l(user.created_at, :format => :friendly) %>
<% end %>
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@
<dd class="list-inline-item"><%= @user.email %></dd>
<% unless @user.creation_address.nil? -%>
<dt class="list-inline-item m-0"><%= t ".created from" %></dt>
<dd class="list-inline-item"><%= link_to @user.creation_address, users_path(:ip => @user.creation_address) %></dd>
<dd class="list-inline-item"><%= link_to @user.creation_address, users_list_path(:ip => @user.creation_address) %></dd>
<% end -%>
<dt class="list-inline-item m-0"><%= t ".status" %></dt>
<dd class="list-inline-item"><%= link_to @user.status.capitalize, users_path(:status => @user.status) %></dd>
<dd class="list-inline-item"><%= link_to @user.status.capitalize, users_list_path(:status => @user.status) %></dd>
<dt class="list-inline-item m-0"><%= t ".spam score" %></dt>
<dd class="list-inline-item"><%= @user.spam_score %></dd>
</dl>
Expand Down
26 changes: 14 additions & 12 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2793,18 +2793,20 @@ en:
report: Report this User
go_public:
flash success: "All your edits are now public, and you are now allowed to edit."
index:
title: Users
heading: Users
summary_html: "%{name} created from %{ip_address} on %{date}"
summary_no_ip_html: "%{name} created on %{date}"
empty: No matching users found
page:
found_users:
one: "%{count} user found"
other: "%{count} users found"
confirm: Confirm Selected Users
hide: Hide Selected Users
lists:
show:
title: Users
heading: Users
empty: No matching users found
page:
found_users:
one: "%{count} user found"
other: "%{count} users found"
confirm: Confirm Selected Users
hide: Hide Selected Users
user:
summary_html: "%{name} created from %{ip_address} on %{date}"
summary_no_ip_html: "%{name} created on %{date}"
suspended:
title: Account Suspended
heading: Account Suspended
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@
match "/user/:display_name/remove_friend" => "friendships#remove_friend", :via => [:get, :post], :as => "remove_friend"

# user lists
match "/users" => "users#index", :via => [:get, :post]
match "/users/:status" => "users#index", :via => [:get, :post]
namespace :users do
resource :list, :path => "(:status)", :only => [:show, :update]
end

# geocoder
get "/search" => "geocoder#search"
Expand Down
Loading

0 comments on commit 507c395

Please sign in to comment.