]> git.openstreetmap.org Git - rails.git/commitdiff
Remove current user check from dashboard view
authorAnton Khorev <tony29@yandex.ru>
Wed, 19 Feb 2025 00:59:38 +0000 (03:59 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 19 Feb 2025 01:13:34 +0000 (04:13 +0300)
app/controllers/dashboards_controller.rb
app/views/dashboards/_contact.html.erb
app/views/dashboards/show.html.erb
test/controllers/dashboards_controller_test.rb

index 54dba26d33de85f12ccaacf1d54681382ec5c906..cb73cc38f35baaa76214ca5f15c19d12c400140d 100644 (file)
@@ -9,7 +9,6 @@ class DashboardsController < ApplicationController
   before_action :check_database_readable
 
   def show
-    @user = current_user
     @followings = current_user.followings
     @nearby_users = current_user.nearby - @followings
   end
index 8e78524decb463730cfc2f863151aba6639b8fa1..021f1a33585e7e5dac88e25bdfe894eb211c310b 100644 (file)
@@ -11,8 +11,8 @@
   <div class="col">
     <p class='text-body-secondary mb-0'>
       <%= link_to contact.display_name, contact %>
-      <% if @user.home_location? and contact.home_location? %>
-        <% distance = @user.distance(contact) %>
+      <% if current_user.home_location? and contact.home_location? %>
+        <% distance = current_user.distance(contact) %>
         <% if distance < 1 %>
           (<%= t ".m away", :count => (distance * 1000).round %>)
         <% else %>
index a198f534df1a685134beb19bbfaeb3bcf9a42f47..e110ad531f1f11ad66b4464e24a39a3e52f7ead9 100644 (file)
@@ -3,60 +3,58 @@
 <% end %>
 
 <div class="row">
-  <% if current_user and @user.id == current_user.id %>
-    <div class="col-md order-md-last">
-      <% if !@user.home_location? %>
-        <div id="map" class="content_map border border-secondary-subtle">
-          <p class="m-3"><%= 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 border border-secondary-subtle rounded z-0", :data => { :user => user_data } %>
+  <div class="col-md order-md-last">
+    <% if !current_user.home_location? %>
+      <div id="map" class="content_map border border-secondary-subtle">
+        <p class="m-3"><%= 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 %>
-    </div>
+      <% 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 border border-secondary-subtle rounded z-0", :data => { :user => user_data } %>
+    <% end %>
+  </div>
 
-    <div class="col-md">
-      <h2><%= t ".followings" %></h2>
+  <div class="col-md">
+    <h2><%= t ".followings" %></h2>
 
-      <% if @followings.empty? %>
-        <%= t ".no followings" %>
-      <% else %>
-        <nav class='secondary-actions mb-3'>
-          <ul class='clearfix'>
-            <li><%= link_to t(".followed_changesets"), friend_changesets_path %></li>
-            <li><%= link_to t(".followed_diaries"), friends_diary_entries_path %></li>
-          </ul>
-        </nav>
-        <div>
-          <%= render :partial => "contact", :collection => @followings, :locals => { :type => "following" } %>
-        </div>
-      <% end %>
+    <% if @followings.empty? %>
+      <%= t ".no followings" %>
+    <% else %>
+      <nav class='secondary-actions mb-3'>
+        <ul class='clearfix'>
+          <li><%= link_to t(".followed_changesets"), friend_changesets_path %></li>
+          <li><%= link_to t(".followed_diaries"), friends_diary_entries_path %></li>
+        </ul>
+      </nav>
+      <div>
+        <%= render :partial => "contact", :collection => @followings, :locals => { :type => "following" } %>
+      </div>
+    <% end %>
 
-      <hr>
+    <hr>
 
-      <h2><%= t ".nearby users" %></h2>
+    <h2><%= t ".nearby users" %></h2>
 
-      <% if @nearby_users.empty? %>
-        <%= t ".no nearby users" %>
-      <% else %>
-        <nav class='secondary-actions mb-3'>
-          <ul class='clearfix'>
-            <li><%= link_to t(".nearby_changesets"), nearby_changesets_path %></li>
-            <li><%= link_to t(".nearby_diaries"), nearby_diary_entries_path %></li>
-          </ul>
-        </nav>
-        <div id="nearbyusers">
-          <%= render :partial => "contact", :collection => @nearby_users, :locals => { :type => "nearby mapper" } %>
-        </div>
-      <% end %>
-    </div>
-  <% end %>
+    <% if @nearby_users.empty? %>
+      <%= t ".no nearby users" %>
+    <% else %>
+      <nav class='secondary-actions mb-3'>
+        <ul class='clearfix'>
+          <li><%= link_to t(".nearby_changesets"), nearby_changesets_path %></li>
+          <li><%= link_to t(".nearby_diaries"), nearby_diary_entries_path %></li>
+        </ul>
+      </nav>
+      <div id="nearbyusers">
+        <%= render :partial => "contact", :collection => @nearby_users, :locals => { :type => "nearby mapper" } %>
+      </div>
+    <% end %>
+  </div>
 </div>
index 0adf58a9e4b4cb368c3758a074eba24c83d5541e..c55636585ed97044eafbee1d7e53b64770bf7965 100644 (file)
@@ -9,4 +9,10 @@ class DashboardsControllerTest < ActionDispatch::IntegrationTest
       { :controller => "dashboards", :action => "show" }
     )
   end
+
+  def test_show_unauthorized
+    get dashboard_path
+
+    assert_redirected_to login_path(:referer => dashboard_path)
+  end
 end