debian-mirror-gitlab/lib/api/entities/entity_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
528 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
module Entities
module EntityHelpers
def can_read(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "read_#{attr}".to_sym, yield(obj)) }
end
def can_destroy(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "destroy_#{attr}".to_sym, yield(obj)) }
end
2023-01-13 00:05:48 +05:30
def expose_restricted(attr, documentation: {}, &block)
expose attr, documentation: documentation, if: can_read(attr, &block)
2020-07-28 23:09:34 +05:30
end
end
end
end