summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers.rb10
-rw-r--r--lib/api/helpers/internal_helpers.rb11
2 files changed, 13 insertions, 8 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 7f436b69091..c4f81443282 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -33,6 +33,10 @@ module API
end
# rubocop:disable Cop/ModuleWithInstanceVariables
+ # We can't rewrite this with StrongMemoize because `sudo!` would
+ # actually write to `@current_user`, and `sudo?` would immediately
+ # call `current_user` again which reads from `@current_user`.
+ # We should rewrite this in a way that using StrongMemoize is possible
def current_user
return @current_user if defined?(@current_user)
@@ -46,6 +50,7 @@ module API
@current_user
end
+ # rubocop:enable Cop/ModuleWithInstanceVariables
def sudo?
initial_current_user != current_user
@@ -394,6 +399,7 @@ module API
private
+ # rubocop:disable Cop/ModuleWithInstanceVariables
def initial_current_user
return @initial_current_user if defined?(@initial_current_user)
@@ -403,8 +409,8 @@ module API
unauthorized!
end
end
+ # rubocop:enable Cop/ModuleWithInstanceVariables
- # rubocop:disable Cop/ModuleWithInstanceVariables
def sudo!
return unless sudo_identifier
@@ -423,7 +429,7 @@ module API
sudoed_user = find_user(sudo_identifier)
not_found!("User with ID or username '#{sudo_identifier}'") unless sudoed_user
- @current_user = sudoed_user
+ @current_user = sudoed_user # rubocop:disable Cop/ModuleWithInstanceVariables
end
def sudo_identifier
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index 0d57c822578..e2077d33b9f 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -8,16 +8,14 @@ module API
attr_reader :redirected_path
- # rubocop:disable Cop/ModuleWithInstanceVariables
def wiki?
- set_project unless defined?(@wiki)
- @wiki
+ set_project unless defined?(@wiki) # rubocop:disable Cop/ModuleWithInstanceVariables
+ @wiki # rubocop:disable Cop/ModuleWithInstanceVariables
end
- # rubocop:disable Cop/ModuleWithInstanceVariables
def project
- set_project unless defined?(@project)
- @project
+ set_project unless defined?(@project) # rubocop:disable Cop/ModuleWithInstanceVariables
+ @project # rubocop:disable Cop/ModuleWithInstanceVariables
end
def ssh_authentication_abilities
@@ -78,6 +76,7 @@ module API
@project, @wiki, @redirected_path = Gitlab::RepoPath.parse(params[:project])
end
end
+ # rubocop:enable Cop/ModuleWithInstanceVariables
# Project id to pass between components that don't share/don't have
# access to the same filesystem mounts