Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5440'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 30, 2024
2 parents e0f3030 + df1c592 commit 7565f5a
Show file tree
Hide file tree
Showing 19 changed files with 440 additions and 371 deletions.
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ FactoryBot/ExcessiveCreateList:
- 'test/controllers/notes_controller_test.rb'
- 'test/controllers/traces_controller_test.rb'
- 'test/controllers/user_blocks_controller_test.rb'
- 'test/controllers/users/issued_blocks_controller_test.rb'
- 'test/controllers/users/received_blocks_controller_test.rb'
- 'test/system/users_test.rb'

# Offense count: 635
Expand Down
4 changes: 2 additions & 2 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(user)
can [:create, :destroy], :session
can [:read, :data, :georss], Trace
can [:read, :terms, :create, :save, :suspended, :auth_success, :auth_failure], User
can [:read, :blocks_on, :blocks_by], UserBlock
can :read, UserBlock
end

if user&.active?
Expand Down Expand Up @@ -56,7 +56,7 @@ def initialize(user)
can [:read, :resolve, :ignore, :reopen], Issue
can :create, IssueComment
can [:create, :update, :destroy], Redaction
can [:create, :revoke_all], UserBlock
can [:create, :destroy], UserBlock
can :update, UserBlock, :creator => user
can :update, UserBlock, :revoker => user
can :update, UserBlock, :active? => true
Expand Down
44 changes: 2 additions & 42 deletions app/controllers/user_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class UserBlocksController < ApplicationController

authorize_resource

before_action :lookup_user, :only => [:new, :create, :revoke_all, :blocks_on, :blocks_by]
before_action :lookup_user, :only => [:new, :create]
before_action :lookup_user_block, :only => [:show, :edit, :update]
before_action :require_valid_params, :only => [:create, :update]
before_action :check_database_readable
before_action :check_database_writable, :only => [:create, :update, :revoke_all]
before_action :check_database_writable, :only => [:create, :update]

def index
@params = params.permit
Expand Down Expand Up @@ -105,46 +105,6 @@ def update
end
end

##
# revokes all active blocks
def revoke_all
if request.post? && params[:confirm]
@user.blocks.active.each { |block| block.revoke!(current_user) }
flash[:notice] = t ".flash"
redirect_to user_blocks_on_path(@user)
end
end

##
# shows a list of all the blocks on the given user
def blocks_on
@params = params.permit(:display_name)

user_blocks = UserBlock.where(:user => @user)

@user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker])

@show_user_name = false
@show_creator_name = true

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

##
# shows a list of all the blocks by the given user.
def blocks_by
@params = params.permit(:display_name)

user_blocks = UserBlock.where(:creator => @user)

@user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker])

@show_user_name = true
@show_creator_name = false

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

private

##
Expand Down
31 changes: 31 additions & 0 deletions app/controllers/users/issued_blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Users
class IssuedBlocksController < ApplicationController
include UserMethods
include PaginationMethods

layout "site"

before_action :authorize_web
before_action :set_locale

authorize_resource :class => UserBlock

before_action :lookup_user
before_action :check_database_readable

##
# shows a list of all the blocks by the given user.
def show
@params = params.permit(:user_display_name)

user_blocks = UserBlock.where(:creator => @user)

@user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker])

@show_user_name = true
@show_creator_name = false

render :partial => "user_blocks/page" if turbo_frame_request_id == "pagination"
end
end
end
48 changes: 48 additions & 0 deletions app/controllers/users/received_blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Users
class ReceivedBlocksController < ApplicationController
include UserMethods
include PaginationMethods

layout "site"

before_action :authorize_web
before_action :set_locale

authorize_resource :class => UserBlock

before_action :lookup_user
before_action :check_database_readable
before_action :check_database_writable, :only => :destroy

##
# shows a list of all the blocks on the given user
def show
@params = params.permit(:user_display_name)

user_blocks = UserBlock.where(:user => @user)

@user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker])

@show_user_name = false
@show_creator_name = true

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

##
# shows revoke all active blocks page
def edit; end

