]> git.openstreetmap.org Git - rails.git/commitdiff
Split the non-public information off of the profile page
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Jul 2021 16:54:57 +0000 (17:54 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 18 Aug 2021 12:32:36 +0000 (13:32 +0100)
This opens up many possibilities for more interesting things to be
shown on the dashboard, as well as making it easier to find if
you have lots of content in your profile.

12 files changed:
app/abilities/ability.rb
app/assets/stylesheets/common.scss
app/controllers/dashboards_controller.rb [new file with mode: 0644]
app/views/dashboards/_contact.html.erb [moved from app/views/users/_contact.html.erb with 93% similarity]
app/views/dashboards/_popup.html.erb [moved from app/views/users/_popup.html.erb with 100% similarity]
app/views/dashboards/show.html.erb [new file with mode: 0644]
app/views/layouts/_header.html.erb
app/views/users/show.html.erb
config/locales/en.yml
config/routes.rb
test/controllers/dashboards_controller_test.rb [new file with mode: 0644]
test/controllers/users_controller_test.rb

index 018ce00966bd295e347fe8a5d8fa9c3b9bd4701b..769fbca475e401ba9538ae6164cd60f84e6bf6fe 100644 (file)
@@ -42,6 +42,7 @@ class Ability
         can [:index, :new, :create, :show, :edit, :update, :destroy], :oauth2_application
         can [:index, :destroy], :oauth2_authorized_application
         can [:new, :show, :create, :destroy], :oauth2_authorization
+        can [:show], :dashboard
         can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry
         can [:make_friend, :remove_friend], Friendship
         can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
index 0023286bf6391e405de80666cb962cf7d5fa0cba..42090e73329ad63c1c680a7ce594fe9885276d1f 100644 (file)
@@ -1123,11 +1123,7 @@ tr.turn:hover {
   margin-bottom: 0;
 }
 
-.users-show {
-  // Silly exception; remove when user page is redesigned.
-  .content-inner {
-    max-width: none;
-  }
+.dashboards-show {
   p#no_home_location {
     margin: $lineheight;
   }
diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb
new file mode 100644 (file)
index 0000000..540683d
--- /dev/null
@@ -0,0 +1,14 @@
+class DashboardsController < ApplicationController
+  layout "site"
+
+  before_action :authorize_web
+  before_action :set_locale
+
+  authorize_resource :class => false
+
+  before_action :check_database_readable
+
+  def show
+    @user = current_user
+  end
+end
similarity index 93%
rename from app/views/users/_contact.html.erb
rename to app/views/dashboards/_contact.html.erb
index c7e10c060c2c655eb4076f6d0d301ff8bff3e437..3b46a3b4566b610ecbee25401984239663ffbb03 100644 (file)
@@ -12,9 +12,9 @@
       <% if @user.home_lon and @user.home_lat and contact.home_lon and contact.home_lat %>
         <% distance = @user.distance(contact) %>
         <% if distance < 1 %>
-          (<%= t "users.show.m away", :count => (distance * 1000).round %>)
+          (<%= t ".m away", :count => (distance * 1000).round %>)
         <% else %>
-          (<%= t "users.show.km away", :count => distance.round %>)
+          (<%= t ".km away", :count => distance.round %>)
         <% end %>
       <% end %>
     </p>
diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb
new file mode 100644 (file)
index 0000000..3fe27b7
--- /dev/null
@@ -0,0 +1,61 @@
+<% content_for :heading do %>
+  <h1><%= t ".title" %></h1>
+<% end %>
+
+<div class="row">
+  <% if current_user and @user.id == current_user.id %>
+    <div class="col-md order-md-last">
+      <% if @user.home_lat.nil? or @user.home_lon.nil? %>
+        <div id="map" class="content_map">
+          <p id="no_home_location"><%= t(".no_home_location_html", :edit_profile_link => link_to(t(".edit_your_profile"), edit_profile_path)) %></p>
+        </div>
+      <% else %>
+        <% content_for :head do %>
+          <%= javascript_include_tag "user" %>
+        <% end %>
+        <% user_data = {
+             :lon => current_user.home_lon,
+             :lat => current_user.home_lat,
+             :icon => image_path("marker-red.png"),
+             :description => render(:partial => "popup", :object => current_user, :locals => { :type => "your location" })
+           } %>
+        <%= tag.div "", :id => "map", :class => "content_map", :data => { :user => user_data } %>
+      <% end %>
+
+      <% friends = @user.friends %>
+      <% nearby = @user.nearby - friends %>
+    </div>
+
+    <div class="col-md">
+      <h3><%= t ".my friends" %></h3>
+
+      <% if friends.empty? %>
+        <%= t ".no friends" %>
+      <% else %>
+        <ul class='secondary-actions clearfix'>
+          <li><%= link_to t(".friends_changesets"), friend_changesets_path %></li>
+          <li><%= link_to t(".friends_diaries"), friends_diary_entries_path %></li>
+        </ul>
+        <div id="friends-container">
+          <%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %>
+        </div>
+      <% end %>
+
+      <hr>
+
+      <h3><%= t ".nearby users" %></h3>
+
+      <% if nearby.empty? %>
+        <%= t ".no nearby users" %>
+      <% else %>
+        <ul class='secondary-actions clearfix'>
+          <li><%= link_to t(".nearby_changesets"), nearby_changesets_path %></li>
+          <li><%= link_to t(".nearby_diaries"), nearby_diary_entries_path %></li>
+        </ul>
+        <div id="nearbyusers">
+          <%= render :partial => "contact", :collection => nearby, :locals => { :type => "nearby mapper" } %>
+        </div>
+      <% end %>
+    </div>
+  <% end %>
+</div>
index a20474b57a2ed9624bb40265635e414e93b08c43..192b0761431faf62a8f25a002f6e293c8f72a806 100644 (file)
@@ -90,6 +90,7 @@
           </span>
         </a>
         <div class='dropdown-menu dropdown-menu-right'>
+          <%= link_to t("users.show.my_dashboard"), dashboard_path, :class => "dropdown-item" %>
           <%= link_to inbox_messages_path, :class => "dropdown-item" do %>
             <%= t("users.show.my messages") %>
             <span class='count-number'><%= number_with_delimiter(current_user.new_messages.size) %></span>
index caa7730cb16fe4809b8452c3b461c659c5081430..95abbdc3c73f721f15747dbf6fcda9b93157c13f 100644 (file)
   <% end -%>
 
 <% end %>
-
-<div class="row">
-  <% if current_user and @user.id == current_user.id %>
-    <div class="col-md order-md-last">
-      <% if @user.home_lat.nil? or @user.home_lon.nil? %>
-        <div id="map" class="content_map">
-          <p id="no_home_location"><%= t(".no_home_location_html", :edit_profile_link => link_to(t(".edit_your_profile"), edit_profile_path)) %></p>
-        </div>
-      <% else %>
-        <% content_for :head do %>
-          <%= javascript_include_tag "user" %>
-        <% end %>
-        <% user_data = {
-             :lon => current_user.home_lon,
-             :lat => current_user.home_lat,
-             :icon => image_path("marker-red.png"),
-             :description => render(:partial => "popup", :object => current_user, :locals => { :type => "your location" })
-           } %>
-        <%= tag.div "", :id => "map", :class => "content_map", :data => { :user => user_data } %>
-      <% end %>
-
-      <% friends = @user.friends %>
-      <% nearby = @user.nearby - friends %>
-    </div>
-
-    <div class="col-md">
-      <h3><%= t ".my friends" %></h3>
-
-      <% if friends.empty? %>
-        <%= t ".no friends" %>
-      <% else %>
-        <ul class='secondary-actions clearfix'>
-          <li><%= link_to t(".friends_changesets"), friend_changesets_path %></li>
-          <li><%= link_to t(".friends_diaries"), friends_diary_entries_path %></li>
-        </ul>
-        <div id="friends-container">
-          <%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %>
-        </div>
-      <% end %>
-
-      <hr>
-
-      <h3><%= t ".nearby users" %></h3>
-
-      <% if nearby.empty? %>
-        <%= t ".no nearby users" %>
-      <% else %>
-        <ul class='secondary-actions clearfix'>
-          <li><%= link_to t(".nearby_changesets"), nearby_changesets_path %></li>
-          <li><%= link_to t(".nearby_diaries"), nearby_diary_entries_path %></li>
-        </ul>
-        <div id="nearbyusers">
-          <%= render :partial => "contact", :collection => nearby, :locals => { :type => "nearby mapper" } %>
-        </div>
-      <% end %>
-    </div>
-  <% end %>
-</div>
index 5b1686c6b81b6eddf6c2f63304d00b9428bcde85..9f0e42f7a1689e2c476eb8f08fa7f61f149aad70 100644 (file)
@@ -416,6 +416,26 @@ en:
       title_particular: "OpenStreetMap changeset #%{changeset_id} discussion"
     timeout:
       sorry: "Sorry, the list of changeset comments you requested took too long to retrieve."
+  dashboards:
+    contact:
+      km away: "%{count}km away"
+      m away: "%{count}m away"
+    popup:
+      your location: "Your location"
+      nearby mapper: "Nearby mapper"
+      friend: "Friend"
+    show:
+      title: My Dashboard
+      no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users."
+      edit_your_profile: Edit your profile
+      my friends: My friends
+      no friends: You have not added any friends yet.
+      nearby users: "Other nearby users"
+      no nearby users: "There are no other users who admit to mapping nearby yet."
+      friends_changesets: "friends' changesets"
+      friends_diaries: "friends' diary entries"
+      nearby_changesets: "nearby user changesets"
+      nearby_diaries: "nearby user diary entries"
   diary_entries:
     new:
       title: New Diary Entry
@@ -2484,6 +2504,7 @@ en:
       my settings: My Settings
       my comments: My Comments
       my_preferences: My Preferences
+      my_dashboard: My Dashboard
       blocks on me: Blocks on Me
       blocks by me: Blocks by Me
       edit_profile: Edit Profile
@@ -2505,14 +2526,6 @@ en:
       spam score: "Spam Score:"
       description: Description
       user location: User location
-      no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users."
-      edit_your_profile: Edit your profile
-      my friends: My friends
-      no friends: You have not added any friends yet.
-      km away: "%{count}km away"
-      m away: "%{count}m away"
-      nearby users: "Other nearby users"
-      no nearby users: "There are no other users who admit to mapping nearby yet."
       role:
         administrator: "This user is an administrator"
         moderator: "This user is a moderator"
@@ -2533,15 +2546,7 @@ en:
       unhide_user: "Unhide this User"
       delete_user: "Delete this User"
       confirm: "Confirm"
-      friends_changesets: "friends' changesets"
-      friends_diaries: "friends' diary entries"
-      nearby_changesets: "nearby user changesets"
-      nearby_diaries: "nearby user diary entries"
       report: Report this User
-    popup:
-      your location: "Your location"
-      nearby mapper: "Nearby mapper"
-      friend: "Friend"
     account:
       title: "Edit account"
       my settings: My Settings
index dc10818b99aba08f26841b7a6eb3ed24db3107a2..f4c19f88cb9278ad050e9c972ad0a2939efefc8f 100644 (file)
@@ -240,6 +240,7 @@ OpenStreetMap::Application.routes.draw do
   match "/user/:display_name/account" => "users#account", :via => [:get, :post], :as => "user_account"
   post "/user/:display_name/set_status" => "users#set_status", :as => :set_status_user
 
+  resource :dashboard, :only => [:show]
   resource :preferences, :only => [:show, :edit, :update]
   resource :profile, :only => [:edit, :update]
 
diff --git a/test/controllers/dashboards_controller_test.rb b/test/controllers/dashboards_controller_test.rb
new file mode 100644 (file)
index 0000000..5073df8
--- /dev/null
@@ -0,0 +1,34 @@
+require "test_helper"
+
+class DashboardsControllerTest < ActionDispatch::IntegrationTest
+  ##
+  # test all routes which lead to this controller
+  def test_routes
+    assert_routing(
+      { :path => "/dashboard", :method => :get },
+      { :controller => "dashboards", :action => "show" }
+    )
+  end
+
+  def test_show_no_friends
+    user = create(:user)
+    session_for(user)
+
+    get dashboard_path
+  end
+
+  def test_show_with_friends
+    user = create(:user, :home_lon => 1.1, :home_lat => 1.1)
+    friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2)
+    create(:friendship, :befriender => user, :befriendee => friend_user)
+    create(:changeset, :user => friend_user)
+    session_for(user)
+
+    get dashboard_path
+
+    # Friends should be visible as we're now logged in
+    assert_select "div#friends-container" do
+      assert_select "div.contact-activity", :count => 1
+    end
+  end
+end
index 10c5c3bee674e626585f7ba8632ff42455cc2afd..3d8914e5897ab5bd1d0141cbdcc510ef83e466d1 100644 (file)
@@ -556,10 +556,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :not_found
 
     # Test a normal user
-    user = create(:user, :home_lon => 1.1, :home_lat => 1.1)
-    friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2)
-    create(:friendship, :befriender => user, :befriendee => friend_user)
-    create(:changeset, :user => friend_user)
+    user = create(:user)
 
     get user_path(user)
     assert_response :success
@@ -626,11 +623,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
       assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
     end
 
-    # Friends should be visible as we're now logged in
-    assert_select "div#friends-container" do
-      assert_select "div.contact-activity", :count => 1
-    end
-
     # Login as a moderator
     session_for(create(:moderator_user))