From 9fff6ae92789893936f76880a575f80777af5564 Mon Sep 17 00:00:00 2001 From: Peter Bhat Harkins Date: Tue, 29 Aug 2023 07:45:28 -0500 Subject: [PATCH] enable mod_userdir diff of `rails routes`: 12,13d11 < GET /newest/:user(.:format) home#newest_by_user < GET /newest/:user/page/:page(.:format) home#newest_by_user 32d29 < user_threads GET /threads/:user(.:format) comments#user_threads 120,122c117,132 < u GET /u(.:format) users#tree < user GET /u/:username(.:format) users#show < user_standing GET /u/:username/standing(.:format) users#standing --- > users_tree GET /users(.:format) users#tree > user GET /~:username(.:format) users#show > user_standing GET /~:username/standing(.:format) users#standing > GET /~:user/stories(/page/:page)(.:format) home#newest_by_user > user_threads GET /~:user/threads(.:format) comments#user_threads > user_ban POST /~:username/ban(.:format) users#ban > user_unban POST /~:username/unban(.:format) users#unban > user_disable_invite POST /~:username/disable_invitation(.:format) users#disable_invitation > user_enable_invite POST /~:username/enable_invitation(.:format) users#enable_invitation > u GET /u(.:format) redirect(302, /users) > GET /u/:username(.:format) redirect(302, /~%{username}) > GET /@:username(.:format) redirect(302, /~%{username}) > GET /u/:username/standing(.:format) redirect(302, ~%{username}/standing) > GET /newest/:user(.:format) redirect(302, ~%{user}/stories) > GET /newest/:user(/page/:page)(.:format) redirect(302, ~%{user}/stories/page/%{page}) > GET /threads/:user(.:format) redirect(302, ~%{user}/threads) 125,128d134 < user_ban POST /users/:username/ban(.:format) users#ban < user_unban POST /users/:username/unban(.:format) users#unban < user_disable_invite POST /users/:username/disable_invitation(.:format) users#disable_invitation < user_enable_invite POST /users/:username/enable_invitation(.:format) users#enable_invitation --- app/assets/stylesheets/application.css.erb | 2 +- app/controllers/keybase_proofs_controller.rb | 4 +- app/helpers/users_helper.rb | 29 +++++++++ app/models/comment.rb | 14 ----- app/models/story.rb | 13 ---- app/views/about/about.html.erb | 10 +-- app/views/about/chat.html.erb | 8 +-- app/views/comments/_comment.html.erb | 7 +-- app/views/comments/_threads.html.erb | 7 +-- app/views/hats/index.html.erb | 3 +- app/views/hats/requests_index.html.erb | 2 +- app/views/invitations/build.html.erb | 2 +- app/views/login/index.html.erb | 2 +- app/views/messages/index.html.erb | 6 +- app/views/messages/show.html.erb | 7 +-- app/views/moderations/_table.html.erb | 3 +- app/views/settings/index.html.erb | 4 +- app/views/signup/index.html.erb | 4 +- app/views/signup/invited.html.erb | 3 +- app/views/stories/_listdetail.html.erb | 16 ++--- app/views/stories/_similar.html.erb | 2 +- app/views/users/_invitationform.html.erb | 8 +-- app/views/users/list.html.erb | 16 +---- app/views/users/show.html.erb | 9 ++- app/views/users/tree.html.erb | 24 +++---- config/routes.rb | 35 +++++++---- extras/markdowner.rb | 2 +- spec/models/markdowner_spec.rb | 6 +- spec/requests/users_controller_spec.rb | 10 +-- spec/routing/user_spec.rb | 66 ++++++++++++++++++++ 30 files changed, 181 insertions(+), 143 deletions(-) create mode 100644 spec/routing/user_spec.rb diff --git a/app/assets/stylesheets/application.css.erb b/app/assets/stylesheets/application.css.erb index b12f9c04..309d3e38 100644 --- a/app/assets/stylesheets/application.css.erb +++ b/app/assets/stylesheets/application.css.erb @@ -1246,7 +1246,7 @@ ul.user_tree { color: var(--color-fg-contrast-4-5); } -/* /u/:username/standing */ +/* /~:username/standing */ /* https://codepen.io/sosuke/pen/Pjoqqp */ .unwarned { filter: invert(36%) sepia(52%) saturate(0%) hue-rotate(292deg) brightness(96%) contrast(85%); diff --git a/app/controllers/keybase_proofs_controller.rb b/app/controllers/keybase_proofs_controller.rb index d9d743b0..23d0f725 100644 --- a/app/controllers/keybase_proofs_controller.rb +++ b/app/controllers/keybase_proofs_controller.rb @@ -44,8 +44,8 @@ class KeybaseProofsController < ApplicationController @contacts = ["admin@#{Keybase.DOMAIN}"] @prefill_url = "#{new_keybase_proof_url}?kb_username=%{kb_username}&" \ "kb_signature=%{sig_hash}&kb_ua=%{kb_ua}&username=%{username}" - @profile_url = "#{u_url}/%{username}" - @check_url = "#{u_url}/%{username}.json" + @profile_url = "/~%{username}" + @check_url = "/~%{username}.json" @logo_black = "https://lobste.rs/small-black-logo.svg" @logo_full = "https://lobste.rs/full-color.logo.svg" @user_re = User.username_regex_s[1...-1] diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 34dba763..542a0d50 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -30,6 +30,35 @@ module UsersHelper end end + def styled_user_link user, content = nil, css_classes = [] + if content.is_a?(Story) && content.user_is_author? + css_classes.push 'user_is_author' + end + if content.is_a?(Comment) && content.story && + content.story.user_is_author? && content.story.user_id == user.id + css_classes.push 'user_is_author' + end + + if !user.is_active? + css_classes.push 'inactive_user' + end + if user.is_new? + css_classes.push 'new_user' + end + + link_to(user.username, user, class: css_classes) + end + + def user_karma(user) + if user.is_admin? + "(administrator)" + elsif user.is_moderator? + "(moderator" + else + "(#{user.karma})" + end + end + private def user_is_moderator? diff --git a/app/models/comment.rb b/app/models/comment.rb index 6092b843..2aa869fc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -353,20 +353,6 @@ class Comment < ApplicationRecord self.updated_at && (self.updated_at - self.created_at > 1.minute) end - def html_class_for_user - c = [] - if !self.user.is_active? - c.push "inactive_user" - elsif self.user.is_new? - c.push "new_user" - elsif self.story && self.story.user_is_author? && - self.story.user_id == self.user_id - c.push "user_is_author" - end - - c.join("") - end - def is_deletable_by_user?(user) if user && user.is_moderator? return true diff --git a/app/models/story.rb b/app/models/story.rb index 648809cc..a052e58f 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -478,19 +478,6 @@ class Story < ApplicationRecord @hider_count ||= HiddenStory.where(:story_id => self.id).count end - def html_class_for_user - c = [] - if !self.user.is_active? - c.push "inactive_user" - elsif self.user.is_new? - c.push "new_user" - elsif self.user_is_author? - c.push "user_is_author" - end - - c.join("") - end - def is_flaggable? if self.created_at && self.score > FLAGGABLE_MIN_SCORE Time.current - self.created_at <= FLAGGABLE_DAYS.days diff --git a/app/views/about/about.html.erb b/app/views/about/about.html.erb index 6c1edc6b..00183cea 100644 --- a/app/views/about/about.html.erb +++ b/app/views/about/about.html.erb @@ -7,8 +7,8 @@