##
# revokes all active blocks
def destroy
if params[:confirm]
@user.blocks.active.each { |block| block.revoke!(current_user) }
flash[:notice] = t ".flash"
redirect_to user_received_blocks_path(@user)
else
render :action => :edit
end
end
end
end
16 changes: 8 additions & 8 deletions app/views/user_blocks/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
<% if current_user&.blocks&.exists? %>
<li class="nav-item">
<%= link_to t(".blocks_on_me"),
user_blocks_on_path(current_user),
:class => ["nav-link", { :active => action_name == "blocks_on" && current_user == @user }] %>
user_received_blocks_path(current_user),
:class => ["nav-link", { :active => controller_name == "received_blocks" && current_user == @user }] %>
</li>
<% end %>
<% on_user = @user || @user_block&.user %>
<% if on_user != current_user && on_user&.blocks&.exists? %>
<li class="nav-item">
<%= link_to t(".blocks_on_user_html", :user => tag.span(on_user.display_name, :class => "username text-truncate d-inline-block align-bottom", :dir => "auto")),
user_blocks_on_path(on_user),
:class => ["nav-link", { :active => action_name == "blocks_on" }] %>
user_received_blocks_path(on_user),
:class => ["nav-link", { :active => controller_name == "received_blocks" }] %>
</li>
<% end %>
<% if current_user&.blocks_created&.exists? %>
<li class="nav-item">
<%= link_to t(".blocks_by_me"),
user_blocks_by_path(current_user),
:class => ["nav-link", { :active => action_name == "blocks_by" && current_user == @user }] %>
user_issued_blocks_path(current_user),
:class => ["nav-link", { :active => controller_name == "issued_blocks" && current_user == @user }] %>
</li>
<% end %>
<% by_user = @user || @user_block&.creator %>
<% if by_user != current_user && by_user&.blocks_created&.exists? %>
<li class="nav-item">
<%= link_to t(".blocks_by_user_html", :user => tag.span(by_user.display_name, :class => "username text-truncate d-inline-block align-bottom", :dir => "auto")),
user_blocks_by_path(by_user),
:class => ["nav-link", { :active => action_name == "blocks_by" }] %>
user_issued_blocks_path(by_user),
:class => ["nav-link", { :active => controller_name == "issued_blocks" }] %>
</li>
<% end %>
<% if @user_block&.persisted? %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/user_blocks/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
<th></th>
</tr>
</thead>
<%= render :partial => "block", :collection => @user_blocks %>
<%= render :partial => "user_blocks/block", :collection => @user_blocks %>
</table>

<%= render "shared/pagination",
:translation_scope => "shared.pagination.user_blocks",
:newer_id => @newer_user_blocks_id,
:older_id => @older_user_blocks_id %>
</turbo-frame>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<% content_for :heading_class, "pb-0" %>
<% content_for :heading do %>
<h1><%= t(".heading_html", :name => link_to(@user.display_name, @user)) %></h1>
<%= render :partial => "navigation" %>
<%= render :partial => "user_blocks/navigation" %>
<% end %>

<% unless @user_blocks.empty? %>
<%= render :partial => "page" %>
<%= render :partial => "user_blocks/page" %>
<% else %>
<p><%= t ".empty", :name => @user.display_name %></p>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<% unless @user.blocks.active.empty? %>

<%= bootstrap_form_for :revoke_all, :url => { :action => "revoke_all" } do |f| %>
<%= bootstrap_form_for :revoke_all, :url => { :action => :destroy }, :method => :delete do |f| %>
<div class="mb-3">
<div class="form-check">
<%= check_box_tag "confirm", "yes", false, { :class => "form-check-input" } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<% content_for :heading_class, "pb-0" %>
<% content_for :heading do %>
<h1><%= t(".heading_html", :name => link_to(@user.display_name, @user)) %></h1>
<%= render :partial => "navigation" %>
<%= render :partial => "user_blocks/navigation" %>
<% end %>

<% unless @user_blocks.empty? %>
<%= render :partial => "page" %>
<%= render :partial => "user_blocks/page" %>
<% else %>
<p><%= t ".empty", :name => @user.display_name %></p>
<% end %>
12 changes: 6 additions & 6 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

<% if current_user.blocks.exists? %>
<li>
<%= link_to t(".blocks on me"), user_blocks_on_path(current_user) %>
<%= link_to t(".blocks on me"), user_received_blocks_path(current_user) %>
<span class='badge count-number'><%= number_with_delimiter(current_user.blocks.active.size) %></span>
</li>
<% end %>

<% if can?(:create, UserBlock) and current_user.blocks_created.exists? %>
<li>
<%= link_to t(".blocks by me"), user_blocks_by_path(current_user) %>
<%= link_to t(".blocks by me"), user_issued_blocks_path(current_user) %>
<span class='badge count-number'><%= number_with_delimiter(current_user.blocks_created.active.size) %></span>
</li>
<% end %>
Expand Down Expand Up @@ -93,21 +93,21 @@

