Skip to content

Commit

Permalink
Allows users to highlight works
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Jan 12, 2016
1 parent 5d7443e commit 95a16be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/controllers/concerns/sufia/users_controller_behavior.rb
Expand Up @@ -68,17 +68,17 @@ def update_directory?
end

def toggle_trophy
unless current_user.can? :edit, params[:parent_id]
work_id = params[:work_id]
unless current_user.can? :edit, work_id
redirect_to root_path, alert: "You do not have permissions to the work"
return false
end
t = current_user.trophies.where(generic_work_id: params[:parent_id]).first
t = current_user.trophies.where(generic_work_id: work_id).first
if t
t.destroy
# TODO: do this better says Mike
return false if t.persisted?
else
t = current_user.trophies.create(generic_work_id: params[:parent_id])
t = current_user.trophies.create(generic_work_id: work_id)
return false unless t.persisted?
end
render json: t
Expand Down
5 changes: 2 additions & 3 deletions app/views/my/_work_action_menu.html.erb
Expand Up @@ -23,9 +23,8 @@
</li>

<li role="menuitem" tabindex="-1">
<%= link_to('#') do %>
<i aria-hidden="true" class='glyphicon glyphicon-star'></i>
<span> TODO: Highlight Work on Profile </span>
<%= display_trophy_link(@user, document.id) do |text| %>
<i class='glyphicon glyphicon-star'></i> <%= text %>
<% end %>
</li>
<li role="menuitem" tabindex="-1">
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/users_controller_spec.rb
Expand Up @@ -286,22 +286,22 @@

describe "#toggle_trophy" do
let(:work) { GenericWork.create(title: ["w1"]) { |w| w.apply_depositor_metadata(user) } }
let(:parent_id) { work.id }
let(:work_id) { work.id }
let(:another_user) { FactoryGirl.create(:user) }

it "trophies a work" do
post :toggle_trophy, id: user.user_key, parent_id: parent_id
post :toggle_trophy, id: user.user_key, work_id: work_id
json = JSON.parse(response.body)
expect(json['user_id']).to eq user.id
expect(json['generic_work_id']).to eq parent_id
expect(json['generic_work_id']).to eq work_id
end
it "does not trophy a work for a different user" do
post :toggle_trophy, id: another_user.user_key, parent_id: parent_id
post :toggle_trophy, id: another_user.user_key, work_id: work_id
expect(response).to_not be_success
end
it "does not trophy a work with no edit privs" do
sign_in another_user
post :toggle_trophy, id: another_user.user_key, parent_id: parent_id
post :toggle_trophy, id: another_user.user_key, work_id: work_id
expect(response).to_not be_success
end
end
Expand Down

0 comments on commit 95a16be

Please sign in to comment.