6234: admin user can see other users' home projects; also add link to users' home...
authorradhika <radhika@curoverse.com>
Wed, 17 Jun 2015 21:33:46 +0000 (17:33 -0400)
committerradhika <radhika@curoverse.com>
Wed, 17 Jun 2015 21:33:46 +0000 (17:33 -0400)
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/views/application/_show_recent.html.erb
apps/workbench/test/integration/users_test.rb

index c4600f2c0f7627a88fa6e8235d04077678afafda..4087b59fdbeede3f399a965a9e73360626203268 100644 (file)
@@ -10,12 +10,22 @@ class ProjectsController < ApplicationController
   end
 
   def find_object_by_uuid
-    if current_user and params[:uuid] == current_user.uuid
-      @object = current_user.dup
-      @object.uuid = current_user.uuid
+    if (current_user and params[:uuid] == current_user.uuid) or
+       (resource_class_for_uuid(params[:uuid]) == User)
+      if params[:uuid] != current_user.uuid
+        @object = User.find(params[:uuid])
+      else
+        @object = current_user.dup
+        @object.uuid = current_user.uuid
+      end
+
       class << @object
         def name
-          'Home'
+          if current_user.uuid == self.uuid
+            'Home'
+          else
+            "Home for #{self.email}"
+          end
         end
         def description
           ''
index 57a5b74e93469c96232000d05bf83ac561b3aa66..dd6876d575e92c06c7f06c663ab812c0c2c1e36f 100644 (file)
@@ -8,6 +8,8 @@
 
 <% attr_blacklist = ' created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at owner_uuid group_class properties' %>
 
+<% show_home_link = current_user.is_admin and controller.model_class == User %>
+
 <%= render partial: "paging", locals: {results: objects, object: @object} %>
 
 <%= form_tag do |f| %>
         <%= controller.model_class.attribute_info[attr.to_sym].andand[:column_heading] or attr.sub /_uuid/, '' %>
       </th>
       <% end %>
+      <% if show_home_link %>
+        <th class="arv-user-home">
+          <!-- a column for user's home -->
+        </th>
+      <% end %>
       <th>
         <!-- a column for delete buttons -->
       </th>
         <% end %>
       </td>
       <% end %>
+      <% if show_home_link %>
+        <td>
+          <%= link_to 'Home', "/projects/#{object.uuid}" %>
+        </td>
+      <% end %>
       <td>
         <%= render partial: 'delete_object_button', locals: {object:object} %>
       </td>
index 4615f846d7ee8170f94aa542d390385f85f6d429..8de7e9e2c48fb3e8d4cd29ec310a68631e97fbe4 100644 (file)
@@ -218,10 +218,15 @@ class UsersTest < ActionDispatch::IntegrationTest
 
       within('tr', text: user['uuid']) do
         assert_text user['email']
+        if username == 'admin'
+          assert_selector 'a', text: 'Home'
+        else
+          assert_no_selector 'a', text: 'Home'
+        end
         assert_selector 'a', text: 'Show'
         find('a', text: 'Show').click
       end
-      assert_selector 'a', text:'Attributes'
+      assert_selector 'a', text: 'Attributes'
     end
   end
 
@@ -233,6 +238,7 @@ class UsersTest < ActionDispatch::IntegrationTest
     active_user = api_fixture('users', 'active')
     within('tr', text: active_user['uuid']) do
       assert_text active_user['email']
+      assert_selector "a[href=\"/projects/#{active_user['uuid']}\"]", text: 'Home'
       assert_selector 'a', text: 'Show'
       find('a', text: 'Show').click
     end