end
end
+ class AlreadyLockedError < StandardError
+ def http_status
+ 403
+ end
+ end
+
class UnauthorizedError < StandardError
def http_status
401
api_column_map
end
- # Return nil if current user is not allowed to see the list of
- # writers. Otherwise, return a list of user_ and group_uuids with
- # write permission. (If not returning nil, current_user is always in
- # the list because can_manage permission is needed to see the list
- # of writers.)
+ # If current user can manage the object, return an array of uuids of
+ # users and groups that have permission to write the object. The
+ # first two elements are always [self.owner_uuid, current user's
+ # uuid].
+ #
+ # If current user can write but not manage the object, return
+ # [self.owner_uuid, current user's uuid].
+ #
+ # If current user cannot write this object, just return
+ # [self.owner_uuid].
def writable_by
unless (owner_uuid == current_user.uuid or
current_user.is_admin or
- current_user.groups_i_can(:manage).index(owner_uuid))
- return nil
+ (current_user.groups_i_can(:manage) & [uuid, owner_uuid]).any?)
+ if ((current_user.groups_i_can(:write) + [current_user.uuid]) &
+ [uuid, owner_uuid]).any?
+ return [owner_uuid, current_user.uuid]
+ else
+ return [owner_uuid]
+ end
end
[owner_uuid, current_user.uuid] + permissions.collect do |p|
if ['can_write', 'can_manage'].index p.name
attributes
end
- def has_permission? perm_type, target_uuid
- Link.where(link_class: "permission",
- name: perm_type,
- tail_uuid: uuid,
- head_uuid: target_uuid).any?
- end
-
protected
def ensure_ownership_path_leads_to_user
"_____-#{uuid_prefix}-_______________"
end
+ def self.uuid_regex
+ %r/[a-z0-9]{5}-#{uuid_prefix}-[a-z0-9]{15}/
+ end
+
def ensure_valid_uuids
specials = [system_user_uuid]
log = Log.new(event_type: event_type).fill_object(self)
yield log
log.save!
- connection.execute "NOTIFY logs, '#{log.id}'"
log_start_state
end