summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-08-29 13:05:07 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-09-15 12:21:00 -0500
commitcb85cf1f0a7047c485d7b29b2792b8965e270898 (patch)
treec681b20e379478042e718afa1473af209af126a0 /app
parent372be2d2e8fe8d607011aa7e2b2fca99eeea007d (diff)
downloadgitlab-ce-cb85cf1f0a7047c485d7b29b2792b8965e270898.tar.gz
Refactor LFS token logic to use a Redis key instead of a DB field, making it a 1 use only token.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/git_http_client_controller.rb3
-rw-r--r--app/helpers/lfs_helper.rb6
-rw-r--r--app/models/deploy_key.rb5
-rw-r--r--app/models/user.rb3
4 files changed, 7 insertions, 10 deletions
diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb
index 1e6709dc8eb..4dff1ce6568 100644
--- a/app/controllers/projects/git_http_client_controller.rb
+++ b/app/controllers/projects/git_http_client_controller.rb
@@ -132,8 +132,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
end
def lfs_deploy_key?
- key = user
- @lfs_deploy_key.present? && (key && key.projects.include?(project))
+ @lfs_deploy_key.present? && (user && user.projects.include?(project))
end
def verify_workhorse_api!
diff --git a/app/helpers/lfs_helper.rb b/app/helpers/lfs_helper.rb
index 0c867fc8741..2f5709a7395 100644
--- a/app/helpers/lfs_helper.rb
+++ b/app/helpers/lfs_helper.rb
@@ -25,7 +25,11 @@ module LfsHelper
def lfs_download_access?
return false unless project.lfs_enabled?
- project.public? || ci? || lfs_deploy_key? || (user && user.can?(:download_code, project))
+ return true if project.public?
+ return true if ci?
+ return true if lfs_deploy_key?
+
+ (user && user.can?(:download_code, project))
end
def lfs_upload_access?
diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb
index de51b63c120..2c525d4cd7a 100644
--- a/app/models/deploy_key.rb
+++ b/app/models/deploy_key.rb
@@ -1,12 +1,7 @@
class DeployKey < Key
- include TokenAuthenticatable
- add_authentication_token_field :lfs_token
-
has_many :deploy_keys_projects, dependent: :destroy
has_many :projects, through: :deploy_keys_projects
- before_save :ensure_lfs_token
-
scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) }
scope :are_public, -> { where(public: true) }
diff --git a/app/models/user.rb b/app/models/user.rb
index 94ae3911859..6996740eebd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -13,7 +13,6 @@ class User < ActiveRecord::Base
DEFAULT_NOTIFICATION_LEVEL = :participating
add_authentication_token_field :authentication_token
- add_authentication_token_field :lfs_token
default_value_for :admin, false
default_value_for(:external) { current_application_settings.user_default_external }
@@ -118,7 +117,7 @@ class User < ActiveRecord::Base
before_validation :set_public_email, if: ->(user) { user.public_email_changed? }
after_update :update_emails_with_primary_email, if: ->(user) { user.email_changed? }
- before_save :ensure_authentication_token, :ensure_lfs_token
+ before_save :ensure_authentication_token
before_save :ensure_external_user_rights
after_save :ensure_namespace_correct
after_initialize :set_projects_limit