summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-24 14:10:55 +0100
committerDouwe Maan <douwe@gitlab.com>2015-03-24 14:11:48 +0100
commit4830b2be5e076126f89d2c67bab94302559aa93a (patch)
treeed221ec195ff15ab3365701838e89b6698682ded /lib/api
parent2953e0d19b46a937ee9d84139adbc263c8e89757 (diff)
downloadgitlab-ce-4830b2be5e076126f89d2c67bab94302559aa93a.tar.gz
Refactor GitAccess to use instance variables.
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/internal.rb36
-rw-r--r--lib/api/merge_requests.rb3
2 files changed, 19 insertions, 20 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 753d0fcbd98..30bade74cf6 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -17,39 +17,37 @@ module API
post "/allowed" do
status 200
- actor = if params[:key_id]
- Key.find_by(id: params[:key_id])
- elsif params[:user_id]
- User.find_by(id: params[:user_id])
- end
+ actor =
+ if params[:key_id]
+ Key.find_by(id: params[:key_id])
+ elsif params[:user_id]
+ User.find_by(id: params[:user_id])
+ end
unless actor
return Gitlab::GitAccessStatus.new(false, 'No such user or key')
end
project_path = params[:project]
-
+
# Check for *.wiki repositories.
# Strip out the .wiki from the pathname before finding the
# project. This applies the correct project permissions to
# the wiki repository as well.
- access =
- if project_path.end_with?('.wiki')
- project_path.chomp!('.wiki')
- Gitlab::GitAccessWiki.new
- else
- Gitlab::GitAccess.new
- end
+ wiki = project_path.end_with?('.wiki')
+ project_path.chomp!('.wiki') if wiki
project = Project.find_with_namespace(project_path)
if project
- status = access.check(
- actor,
- params[:action],
- project,
- params[:changes]
- )
+ access =
+ if wiki
+ Gitlab::GitAccessWiki.new(actor, project)
+ else
+ Gitlab::GitAccess.new(actor, project)
+ end
+
+ status = access.check(params[:action], params[:changes])
end
if project && status && status.allowed?
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 25b7857f4b1..f3765f5ab03 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -178,7 +178,8 @@ module API
put ":id/merge_request/:merge_request_id/merge" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
- allowed = ::Gitlab::GitAccess.can_push_to_branch?(current_user, user_project, merge_request.target_branch)
+ allowed = ::Gitlab::GitAccess.new(current_user, user_project).
+ can_push_to_branch?(merge_request.target_branch)
if allowed
if merge_request.unchecked?