diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-24 16:58:32 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-24 16:58:32 +0100 |
commit | 81ba3f9177fcfd76f6b3b715c572ce4920398345 (patch) | |
tree | bfcefba5a558d69051bf67f2cef2a259c0928942 /lib/api/helpers.rb | |
parent | 4f5ed812325845f263fc9b566651c1179b5c24bc (diff) | |
download | gitlab-ce-81ba3f9177fcfd76f6b3b715c572ce4920398345.tar.gz |
API: Introduce `#find_group!` which also check access permission22373-reduce-queries-in-api-helpers-find_project
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 42f4c2ccf9d..0d3ddb89dc3 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -105,7 +105,15 @@ module API end def find_group(id) - group = Group.find_by(path: id) || Group.find_by(id: id) + if id =~ /^\d+$/ + Group.find_by(id: id) + else + Group.find_by(path: id) + end + end + + def find_group!(id) + group = find_group(id) if can?(current_user, :read_group, group) group |