Skip to content

Commit

Permalink
Restores editor logic in view. Removes collector logic. Fixes #1477
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Dec 17, 2015
1 parent 1e04e5c commit 2dd3b5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 4 additions & 0 deletions app/presenters/sufia/file_set_presenter.rb
Expand Up @@ -4,6 +4,10 @@ class FileSetPresenter < ::CurationConcerns::FileSetPresenter

delegate :depositor, :tag, :date_created, :date_modified, to: :solr_document

def editor?
current_ability.can?(:edit, solr_document)
end

def tweeter
user = ::User.find_by_user_key(depositor)
if user.try(:twitter_handle).present?
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/sufia/work_show_presenter.rb
Expand Up @@ -3,6 +3,10 @@ class WorkShowPresenter < ::CurationConcerns::WorkShowPresenter
# delegate fields from Sufia::Works::Metadata to solr_document
delegate :based_near, :depositor, :identifier, :resource_type, :tag, to: :solr_document

def editor?
current_ability.can?(:edit, solr_document)
end

def tweeter
user = ::User.find_by_user_key(depositor)
if user.try(:twitter_handle).present?
Expand Down
40 changes: 17 additions & 23 deletions app/views/curation_concerns/base/_show_actions.html.erb
@@ -1,23 +1,17 @@
<%# TODO: set these variables based on the current user
# See https://github.com/projecthydra/sufia/issues/1477 %>
<% collector = true %>
<% editor = true %>
<% if collector || editor %>
<div class="form-actions">
<% if Sufia.config.analytics %>
<%= link_to "Analytics", sufia.stats_work_path(@presenter), id: 'stats', class: 'btn btn-default' %>
<% end %>
<% if Sufia.config.citations %>
<%= link_to "Citations", sufia.citations_work_path(@presenter), id: 'citations', class: 'btn btn-default' %>
<% end %>
<% if editor %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, @presenter]), class: 'btn btn-default' %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, @presenter], class: 'btn btn-danger pull-right', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %>
<% end %>
<%= link_to 'Export to EndNote', polymorphic_path([main_app, @presenter], format: 'endnote'), class: 'btn btn-default' %>
<%= link_to 'Export to Zotero', sufia.static_path('zotero'), id: 'zoteroLink', name: 'zotero', class: 'btn btn-default' %>
<%= link_to 'Export to Mendeley', sufia.static_path('mendeley'), id: 'mendeleyLink', name: 'mendeley', class: 'btn btn-default' %>
<!-- COinS hook for Zotero -->
<span class="Z3988" title="<%= export_as_openurl_ctx_kev(@presenter) %>"></span>
</div>
<% end %>
<div class="form-actions">
<% if Sufia.config.analytics %>
<%= link_to "Analytics", sufia.stats_work_path(@presenter), id: 'stats', class: 'btn btn-default' %>
<% end %>
<% if Sufia.config.citations %>
<%= link_to "Citations", sufia.citations_work_path(@presenter), id: 'citations', class: 'btn btn-default' %>
<% end %>
<% if @presenter.editor? %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, @presenter]), class: 'btn btn-default' %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, @presenter], class: 'btn btn-danger pull-right', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %>
<% end %>
<%= link_to 'Export to EndNote', polymorphic_path([main_app, @presenter], format: 'endnote'), class: 'btn btn-default' %>
<%= link_to 'Export to Zotero', sufia.static_path('zotero'), id: 'zoteroLink', name: 'zotero', class: 'btn btn-default' %>
<%= link_to 'Export to Mendeley', sufia.static_path('mendeley'), id: 'mendeleyLink', name: 'mendeley', class: 'btn btn-default' %>
<!-- COinS hook for Zotero -->
<span class="Z3988" title="<%= export_as_openurl_ctx_kev(@presenter) %>"></span>
</div>
@@ -1,6 +1,7 @@
require 'spec_helper'

describe 'curation_concerns/base/_show_actions.html.erb', type: :view do
let(:user) { create(:user) }
let(:object_profile) { ["{\"id\":\"999\"}"] }
let(:contributor) { ['Frodo'] }
let(:creator) { ['Bilbo'] }
Expand All @@ -15,18 +16,17 @@
rights_tesim: ['http://creativecommons.org/licenses/by/3.0/us/']
)
}
let(:ability) { nil }
let(:ability) { Ability.new(user) }
let(:presenter) do
Sufia::WorkShowPresenter.new(solr_document, ability)
end
let(:locals) { { collector: true, editor: false } }
describe 'citations' do
let(:page) { Capybara::Node::Simple.new(rendered) }
before do
Sufia.config.citations = citations
allow(controller).to receive(:can?).with(:edit, presenter).and_return(false)
assign(:presenter, presenter)
render partial: 'curation_concerns/base/show_actions.html.erb', locals: locals
render partial: 'curation_concerns/base/show_actions.html.erb'
end
context 'when enabled' do
let(:citations) { true }
Expand Down

0 comments on commit 2dd3b5f

Please sign in to comment.