Permalink
Browse files

Improve the plonking

  • Loading branch information...
1 parent 4d06b8d commit e7ced918ed30987438bc76b878b25d4a0b462feb @nono nono committed Sep 27, 2011
@@ -1,11 +0,0 @@
-# encoding: UTF-8
-class Moderation::BlacklistController < ModerationController
- include ActionView::Helpers::TextHelper
-
- def create
- nb_days = (params[:nb_days] || 2).to_i
- @account = Account.find(params[:account_id])
- @account.blacklist(nb_days)
- render :json => { :notice => "#{@account.login} a été blacklisté pour #{pluralize nb_days, "jour"}" }
- end
-end
@@ -0,0 +1,11 @@
+# encoding: UTF-8
+class Moderation::PlonkController < ModerationController
+ include ActionView::Helpers::TextHelper
+
+ def create
+ nb_days = (params[:nb_days] || 2).to_i
+ @account = Account.find(params[:account_id])
+ @account.plonk(nb_days, current_user.id)
+ render :json => { :notice => "#{@account.login} a été plonké pour #{pluralize nb_days, "jour"}" }
+ end
+end
View
@@ -43,6 +43,7 @@
#
class Account < ActiveRecord::Base
include Canable::Cans
+ include ActionView::Helpers::TextHelper
has_many :logs
belongs_to :user, :inverse_of => :account
@@ -184,7 +185,7 @@ def self.send_reset_password_instructions(attributes={})
### Actions ###
def can_post_on_board?
- active_for_authentication? && !blacklisted?
+ active_for_authentication? && !plonked?
end
def tag(node, tags)
@@ -196,7 +197,7 @@ def read(node)
end
def viewable_by?(account)
- account.admin? || account.moderator? || account.id == self.id
+ account && (account.admin? || account.moderator? || account.id == self.id)
end
### Karma ###
@@ -217,19 +218,19 @@ def nb_votes
[self["nb_votes"], 0].max
end
-### Blacklist for the board ###
+### Plonk for the board ###
- def blacklisted?
- $redis.exists("blacklist/#{self.id}")
+ def plonked?
+ $redis.exists("plonk/#{self.id}")
end
- def blacklist(nb_days)
- $redis.set("blacklist/#{self.id}", 1)
- $redis.expire("blacklist/#{self.id}", nb_days * 86400)
- logs.create(:description => "Interdiction de tribune pour #{nb_days} jours")
+ def plonk(nb_days, user_id)
+ $redis.set("plonk/#{self.id}", 1)
+ $redis.expire("plonk/#{self.id}", nb_days * 86400)
+ logs.create(:description => "Interdiction de tribune pour #{pluralize nb_days, "jour"}", :user_id => user_id)
end
- def can_blacklist?
+ def can_plonk?
moderator? || admin?
end
View
@@ -7,10 +7,13 @@
# id :integer(4) not null, primary key
# account_id :integer(4)
# description :string(255)
+# user_id :integer(4)
+# created_at :datetime
#
-# The Log class is here to keep some facts about accounts like blacklist.
+# The Log class is here to keep some facts about accounts like plonks.
#
class Log < ActiveRecord::Base
- belongs_to :account
+ belongs_to :account # The account that has been modified
+ belongs_to :user # The AMR or user who made the modification
end
@@ -11,18 +11,18 @@
- if current_account.amr?
%li Karma&nbsp;: #{a.karma}
%li Dernière connexion&nbsp;: #{a.current_sign_in_at ? l(@user.account.current_sign_in_at) : "-"}
- - if current_account.can_blacklist?
+ - if current_account.can_plonk?
%h2 Interdire de tribune
%ul
- %li= button_to "24h", moderation_blacklist_index_path(:nb_days => 1, :account_id => @user.account.id), :remote => true
- %li= button_to "2 jours", moderation_blacklist_index_path(:nb_days => 2, :account_id => @user.account.id), :remote => true
- %li= button_to "une semaine", moderation_blacklist_index_path(:nb_days => 7, :account_id => @user.account.id), :remote => true
- %li= button_to "un mois", moderation_blacklist_index_path(:nb_days => 30, :account_id => @user.account.id), :remote => true
+ %li= button_to "24h", moderation_plonk_index_path(:nb_days => 1, :account_id => @user.account.id), :remote => true
+ %li= button_to "2 jours", moderation_plonk_index_path(:nb_days => 2, :account_id => @user.account.id), :remote => true
+ %li= button_to "une semaine", moderation_plonk_index_path(:nb_days => 7, :account_id => @user.account.id), :remote => true
+ %li= button_to "un mois", moderation_plonk_index_path(:nb_days => 30, :account_id => @user.account.id), :remote => true
- if @user.account.logs.any?
%h2 Historique
%ul
= list_of(@user.account.logs) do |log|
- #{l log.created_at} - #{log.description}
+ #{l log.created_at} - #{log.user.try :name} - #{log.description}
%ul
%li= link_to "Derniers journaux", user_path(@user)
%li= link_to "Dernières dépêches", news_user_path(@user)
View
@@ -113,7 +113,7 @@
post :refuse, :on => :member
post :accept, :on => :member
end
- resources :blacklist, :only => [:create]
+ resources :plonk, :only => [:create]
end
# Admin
@@ -0,0 +1,6 @@
+class AddUserIdToLogs < ActiveRecord::Migration
+ def change
+ add_column :logs, :user_id, :integer
+ remove_column :logs, :updated_at
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110926220039) do
+ActiveRecord::Schema.define(:version => 20110927231326) do
create_table "accounts", :force => true do |t|
t.integer "user_id"
@@ -127,7 +127,7 @@
t.integer "account_id"
t.string "description"
t.datetime "created_at"
- t.datetime "updated_at"
+ t.integer "user_id"
end
add_index "logs", ["account_id"], :name => "index_logs_on_account_id"

0 comments on commit e7ced91

Please sign in to comment.