Skip to content
Snippets Groups Projects
Commit 9803f748 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Refactor GitLab API usage to use either access_token or private_token

parent f7dbf6d1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -79,7 +79,7 @@ class ProjectsController < ApplicationController
 
def destroy
project.destroy
Network.new.disable_ci(project.gitlab_id, current_user.access_token)
Network.new.disable_ci(project.gitlab_id, current_user.authenticate_options)
 
EventService.new.remove_project(current_user, project)
 
Loading
Loading
Loading
Loading
@@ -82,11 +82,15 @@ class Network
end
end
 
def disable_ci(project_id, access_token)
query = "projects/#{project_id}/services/gitlab-ci.json?access_token=#{access_token}"
def disable_ci(project_id, api_opts)
opts = {
query: api_opts
}
query = "projects/#{project_id}/services/gitlab-ci.json?#{options.to_query}"
 
endpoint = File.join(url, API_PREFIX, query)
response = self.class.delete(endpoint, default_opts)
response = self.class.delete(endpoint, default_opts.merge(opts))
 
build_response(response)
end
Loading
Loading
Loading
Loading
@@ -87,12 +87,7 @@ ls -la
end
 
def from_gitlab(user, scope = :owned, options)
opts = if user.access_token
{ access_token: user.access_token }
else
{ private_token: user.private_token }
end
opts = user.authenticate_options
opts.merge! options
 
projects = Network.new.projects(opts.compact, scope)
Loading
Loading
Loading
Loading
@@ -60,12 +60,8 @@ class User
end
 
def can_manage_project?(project_gitlab_id)
opts = {
access_token: self.access_token,
}
Rails.cache.fetch(cache_key('manage', project_gitlab_id, sync_at)) do
!!Network.new.project_hooks(opts, project_gitlab_id)
!!Network.new.project_hooks(authenticate_options, project_gitlab_id)
end
end
 
Loading
Loading
@@ -81,15 +77,19 @@ class User
end
end
 
def authenticate_options
if attributes['access_token']
{ access_token: attributes['access_token'] }
else
{ private_token: attributes['private_token'] }
end
end
private
 
def project_info(project_gitlab_id)
opts = {
access_token: self.access_token,
}
Rails.cache.fetch(cache_key("project_info", project_gitlab_id, sync_at)) do
Network.new.project(opts, project_gitlab_id)
Network.new.project(authenticate_options, project_gitlab_id)
end
end
end
Loading
Loading
@@ -12,13 +12,7 @@ class CreateProjectService
project_url: project_route.gsub(":project_id", @project.id.to_s),
}
 
auth_opts = if current_user.access_token
{ access_token: current_user.access_token }
else
{ private_token: current_user.private_token }
end
unless Network.new.enable_ci(@project.gitlab_id, data, auth_opts)
unless Network.new.enable_ci(@project.gitlab_id, data, current_user.authenticate_options)
raise ActiveRecord::Rollback
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment