Create changeset_comments resources for users

This commit is contained in:
Anton Khorev 2025-01-19 04:11:06 +03:00
parent 9fbe52dd21
commit 420d9da1f9
7 changed files with 91 additions and 1 deletions

View file

@ -0,0 +1,14 @@
module Users
class ChangesetCommentsController < CommentsController
def index
@title = t ".title", :user => @user.display_name
comments = ChangesetComment.where(:author => @user)
comments = comments.visible unless current_user&.moderator?
@params = params.permit(:display_name, :before, :after)
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:author])
end
end
end

View file

@ -25,6 +25,8 @@ class ChangesetComment < ApplicationRecord
belongs_to :changeset belongs_to :changeset
belongs_to :author, :class_name => "User" belongs_to :author, :class_name => "User"
scope :visible, -> { where(:visible => true) }
validates :id, :uniqueness => true, :presence => { :on => :update }, validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :only_integer => true } :numericality => { :on => :update, :only_integer => true }
validates :changeset, :associated => true validates :changeset, :associated => true

View file

@ -0,0 +1,22 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<table class="table table-striped" width="100%">
<thead>
<tr>
<th width="25%"><%= t ".changeset" %></th>
<th width="25%"><%= t ".when" %></th>
<th width="50%"><%= t ".comment" %></th>
</tr>
</thead>
<% @comments.each do |comment| -%>
<tr>
<td width="25%" class="<%= "text-muted" unless comment.visible? %>"><%= link_to comment.changeset.id, changeset_path(comment.changeset) %></td>
<td width="25%" class="<%= "text-muted" unless comment.visible? %>"><span title="<%= l comment.created_at, :format => :friendly %>"><%= time_ago_in_words(comment.created_at, :scope => :"datetime.distance_in_words_ago") %></span></td>
<td width="50%" class="richtext text-break<%= " text-muted" unless comment.visible? %>"><%= comment.body.to_html %></td>
</tr>
<% end -%>
</table>
<%= render "shared/pagination",
:newer_id => @newer_comments_id,
:older_id => @older_comments_id %>
</turbo-frame>

View file

@ -4,7 +4,10 @@
<h1><%= t ".heading_html", :user => link_to(@user.display_name, @user) %></h1> <h1><%= t ".heading_html", :user => link_to(@user.display_name, @user) %></h1>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active"><%= t ".diary_entries" %></a> <%= link_to t(".diary_entries"), user_diary_comments_path, :class => ["nav-link", { "active" => controller_name == "diary_comments" }] %>
</li>
<li class="nav-item">
<%= link_to t(".changesets"), user_changeset_comments_path, :class => ["nav-link", { "active" => controller_name == "changeset_comments" }] %>
</li> </li>
</ul> </ul>
<% end %> <% end %>

View file

@ -1939,6 +1939,9 @@ en:
preview: Preview preview: Preview
help: Help help: Help
pagination: pagination:
changeset_comments:
older: Older Comments
newer: Newer Comments
diary_comments: diary_comments:
older: Older Comments older: Older Comments
newer: Newer Comments newer: Newer Comments
@ -2875,8 +2878,16 @@ en:
comments: comments:
index: index:
heading_html: "%{user}'s Comments" heading_html: "%{user}'s Comments"
changesets: "Changesets"
diary_entries: "Diary entries" diary_entries: "Diary entries"
no_comments: "No comments" no_comments: "No comments"
changeset_comments:
index:
title: "Changeset Comments added by %{user}"
page:
changeset: Changeset
when: When
comment: Comment
diary_comments: diary_comments:
index: index:
title: "Diary Comments added by %{user}" title: "Diary Comments added by %{user}"

View file

@ -268,6 +268,7 @@ OpenStreetMap::Application.routes.draw do
resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy] resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy]
scope :module => :users do scope :module => :users do
resources :diary_comments, :only => :index resources :diary_comments, :only => :index
resources :changeset_comments, :only => :index
resource :issued_blocks, :path => "blocks_by", :only => :show resource :issued_blocks, :path => "blocks_by", :only => :show
resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy] resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy]
resource :status, :only => :update resource :status, :only => :update

View file

@ -0,0 +1,37 @@
require "test_helper"
module Users
class ChangesetCommentsControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
assert_routing(
{ :path => "/user/username/changeset_comments", :method => :get },
{ :controller => "users/changeset_comments", :action => "index", :user_display_name => "username" }
)
end
def test_index
user = create(:user)
other_user = create(:user)
changeset = create(:changeset, :closed)
create_list(:changeset_comment, 3, :changeset => changeset, :author => user)
create_list(:changeset_comment, 2, :changeset => changeset, :author => other_user)
get user_changeset_comments_path(user)
assert_response :success
assert_select "table.table-striped tbody" do
assert_select "tr", :count => 3
end
create(:changeset_comment, :changeset => changeset, :author => user)
create(:changeset_comment, :changeset => changeset, :author => user, :visible => false)
get user_changeset_comments_path(user)
assert_response :success
assert_select "table.table-striped tbody" do
assert_select "tr", :count => 4
end
end
end
end