blob: 00630f8f7b81a99fce137b51a0d569f7197eda41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
class Proxy < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
# Remeber nicks from when meeting took place
# May be useful when reading logs (if user changes nick)
council_member_nick :string
proxy_nick :string
timestamps
end
belongs_to :council_member, :class_name => 'User', :null => false
belongs_to :proxy, :class_name => 'User', :null => false
belongs_to :agenda, :null => false
validates_presence_of :council_member, :proxy, :agenda
validates_uniqueness_of :council_member_id, :scope => :agenda_id
validates_uniqueness_of :proxy_id, :scope => :agenda_id
validate :council_member_must_be_council_member
validate :proxy_must_not_be_council_member
# --- Permissions --- #
def create_permitted?
return false unless acting_user.council_member?
council_member_is?(acting_user)
end
def update_permitted?
false
end
def destroy_permitted?
return false if agenda.state == 'old'
council_member_is?(acting_user)
end
def view_permitted?(field)
true
end
before_create do |proxy|
proxy.council_member_nick = proxy.council_member.irc_nick
proxy.proxy_nick = proxy.proxy.irc_nick
end
protected
def council_member_must_be_council_member
return if council_member.nil?
errors.add(:council_member, 'must be council member') unless council_member.council_member?
end
def proxy_must_not_be_council_member
return if proxy.nil?
errors.add(:proxy, 'must not be council member') if proxy.council_member?
end
end
|