Lobsters is a computing-focused community centered around link aggregation and discussion, launched on July 3rd, 2012. - The administrator is Peter Bhat Harkins ("pushcx"), contact him with any support issues. - Lobsters was created by joshua stein + The administrator is Peter Bhat Harkins ("pushcx"), contact him with any support issues. + Lobsters was created by joshua stein with careful design touches to encourage a healthy community:

@@ -87,7 +87,7 @@

Invitation Tree

- The full user tree is public and each user's profile + The full <%= link_to 'user tree', users_tree_path %> is public and each user's profile shows who invited them. This provides some degree of accountability and helps identify voting rings.

@@ -113,7 +113,7 @@

- The quickest way to receive an invitation is to talk to someone you recognize from the site. + The quickest way to receive an invitation is to talk to someone you <%= link_to 'recognize from the site', users_tree_path %>. If you wrote a link that was posted, please reach out in chat, we'd love to have you join the discussion. Finally, if you can't find anyone you know in the invitation tree and didn't author something posted to the site, <% if Rails.application.allow_invitation_requests? %> @@ -176,7 +176,7 @@

Transparency Policy

All moderator actions on this site are visible to - everyone and the identities of those moderators are public. + everyone and the identities of those moderators are <%= link_to 'public', moderators_path %>. While the individual actions of a moderator may cause debate, there should be no question about if an action happened or who is responsible.

