Permalink
Browse files

Prevent owned/starred gist collisions

  • Loading branch information...
rwdaigle committed Nov 24, 2012
1 parent d8b87c5 commit 158d462bec3b4bab4017351c40f6d8b9462ca6e1
Showing with 5 additions and 4 deletions.
  1. +1 −1 app/models/gist.rb
  2. +1 −1 app/models/gist_fetcher.rb
  3. +3 −2 app/models/gist_file.rb
View
@@ -43,7 +43,7 @@ def import(user_id, gh_gist, overrides = {})
gh_created_at: gh_gist.created_at, gh_updated_at: gh_gist.updated_at
}.merge(overrides)
- if(existing_gist = where(gh_id: gh_id).first)
+ if(existing_gist = user.gists.where(gh_id: gh_id).first)
log({ns: self, fn: __method__, measure: true, at: 'gist-imported'}, user, existing_gist)
existing_gist.update_attributes(attributes)
existing_gist
@@ -46,7 +46,7 @@ def fetch_gist_files(user_id, gh_gist_id)
user = User.find(user_id)
log({ns: self, fn: __method__, measure: true, gh_gist_id: gh_gist_id}, user) do
gh_client(user) do |gh|
- GistFile.import(gh.gist(gh_gist_id))
+ GistFile.import(user_id, gh.gist(gh_gist_id))
end
end
end
View
@@ -6,9 +6,10 @@ class GistFile < ActiveRecord::Base
class << self
- def import(gh_gist)
+ def import(user_id, gh_gist)
- gist = Gist.where(gh_id: gh_gist['id']).first
+ user = User.find(user_id)
+ gist = user.gists.where(gh_id: gh_gist['id']).first
gh_gist.files.each do |filename, gh_file|

0 comments on commit 158d462

Please sign in to comment.