1 class UserBlock < ActiveRecord::Base
2 validate :moderator_permissions
4 belongs_to :user, :class_name => "User", :foreign_key => :user_id
5 belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
6 belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id
8 PERIODS = USER_BLOCK_PERIODS
11 # returns true if the block is currently active (i.e: the user can't
14 needs_view or ends_at > Time.now.getutc
18 # revokes the block, allowing the user to use the API again. the argument
19 # is the user object who is revoking the ban.
21 update_attributes({ :ends_at => Time.now.getutc(),
22 :revoker_id => revoker.id,
23 :needs_view => false })
28 # validate that only moderators are allowed to change the
29 # block. this should be caught and dealt with in the controller,
30 # but i've also included it here just in case.
31 def moderator_permissions
32 errors.add_to_base(I18n.t('user_block.model.non_moderator_update')) if creator_id_changed? and !creator.moderator?
33 errors.add_to_base(I18n.t('user_block.model.non_moderator_revoke')) unless revoker_id.nil? or revoker.moderator?