Skip to content

Commit

Permalink
Let admin reset votes on candidate news
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Jun 22, 2012
1 parent c7c018e commit d6e62dd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/RonRonnement.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ button, input[type='submit'] {
&#admin_49_3, &.archive_button, &.reopen_button {
background: url("/images/icones/target.png") no-repeat 2px 2px $C_CLAIR;
}
&.reset_news {
background: url("/images/icones/loop.png") no-repeat 2px 2px $C_CLAIR;
}
&.rewrite_news {
background: url("/images/icones/pen.png") no-repeat 2px 2px $C_CLAIR;
}
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/moderation/news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def refuse
end
end

def reset
enforce_reset_permission(@news)
@news.reset_votes
redirect_to [:moderation, @news], :notice => "Votes remis à zéro"
end

def rewrite
enforce_rewrite_permission(@news)
if @news.unlocked?
Expand Down
14 changes: 12 additions & 2 deletions app/models/news.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def be_refused
end

def be_rewritten
%w(pour contre).each {|word| $redis.del("news/#{self.id}/#{word}") }
node.update_column(:score, 0)
reset_votes
Push.create(self, :kind => :rewritten, :username => moderator.name)
end

Expand Down Expand Up @@ -216,6 +215,8 @@ def create_node(attrs={})
super attrs
end

### Moderators' votes ###

def vote_on_candidate(value, account)
word = value > 0 ? "pour" : "contre"
who = account.login
Expand All @@ -240,6 +241,11 @@ def voters_against
$redis.smembers("news/#{self.id}/contre").to_sentence
end

def reset_votes
%w(pour contre).each {|word| $redis.del("news/#{self.id}/#{word}") }
node.update_column(:score, 0)
end

### ACL ###

def self.accept_threshold
Expand Down Expand Up @@ -278,6 +284,10 @@ def refusable_by?(account)
account.admin? || (account.moderator? && refusable?)
end

def resetable_by?(account)
account.admin?
end

def rewritable_by?(account)
account.admin?
end
Expand Down
1 change: 1 addition & 0 deletions app/views/moderation/news/_vote.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
#buttons_49_3(style="display: none;")
= button_to "Publier", accept_moderation_news_path(@news), :class => "publish_news"
= button_to "Refuser", refuse_moderation_news_path(@news), :class => "refuse_news"
= button_to "Revoter", reset_moderation_news_path(@news), :class => "reset_news"
- if @news.node.cc_licensed?
= button_to "Re-rédaction", rewrite_moderation_news_path(@news), :class => "rewrite_news"
1 change: 1 addition & 0 deletions config/initializers/canable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def enforce_#{can}_permission(resource, message="")
Canable.add(:tag, :taggable)
Canable.add(:accept, :acceptable)
Canable.add(:refuse, :refusable)
Canable.add(:reset, :resetable)
Canable.add(:rewrite, :rewritable)
Canable.add(:ppp, :pppable)
Canable.add(:answer, :answerable)
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
post :refuse
post :rewrite
post :ppp
post :reset
get :vote
end
end
Expand Down

0 comments on commit d6e62dd

Please sign in to comment.