diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-28 20:38:32 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-28 09:46:59 +0300 |
commit | 924a6b7d33a245845071894de8d46d77bd44b52e (patch) | |
tree | 1771c05a31b1bf41784c33d1bb1aa2e19ef25268 /app/finders/access_requests_finder.rb | |
parent | 9a28756c07f0f73bd134385bf11b44527ee81631 (diff) |
New AccessRequestsFinder
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/finders/access_requests_finder.rb')
-rw-r--r-- | app/finders/access_requests_finder.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/finders/access_requests_finder.rb b/app/finders/access_requests_finder.rb new file mode 100644 index 00000000000..78fb7627741 --- /dev/null +++ b/app/finders/access_requests_finder.rb @@ -0,0 +1,29 @@ +class AccessRequestsFinder + attr_accessor :source + + # Arguments: + # source - a Group or Project + def initialize(source) + @source = source + end + + def execute(current_user, raise_error: false) + if cannot_see_access_requests?(current_user) + raise Gitlab::Access::AccessDeniedError if raise_error + + return [] + end + + source.requesters + end + + def execute!(current_user) + execute(current_user, raise_error: true) + end + + private + + def cannot_see_access_requests?(current_user) + !source || !current_user || !current_user.can?(:"admin_#{source.class.to_s.underscore}", source) + end +end |