blob: e12706dc9a38128247fb83abb8b5cb73fd55f234 (
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
|
module Permissions
module OwnedModel
def create_permitted?
acting_user.signed_up?
end
def update_permitted?
owned?
end
def edit_permitted?(field)
owned_soft?
end
def destroy_permitted?
owned?
end
def view_permitted?(field)
owned_soft?
end
protected
def owned?
owner_is?(acting_user) and !owner_changed?
end
def owned_soft?
owner_is?(acting_user)
end
def must_be_owned
errors.add(:owner, "must be current_user") unless owned?
end
def included
validate_presence_of :owner
end
end
end
def owned_model(owner_class)
belongs_to :owner, :class_name => owner_class, :creator => true
never_show :owner
attr_readonly :owner
include Permissions::OwnedModel
end
|