Skip to content

Commit

Permalink
Move users list to administrator module
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Aug 22, 2024
1 parent ceb87bb commit d1a184d
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 263 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/administrator/users_controller.rb'

Style/Documentation:
Enabled: false
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/administrator/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Administrator
class UsersController < ApplicationController
include PaginationMethods

layout "site"

before_action :authorize_web
before_action :set_locale
before_action :check_database_readable

authorize_resource

##
# 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_ip => @params[:ip]) if @params[:ip]

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

render :partial => "page" if turbo_frame_request_id == "pagination"
end
end
end
end
25 changes: 0 additions & 25 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,30 +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_ip => @params[:ip]) if @params[:ip]

@users_count = users.count
@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
Expand Up @@ -3,8 +3,8 @@
<div class="row">
<div class="col">
<%= render "shared/pagination",
:newer_key => "users.page.newer",
:older_key => "users.page.older",
:newer_key => "administrator.users.page.newer",
:older_key => "administrator.users.page.older",
:newer_id => @newer_users_id,
:older_id => @older_users_id %>
</div>
Expand Down Expand Up @@ -32,8 +32,8 @@
<div class="row">
<div class="col">
<%= render "shared/pagination",
:newer_key => "users.page.newer",
:older_key => "users.page.older",
:newer_key => "administrator.users.page.newer",
:older_key => "administrator.users.page.older",
: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_ip %>
<%= t "users.index.summary_html",
<%= t ".summary_html",
:name => link_to(user.display_name, user),
:ip_address => link_to(user.creation_ip, :ip => user.creation_ip),
: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.
31 changes: 17 additions & 14 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2874,20 +2874,6 @@ 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:
older: "Older Users"
newer: "Newer Users"
found_users:
one: "%{count} user found"
other: "%{count} users found"
confirm: Confirm Selected Users
hide: Hide Selected Users
suspended:
title: Account Suspended
heading: Account Suspended
Expand Down Expand Up @@ -3109,6 +3095,23 @@ en:
anonymous_warning_sign_up: "sign up"
advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings."
add: Add Note
administrator:
users:
index:
title: Users
heading: Users
empty: No matching users found
page:
older: "Older Users"
newer: "Newer Users"
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}"
javascripts:
close: Close
share:
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@
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]
scope :module => :administrator do
match "users" => "users#index", :via => [:get, :post]
match "users/:status" => "users#index", :via => [:get, :post]
end

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

0 comments on commit d1a184d

Please sign in to comment.