diff --git a/app/controllers/maintenance/user/count_fixes_controller.rb b/app/controllers/maintenance/user/count_fixes_controller.rb index a479132d0..da1816efc 100644 --- a/app/controllers/maintenance/user/count_fixes_controller.rb +++ b/app/controllers/maintenance/user/count_fixes_controller.rb @@ -9,7 +9,7 @@ module Maintenance def create CurrentUser.user.refresh_counts! flash[:notice] = "Counts have been refreshed" - redirect_to user_path(CurrentUser.id) + redirect_to profile_path end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 967d61436..f6c0fb3fa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -36,10 +36,21 @@ class UsersController < ApplicationController def show @user = User.find(params[:id]) - @presenter = UserPresenter.new(@user) respond_with(@user, methods: @user.full_attributes) 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 @user = User.new(user_params(:create)) if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user) diff --git a/app/views/layouts/_main_links.html.erb b/app/views/layouts/_main_links.html.erb index a2af89a7c..3d3933c00 100644 --- a/app/views/layouts/_main_links.html.erb +++ b/app/views/layouts/_main_links.html.erb @@ -2,7 +2,7 @@ <% if CurrentUser.is_anonymous? %> <%= nav_link_to("Sign in", new_session_path) %> <% else %> - <%= nav_link_to("My Account #{CurrentUser.dmail_count}", user_path(CurrentUser.user)) %> + <%= nav_link_to("My Account #{CurrentUser.dmail_count}", profile_path) %> <% end %> <%= nav_link_to("Posts", posts_path) %> <%= nav_link_to("Comments", comments_path(:group_by => "post")) %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 0c7daac07..c77f61cee 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -119,7 +119,7 @@
  • <%= link_to "Sign in", new_session_path %>
  • <%= link_to "Sign up", new_user_path %>
  • <% else %> -
  • <%= link_to "Profile", CurrentUser.user %>
  • +
  • <%= link_to "Profile", profile_path %>
  • <%= link_to "Settings", edit_user_path(CurrentUser.user) %>
  • <% if CurrentUser.is_gold? %>
  • <%= link_to "Change name", new_user_name_change_request_path %>
  • diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index c0f8a4e5f..b8184aef4 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -12,7 +12,7 @@
  • |
  • <% if @user.id == CurrentUser.user.id %> <%= 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 %> <% if !@user.is_platinum? %> diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 4c6406340..b2f971175 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -2,6 +2,10 @@

    Statistics

    + + + + diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index d9c8eda53..e0996424a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,11 +2,11 @@

    <%= link_to_user @user %>

    - <%= 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 %> <%= render "posts/partials/common/inline_blacklist" %> - <%= render "post_summary", :presenter => @presenter, :user => @user %> + <%= render "post_summary", presenter: @user.presenter, user: @user %> <% end %>
    @@ -14,7 +14,7 @@ <%= render "secondary_links" %> <% content_for(:page_title) do %> - User - <%= @presenter.name %> - <%= Danbooru.config.app_name %> + User - <%= @user.presenter.name %> - <%= Danbooru.config.app_name %> <% 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")) %> diff --git a/config/routes.rb b/config/routes.rb index 3b88d2250..f8c8f6062 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -410,6 +410,7 @@ Rails.application.routes.draw do get "/user/show/:id" => redirect("/users/%{id}") get "/user/login" => redirect("/sessions/new") 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/index" => redirect {|params, req| "/wiki_pages?page=#{req.params[:page]}"} diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 825ace11b..0b9788d40 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -75,6 +75,33 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 setup do Danbooru.config.stubs(:enable_recaptcha?).returns(false)
    User ID<%= user.id %>
    Join Date <%= presenter.join_date %>