diff --git a/app/views/about/chat.html.erb b/app/views/about/chat.html.erb index 45be4e28..19316730 100644 --- a/app/views/about/chat.html.erb +++ b/app/views/about/chat.html.erb @@ -9,11 +9,11 @@ in #lobsters. This channel was originally created by - @kristof on freenode, and + @kristof on freenode, and stayed with the network on 2021-05-19 after that domain was lost. - @pushcx, - @355e3b (c355e3b on IRC), and - @aleph (Church on IRC) are channel operators. + @pushcx, + @355e3b (c355e3b on IRC), and + @aleph (Church on IRC) are channel operators.

diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index c43ab1a3..039b654a 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -49,13 +49,10 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% end %> <% if (@user && @user.show_avatars?) || !@user %> - <%= - avatar_img(comment.user, 16) %> + <%= link_to avatar_img(comment.user, 16), comment.user %> <% end %> - <%= - comment.user.username %> + <%= styled_user_link comment.user, comment %> <% if comment.hat %> <%= comment.hat.to_html_label %> diff --git a/app/views/comments/_threads.html.erb b/app/views/comments/_threads.html.erb index 35725dd5..6e211b9e 100644 --- a/app/views/comments/_threads.html.erb +++ b/app/views/comments/_threads.html.erb @@ -81,13 +81,10 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% end %> <% if (@user && @user.show_avatars?) || !@user %> - <%= - avatar_img(comment.user, 16) %> + <%= link_to avatar_img(comment.user, 16), comment.user %> <% end %> - <%= - comment.user.username %> + <%= styled_user_link comment.user, comment %> <% if comment.hat %> <%= comment.hat.to_html_label %> diff --git a/app/views/hats/index.html.erb b/app/views/hats/index.html.erb index 5b38e3c6..1e886f55 100644 --- a/app/views/hats/index.html.erb +++ b/app/views/hats/index.html.erb @@ -21,8 +21,7 @@ <% @hat_groups.keys.sort_by{|a| a.downcase }.each do |hg| %> <% @hat_groups[hg].sort_by{|hh| hh.user.username.downcase }.each do |hh| %> - <%= hh.user.username - %> + <%= styled_user_link hh.user %> <%= hh.to_html_label %> <% if hh.link.to_s.match(/^http/) %> diff --git a/app/views/hats/requests_index.html.erb b/app/views/hats/requests_index.html.erb index 24f622f7..55f7b91e 100644 --- a/app/views/hats/requests_index.html.erb +++ b/app/views/hats/requests_index.html.erb @@ -11,7 +11,7 @@

<%= f.label :user_id, "User:", :class => "required" %> - <%= hr.user.username %> + <%= styled_user_link hr.user %> <%= time_ago_in_words(hr.created_at) %>
diff --git a/app/views/invitations/build.html.erb b/app/views/invitations/build.html.erb index 06558256..07859102 100644 --- a/app/views/invitations/build.html.erb +++ b/app/views/invitations/build.html.erb @@ -1,6 +1,6 @@

- If you don't know (or can't find) an existing user from + If you don't know (or can't find) an <%= link_to 'existing_user', users_tree_path %> from whom to request an invitation, you can make a public request for one. This will display your name and memo to all other logged-in users who can then send you an invitation if they recognize you. diff --git a/app/views/login/index.html.erb b/app/views/login/index.html.erb index e9686369..f7b18a5d 100644 --- a/app/views/login/index.html.erb +++ b/app/views/login/index.html.erb @@ -36,7 +36,7 @@

Not a user yet? Read about how invitations work and see if you know - a current user of the site. + <%= link_to 'a current user', users_tree_path %> of the site. The chat room does not require an invitation.

