3821: The "Remove selected files" option should only be presented if the user can...
authorradhika <radhika@curoverse.com>
Tue, 28 Mar 2017 16:54:56 +0000 (12:54 -0400)
committerradhika <radhika@curoverse.com>
Tue, 28 Mar 2017 16:54:56 +0000 (12:54 -0400)
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/test/integration/collections_test.rb

index 0dc16fbb44561c183b338e5b0272f9380565acc6..056f12f6c8e70faa77f45d5f5d356439d528a1ec 100644 (file)
@@ -274,7 +274,7 @@ module ApplicationHelper
       "data-placement" => "bottom",
       "data-type" => input_type,
       "data-title" => "Edit #{attr.to_s.gsub '_', ' '}",
-      "data-name" => htmloptions['selection_path'] || attr,
+      "data-name" => htmloptions['selection_name'] || attr,
       "data-object-uuid" => object.uuid,
       "data-toggle" => "manual",
       "data-value" => htmloptions['data-value'] || attrvalue,
index fc1ca58d2a9a00cc55912a72bc75ac4209ae39ca..37d9283dbd7a85d6a2f1a797fa3becae18c9828f 100644 (file)
@@ -27,6 +27,7 @@
                     'data-selection-action' => 'combine-collections',
                     'data-toggle' => 'dropdown'
               %></li>
+            <% if @object.editable? %>
             <li><%= link_to "Remove selected files", '#',
                     method: :post,
                     'data-href' => url_for(action: :remove_selected_files),
@@ -34,6 +35,7 @@
                     'data-selection-action' => 'remove-selected-files',
                     'data-toggle' => 'dropdown'
               %></li>
+            <% end %>
           </ul>
         </div>
         <div class="btn-group btn-group-sm">
          </div>
         <% else %>
               <% if @object.editable? %>
-                <i class="fa fa-fw fa-file"></i><%= render_editable_attribute @object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_path' => 'rename-file-path:'+file_path} %>
+                <i class="fa fa-fw fa-file"></i><%= render_editable_attribute @object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_name' => 'rename-file-path:'+file_path} %>
               <% else %>
                 <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %>
               <% end %>
index 2685e521f18f2a7bc29b17b50f011af30d846c71..eb9c2e831a8866d7a25f3f89c9c1eb04ef00a003 100644 (file)
@@ -340,4 +340,21 @@ class CollectionsTest < ActionDispatch::IntegrationTest
 
     assert(page.has_text?('file1renamed'), 'file not found - file1renamed')
   end
+
+  test "remove/rename file options not presented if user cannot update a collection" do
+    # visit a publicly accessible collection as 'spectator'
+    visit page_with_token('spectator', '/collections/zzzzz-4zz18-uukreo9rbgwsujr')
+
+    click_button 'Selection'
+    within('.selection-action-container') do
+      assert_selector 'li', text: 'Create new collection with selected files'
+      assert_no_selector 'li', text: 'Remove selected files'
+    end
+
+    within('.collection_files') do
+      assert(page.has_text?('GNU_General_Public_License'), 'file not found - GNU_General_Public_License')
+      assert_nil first('.fa-pencil')
+      assert_nil first('.fa-trash-o')
+    end
+  end
 end