Commit 4edfee6d629159727694e2b4b9c9fe89bbb44efa
1 parent
a86306b1
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Added archived article verification into vote plugin
Showing
6 changed files
with
51 additions
and
5 deletions
Show diff stats
... | ... | @@ -0,0 +1,18 @@ |
1 | +require_dependency 'models/vote' | |
2 | + | |
3 | +class Vote | |
4 | + | |
5 | + validate :verify_target_archived | |
6 | + | |
7 | + def verify_target_archived | |
8 | + | |
9 | + if voteable.kind_of?(Article) || voteable.kind_of?(Comment) | |
10 | + if voteable.archived? | |
11 | + errors.add(:base, _("The target is achived and can't accept votes")) | |
12 | + false | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + end | |
17 | + | |
18 | +end | ... | ... |
plugins/vote/lib/vote_plugin_helper.rb
... | ... | @@ -2,8 +2,10 @@ module VotePluginHelper |
2 | 2 | |
3 | 3 | def vote_partial(target, like = true, load_voters=false) |
4 | 4 | vote = like ? 1 : -1 |
5 | + | |
5 | 6 | like_action = like ? 'like' : 'dislike' |
6 | 7 | type = target.kind_of?(Article) ? 'article' : target.kind_of?(Comment) ? 'comment' : nil |
8 | + disable_vote = target.archived? ? true : false | |
7 | 9 | |
8 | 10 | proc do |
9 | 11 | settings = Noosfero::Plugin::Settings.new(environment, VotePlugin) |
... | ... | @@ -14,7 +16,7 @@ module VotePluginHelper |
14 | 16 | active = user ? (like ? user.voted_for?(target) : user.voted_against?(target)) : false |
15 | 17 | count = like ? target.votes_for : target.votes_against |
16 | 18 | |
17 | - render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type }) | |
19 | + render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type, :disable_vote => disable_vote }) | |
18 | 20 | else |
19 | 21 | "" |
20 | 22 | end | ... | ... |
plugins/vote/public/style.css
... | ... | @@ -73,3 +73,12 @@ |
73 | 73 | #article .action .vote-detail img { |
74 | 74 | vertical-align: bottom; |
75 | 75 | } |
76 | + | |
77 | +.comments-action-bar span.disabled a, | |
78 | +.comments-action-bar span.disabled a:hover, | |
79 | +.vote-actions span.disabled a, | |
80 | +.vote-actions span.disabled a:hover { | |
81 | + opacity: 0.5; | |
82 | + pointer-events: none; | |
83 | + cursor: default; | |
84 | +} | ... | ... |
plugins/vote/public/vote_actions.js
... | ... | @@ -16,7 +16,9 @@ function openVotersDialog(div) { |
16 | 16 | clearTimeout(openEvent); |
17 | 17 | var url = $(div).data('reload_url'); |
18 | 18 | hideAllVoteDetail(); |
19 | - $.post(url); | |
19 | + if(url && url != '#'){ | |
20 | + $.post(url); | |
21 | + } | |
20 | 22 | } |
21 | 23 | |
22 | 24 | jQuery('body').live('click', function() { hideAllVoteDetail(); }); | ... | ... |
plugins/vote/test/functional/vote_plugin_profile_controller_test.rb
... | ... | @@ -35,6 +35,16 @@ class VotePluginProfileControllerTest < ActionController::TestCase |
35 | 35 | assert profile.votes.empty? |
36 | 36 | end |
37 | 37 | |
38 | + should 'not vote if a target is archived' do | |
39 | + article = Article.create!(:profile => profile, :name => 'Archived article', :archived => true) | |
40 | + comment = Comment.create!(:body => 'Comment test', :source => article, :author => profile) | |
41 | + xhr :post, :vote, :profile => profile.identifier, :id => article.id, :model => 'article', :vote => 1 | |
42 | + assert profile.votes.empty? | |
43 | + | |
44 | + xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1 | |
45 | + assert !profile.voted_for?(comment) | |
46 | + end | |
47 | + | |
38 | 48 | should 'like comment' do |
39 | 49 | xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1 |
40 | 50 | assert profile.voted_for?(comment) | ... | ... |
plugins/vote/views/vote/_vote.html.erb
1 | 1 | <% |
2 | -url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) | |
3 | -reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) | |
2 | +if disable_vote | |
3 | + url = reload_url = '#' | |
4 | + class_action = 'disabled' | |
5 | +else | |
6 | + url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) | |
7 | + reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) | |
8 | +end | |
4 | 9 | %> |
5 | 10 | |
6 | -<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action"> | |
11 | +<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action <%= class_action %>"> | |
7 | 12 | |
8 | 13 | <%= link_to content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), url, :class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'} require-login-popup" %> |
9 | 14 | ... | ... |