<% if @user.blocks.exists? %>
<li>
<%= link_to t(".block_history"), user_blocks_on_path(@user) %>
<%= link_to t(".block_history"), user_received_blocks_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.blocks.active.size) %></span>
</li>
<% end %>

<% if @user.moderator? and @user.blocks_created.exists? %>
<li>
<%= link_to t(".moderator_history"), user_blocks_by_path(@user) %>
<%= link_to t(".moderator_history"), user_issued_blocks_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.blocks_created.active.size) %></span>
</li>
<% end %>

<% if can?(:revoke_all, UserBlock) and @user.blocks.active.exists? %>
<% if can?(:destroy, UserBlock) and @user.blocks.active.exists? %>
<li>
<%= link_to t(".revoke_all_blocks"), revoke_all_user_blocks_path(@user) %>
<%= link_to t(".revoke_all_blocks"), edit_user_received_blocks_path(@user) %>
</li>
<% end %>

Expand Down
39 changes: 21 additions & 18 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,27 @@ en:
report: Report this User
go_public:
flash success: "All your edits are now public, and you are now allowed to edit."
issued_blocks:
show:
title: "Blocks by %{name}"
heading_html: "List of Blocks by %{name}"
empty: "%{name} has not made any blocks yet."
received_blocks:
show:
title: "Blocks on %{name}"
heading_html: "List of Blocks on %{name}"
empty: "%{name} has not been blocked yet."
edit:
title: "Revoking all blocks on %{block_on}"
heading_html: "Revoking all blocks on %{block_on}"
empty: "%{name} has no active blocks."
confirm: "Are you sure you wish to revoke %{active_blocks}?"
active_blocks:
one: "%{count} active block"
other: "%{count} active blocks"
revoke: "Revoke!"
destroy:
flash: "All active blocks have been revoked."
lists:
show:
title: Users
Expand Down Expand Up @@ -2926,16 +2947,6 @@ en:
title: "User blocks"
heading: "List of user blocks"
empty: "No blocks have been made yet."
revoke_all:
title: "Revoking all blocks on %{block_on}"
heading_html: "Revoking all blocks on %{block_on}"
empty: "%{name} has no active blocks."
confirm: "Are you sure you wish to revoke %{active_blocks}?"
active_blocks:
one: "%{count} active block"
other: "%{count} active blocks"
revoke: "Revoke!"
flash: "All active blocks have been revoked."
helper:
time_future_html: "Ends in %{time}."
until_login: "Active until the user logs in."
Expand Down Expand Up @@ -2966,14 +2977,6 @@ en:
read_html: "read at %{time}"
time_in_future_title: "%{time_absolute}; in %{time_relative}"
time_in_past_title: "%{time_absolute}; %{time_relative}"
blocks_on:
title: "Blocks on %{name}"
heading_html: "List of Blocks on %{name}"
empty: "%{name} has not been blocked yet."
blocks_by:
title: "Blocks by %{name}"
heading_html: "List of Blocks by %{name}"
empty: "%{name} has not made any blocks yet."
show:
title: "%{block_on} blocked by %{block_by}"
heading_html: "%{block_on} blocked by %{block_by}"
Expand Down
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
# user pages
resources :users, :path => "user", :param => :display_name, :only => [:show, :destroy] do
resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy]
scope :module => :users do
resource :issued_blocks, :path => "blocks_by", :only => :show
resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy]
end
end
get "/user/:display_name/account", :to => redirect(:path => "/account/edit")
post "/user/:display_name/set_status" => "users#set_status", :as => :set_status_user
Expand Down Expand Up @@ -330,11 +334,7 @@
resources :user_mutes, :only => [:index]

# banning pages
get "/user/:display_name/blocks" => "user_blocks#blocks_on", :as => "user_blocks_on"
get "/user/:display_name/blocks_by" => "user_blocks#blocks_by", :as => "user_blocks_by"
get "/blocks/new/:display_name" => "user_blocks#new", :as => "new_user_block"
resources :user_blocks, :except => :new
match "/user/:display_name/blocks/revoke_all" => "user_blocks#revoke_all", :via => [:get, :post], :as => "revoke_all_user_blocks"
resources :user_blocks, :path_names => { :new => "new/:display_name" }

# issues and reports
resources :issues do
Expand Down
Loading

0 comments on commit 7565f5a

Please sign in to comment.