users: add /profile page (fix #4151).

* Add /profile, /profile.json endpoints.
* Make "My Account" link to /profile.
* Add 'User ID' field to profile page.
This commit is contained in:
evazion
2019-09-01 14:08:55 -05:00
parent a932b25608
commit ff92b32f02
9 changed files with 51 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ module Maintenance
def create def create
CurrentUser.user.refresh_counts! CurrentUser.user.refresh_counts!
flash[:notice] = "Counts have been refreshed" flash[:notice] = "Counts have been refreshed"
redirect_to user_path(CurrentUser.id) redirect_to profile_path
end end
end end
end end

View File

@@ -36,10 +36,21 @@ class UsersController < ApplicationController
def show def show
@user = User.find(params[:id]) @user = User.find(params[:id])
@presenter = UserPresenter.new(@user)
respond_with(@user, methods: @user.full_attributes) respond_with(@user, methods: @user.full_attributes)
end end
def profile
@user = CurrentUser.user
if @user.is_member?
respond_with(@user, methods: @user.full_attributes, template: "users/show")
elsif request.format.html?
redirect_to new_session_path
else
raise ActiveRecord::RecordNotFound
end
end
def create def create
@user = User.new(user_params(:create)) @user = User.new(user_params(:create))
if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user) if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user)

View File

@@ -2,7 +2,7 @@
<% if CurrentUser.is_anonymous? %> <% if CurrentUser.is_anonymous? %>
<%= nav_link_to("Sign in", new_session_path) %> <%= nav_link_to("Sign in", new_session_path) %>
<% else %> <% else %>
<%= nav_link_to("My Account #{CurrentUser.dmail_count}", user_path(CurrentUser.user)) %> <%= nav_link_to("My Account #{CurrentUser.dmail_count}", profile_path) %>
<% end %> <% end %>
<%= nav_link_to("Posts", posts_path) %> <%= nav_link_to("Posts", posts_path) %>
<%= nav_link_to("Comments", comments_path(:group_by => "post")) %> <%= nav_link_to("Comments", comments_path(:group_by => "post")) %>

View File

@@ -119,7 +119,7 @@
<li><%= link_to "Sign in", new_session_path %></li> <li><%= link_to "Sign in", new_session_path %></li>
<li><%= link_to "Sign up", new_user_path %></li> <li><%= link_to "Sign up", new_user_path %></li>
<% else %> <% else %>
<li><%= link_to "Profile", CurrentUser.user %></li> <li><%= link_to "Profile", profile_path %></li>
<li><%= link_to "Settings", edit_user_path(CurrentUser.user) %></li> <li><%= link_to "Settings", edit_user_path(CurrentUser.user) %></li>
<% if CurrentUser.is_gold? %> <% if CurrentUser.is_gold? %>
<li><%= link_to "Change name", new_user_name_change_request_path %></li> <li><%= link_to "Change name", new_user_name_change_request_path %></li>

View File

@@ -12,7 +12,7 @@
<li>|</li> <li>|</li>
<% if @user.id == CurrentUser.user.id %> <% if @user.id == CurrentUser.user.id %>
<%= subnav_link_to "Settings", edit_user_path(CurrentUser.user) %> <%= subnav_link_to "Settings", edit_user_path(CurrentUser.user) %>
<%= subnav_link_to "Profile", user_path(CurrentUser.user) %> <%= subnav_link_to "Profile", profile_path %>
<%= subnav_link_to "Messages #{CurrentUser.user.dmail_count}", dmails_current_folder_path %> <%= subnav_link_to "Messages #{CurrentUser.user.dmail_count}", dmails_current_folder_path %>
<% if !@user.is_platinum? %> <% if !@user.is_platinum? %>

View File

@@ -2,6 +2,10 @@
<h2>Statistics</h2> <h2>Statistics</h2>
<table width="100%" class="user-statistics"> <table width="100%" class="user-statistics">
<tbody> <tbody>
<tr>
<th>User ID</th>
<td><%= user.id %></td>
</tr>
<tr> <tr>
<th>Join Date</th> <th>Join Date</th>
<td><%= presenter.join_date %></td> <td><%= presenter.join_date %></td>

View File

@@ -2,11 +2,11 @@
<div id="a-show"> <div id="a-show">
<h1><%= link_to_user @user %></h1> <h1><%= link_to_user @user %></h1>
<%= render "statistics", :presenter => @presenter, :user => @user %> <%= render "statistics", presenter: @user.presenter, user: @user %>
<% if !CurrentUser.is_admin? && !@user.enable_privacy_mode? || CurrentUser.id == @user.id %> <% if !CurrentUser.is_admin? && !@user.enable_privacy_mode? || CurrentUser.id == @user.id %>
<%= render "posts/partials/common/inline_blacklist" %> <%= render "posts/partials/common/inline_blacklist" %>
<%= render "post_summary", :presenter => @presenter, :user => @user %> <%= render "post_summary", presenter: @user.presenter, user: @user %>
<% end %> <% end %>
</div> </div>
</div> </div>
@@ -14,7 +14,7 @@
<%= render "secondary_links" %> <%= render "secondary_links" %>
<% content_for(:page_title) do %> <% content_for(:page_title) do %>
User - <%= @presenter.name %> - <%= Danbooru.config.app_name %> User - <%= @user.presenter.name %> - <%= Danbooru.config.app_name %>
<% end %> <% end %>
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }), title: "Comments on #{@user.name}'s uploads")) %> <% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }), title: "Comments on #{@user.name}'s uploads")) %>

View File

@@ -410,6 +410,7 @@ Rails.application.routes.draw do
get "/user/show/:id" => redirect("/users/%{id}") get "/user/show/:id" => redirect("/users/%{id}")
get "/user/login" => redirect("/sessions/new") get "/user/login" => redirect("/sessions/new")
get "/user_record" => redirect {|params, req| "/user_feedbacks?search[user_id]=#{req.params[:user_id]}"} get "/user_record" => redirect {|params, req| "/user_feedbacks?search[user_id]=#{req.params[:user_id]}"}
get "/profile", to: "users#profile", as: :profile
get "/wiki" => redirect {|params, req| "/wiki_pages?page=#{req.params[:page]}"} get "/wiki" => redirect {|params, req| "/wiki_pages?page=#{req.params[:page]}"}
get "/wiki/index" => redirect {|params, req| "/wiki_pages?page=#{req.params[:page]}"} get "/wiki/index" => redirect {|params, req| "/wiki_pages?page=#{req.params[:page]}"}

View File

@@ -75,6 +75,33 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
end end
end end
context "profile action" do
should "render the current user's profile" do
get_auth profile_path, @user
assert_response :success
assert_select "#page h1", @user.name
end
should "render the current users's profile in json" do
get_auth profile_path(format: :json), @user
assert_response :success
json = as(@user) { @user.as_json(methods: @user.full_attributes + @user.method_attributes) }
assert_equal(json, response.parsed_body)
end
should "redirect anonymous users to the sign in page" do
get profile_path
assert_redirected_to new_session_path
end
should "return 404 for anonymous api calls" do
get profile_path(format: :json)
assert_response 404
end
end
context "new action" do context "new action" do
setup do setup do
Danbooru.config.stubs(:enable_recaptcha?).returns(false) Danbooru.config.stubs(:enable_recaptcha?).returns(false)