<% end %> diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb index 2c2467cd..55995e16 100644 --- a/app/views/messages/index.html.erb +++ b/app/views/messages/index.html.erb @@ -17,15 +17,13 @@
<% if @direction == :in %> <% if message.author %> - <%= - message.author.username %> + <%= styled_user_link message.author %> <% else %> <%= message.author_username %> <% end %> <%= message.hat.to_html_label if message.hat %> <% else %> - <%= - message.recipient.username %> + <%= styled_user_link message.recipient %> <% end %>
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index fbce1a82..29be9f7b 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -4,14 +4,13 @@

From <% if @message.author %> - <%= @message.author.username %> + <%= styled_user_link @message.author %> <% else %> <%= @message.author_username %> <% end %> <%= @message.hat.to_html_label if @message.hat %> to - <%= - @message.recipient.username %> + <%= styled_user_link @message.recipient %> <%= time_ago_in_words_label(@message.created_at) %>

@@ -57,6 +56,6 @@ <%= render partial: 'form', locals: { new_message: @new_message, replying: true } %> <% else %> - For help with this message, contact a moderator. + For help with this message, contact <%= link_to 'a moderator', moderators_path %>. <% end %>
diff --git a/app/views/moderations/_table.html.erb b/app/views/moderations/_table.html.erb index 0fcb5cd3..56e09c54 100644 --- a/app/views/moderations/_table.html.erb +++ b/app/views/moderations/_table.html.erb @@ -27,8 +27,7 @@ <%= link_to("Category: #{mod.category.category}", mod.category) %> <% elsif mod.user_id %> <% if mod.user %> - User - <%= mod.user.username %> + <%= link_to "User #{mod.user.username}", mod.user %> <% else %> User <%= mod.user_id %> (Deleted) <% end %> diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb index 6c465a8b..297dce2f 100644 --- a/app/views/settings/index.html.erb +++ b/app/views/settings/index.html.erb @@ -1,5 +1,5 @@ <% content_for :subnav do %> - Public Profile + <%= link_to 'Public Profile', @user %> Filtered Tags | <%= link_post 'Logout', logout_path, confirm: 'Are you sure you want to logout?' %> <% end %> @@ -311,7 +311,7 @@
  • Your comments with negative scores will be deleted, and you can check "disown comments" below if you want all of your stories and comments to change to list - inactive-user instead of your username. + inactive-user instead of your username.
  • diff --git a/app/views/signup/index.html.erb b/app/views/signup/index.html.erb index 911954df..36c0c1af 100644 --- a/app/views/signup/index.html.erb +++ b/app/views/signup/index.html.erb @@ -6,8 +6,8 @@ <% else %>

    Signup is currently by invitation only to combat spam and increase - accountability. If you know a current user of the site, - ask them for an invitation, or + accountability. If you know <%= link_to 'a current user', users_tree_path %> + of the site, ask them for an invitation, or <% if Rails.application.allow_invitation_requests? %> request one publicly. <% else %> diff --git a/app/views/signup/invited.html.erb b/app/views/signup/invited.html.erb index c6449f8a..0b1174e5 100644 --- a/app/views/signup/invited.html.erb +++ b/app/views/signup/invited.html.erb @@ -14,8 +14,7 @@

    <%= f.label :invitation, "Invited By:", :class => "required" %> - <%= - @invitation.user.username %> + <%= link_to @invitation.user.username, user_path(@invitation.user), target: '_blank' %>

    <% end %> diff --git a/app/views/stories/_listdetail.html.erb b/app/views/stories/_listdetail.html.erb index 19a9830b..f7ba0e9d 100644 --- a/app/views/stories/_listdetail.html.erb +++ b/app/views/stories/_listdetail.html.erb @@ -66,16 +66,14 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %> <% end %> <% if (@user && @user.show_avatars?) || !@user %> - <%= - avatar_img(ms.user, 16) %> + <%= link_to avatar_img(ms.user, 16), ms.user %> <% end %> <% if ms.user_is_author? %> authored by <% else %> via <% end %> - <%= ms.user.username %> + <%= styled_user_link ms.user, story, ['u-author', 'h-card'] %> <%= time_ago_in_words_label(ms.created_at) %> <% if ms.is_editable_by_user?(@user) %> @@ -98,8 +96,7 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>