Skip to content

Commit

Permalink
Only attempt to sync users who have an access token (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Nov 21, 2018
1 parent 94e2b86 commit 6fec09d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def github_client
if app_installation.present?
Octobox.installation_client(app_installation.github_id)
else
users.first&.subject_client
users.with_access_token.first&.subject_client
end
end

Expand All @@ -168,8 +168,8 @@ def self.extract_full_name(url)
end

def involved_user_ids
ids = users.not_recently_synced.pluck(:id)
ids += repository.users.not_recently_synced.pluck(:id) if repository.present?
ids = users.with_access_token.not_recently_synced.pluck(:id)
ids += repository.users.with_access_token.not_recently_synced.pluck(:id) if repository.present?
ids.uniq
end

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class User < ApplicationRecord
validates_with PersonalAccessTokenValidator

scope :not_recently_synced, -> { where('last_synced_at < ?', 5.minutes.ago) }
scope :with_access_token, -> { where.not(encrypted_access_token: nil) }

def admin?
Octobox.config.github_admin_ids.include?(github_id.to_s)
Expand Down

0 comments on commit 6fec09d

Please sign in to comment.