Skip to content

Commit

Permalink
Improve the plonking
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Sep 27, 2011
1 parent 4d06b8d commit e7ced91
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
11 changes: 0 additions & 11 deletions app/controllers/moderation/blacklist_controller.rb

This file was deleted.

11 changes: 11 additions & 0 deletions app/controllers/moderation/plonk_controller.rb
@@ -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
21 changes: 11 additions & 10 deletions app/models/account.rb
Expand Up @@ -43,6 +43,7 @@
# #
class Account < ActiveRecord::Base class Account < ActiveRecord::Base
include Canable::Cans include Canable::Cans
include ActionView::Helpers::TextHelper


has_many :logs has_many :logs
belongs_to :user, :inverse_of => :account belongs_to :user, :inverse_of => :account
Expand Down Expand Up @@ -184,7 +185,7 @@ def self.send_reset_password_instructions(attributes={})
### Actions ### ### Actions ###


def can_post_on_board? def can_post_on_board?
active_for_authentication? && !blacklisted? active_for_authentication? && !plonked?
end end


def tag(node, tags) def tag(node, tags)
Expand All @@ -196,7 +197,7 @@ def read(node)
end end


def viewable_by?(account) def viewable_by?(account)
account.admin? || account.moderator? || account.id == self.id account && (account.admin? || account.moderator? || account.id == self.id)
end end


### Karma ### ### Karma ###
Expand All @@ -217,19 +218,19 @@ def nb_votes
[self["nb_votes"], 0].max [self["nb_votes"], 0].max
end end


### Blacklist for the board ### ### Plonk for the board ###


def blacklisted? def plonked?
$redis.exists("blacklist/#{self.id}") $redis.exists("plonk/#{self.id}")
end end


def blacklist(nb_days) def plonk(nb_days, user_id)
$redis.set("blacklist/#{self.id}", 1) $redis.set("plonk/#{self.id}", 1)
$redis.expire("blacklist/#{self.id}", nb_days * 86400) $redis.expire("plonk/#{self.id}", nb_days * 86400)
logs.create(:description => "Interdiction de tribune pour #{nb_days} jours") logs.create(:description => "Interdiction de tribune pour #{pluralize nb_days, "jour"}", :user_id => user_id)
end end


def can_blacklist? def can_plonk?
moderator? || admin? moderator? || admin?
end end


Expand Down
7 changes: 5 additions & 2 deletions app/models/log.rb
Expand Up @@ -7,10 +7,13 @@
# id :integer(4) not null, primary key # id :integer(4) not null, primary key
# account_id :integer(4) # account_id :integer(4)
# description :string(255) # 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 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 end
12 changes: 6 additions & 6 deletions app/views/users/_recent.html.haml
Expand Up @@ -11,18 +11,18 @@
- if current_account.amr? - if current_account.amr?
%li Karma&nbsp;: #{a.karma} %li Karma&nbsp;: #{a.karma}
%li Dernière connexion&nbsp;: #{a.current_sign_in_at ? l(@user.account.current_sign_in_at) : "-"} %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 %h2 Interdire de tribune
%ul %ul
%li= button_to "24h", moderation_blacklist_index_path(:nb_days => 1, :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_blacklist_index_path(:nb_days => 2, :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_blacklist_index_path(:nb_days => 7, :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_blacklist_index_path(:nb_days => 30, :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? - if @user.account.logs.any?
%h2 Historique %h2 Historique
%ul %ul
= list_of(@user.account.logs) do |log| = list_of(@user.account.logs) do |log|
#{l log.created_at} - #{log.description} #{l log.created_at} - #{log.user.try :name} - #{log.description}
%ul %ul
%li= link_to "Derniers journaux", user_path(@user) %li= link_to "Derniers journaux", user_path(@user)
%li= link_to "Dernières dépêches", news_user_path(@user) %li= link_to "Dernières dépêches", news_user_path(@user)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -113,7 +113,7 @@
post :refuse, :on => :member post :refuse, :on => :member
post :accept, :on => :member post :accept, :on => :member
end end
resources :blacklist, :only => [:create] resources :plonk, :only => [:create]
end end


# Admin # Admin
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20110927231326_add_user_id_to_logs.rb
@@ -0,0 +1,6 @@
class AddUserIdToLogs < ActiveRecord::Migration
def change
add_column :logs, :user_id, :integer
remove_column :logs, :updated_at
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "accounts", :force => true do |t|
t.integer "user_id" t.integer "user_id"
Expand Down Expand Up @@ -127,7 +127,7 @@
t.integer "account_id" t.integer "account_id"
t.string "description" t.string "description"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.integer "user_id"
end end


add_index "logs", ["account_id"], :name => "index_logs_on_account_id" add_index "logs", ["account_id"], :name => "index_logs_on_account_id"
Expand Down

0 comments on commit e7ced91

Please sign in to comment.