1 class Link < OrvosModel
4 include CommonApiTemplate
5 serialize :properties, Hash
6 before_create :permission_to_attach_to_objects
7 before_update :permission_to_attach_to_objects
9 api_accessible :superuser, :extend => :common do |t|
26 def permission_to_attach_to_objects
27 # Anonymous users cannot write links
28 return false if !current_user
30 # All users can write links that don't affect permissions
31 return true if self.link_class != 'permission'
33 # Administrators can grant permissions
34 return true if current_user.is_admin
36 # All users can grant permissions on objects they own
37 head_obj = self.class.
38 kind_class(self.head_kind).
39 where('uuid=?',head_uuid).
42 return true if head_obj.owner == current_user.uuid
45 # Users with "can_grant" permission on an object can grant
46 # permissions on that object
47 has_grant_permission = self.class.
48 where('link_class=? AND name=? AND tail_uuid=? AND head_uuid=?',
49 'permission', 'can_grant', current_user.uuid, self.head_uuid).
51 return true if has_grant_permission