Commit 5e51fce4 authored by James Lopez's avatar James Lopez

some refactoring to symbolise keys across importers and left a TODO

parent 850180aa
...@@ -18,7 +18,11 @@ class ProjectImportData < ActiveRecord::Base ...@@ -18,7 +18,11 @@ class ProjectImportData < ActiveRecord::Base
validates :project, presence: true validates :project, presence: true
def stringified_credentials # TODO: This doesnt play well with attr_encrypted. Perhaps consider extending Marshall and specify a different Marshaller
JSON[credentials.to_json] before_validation :symbolize_credentials
def symbolize_credentials
return if credentials.blank?
credentials.deep_symbolize_keys!
end end
end end
...@@ -51,9 +51,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -51,9 +51,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
def encrypt_data(data_hash, credentials_keys) def encrypt_data(data_hash, credentials_keys)
new_data_hash = {} new_data_hash = {}
credentials_keys.each do |key| credentials_keys.each do |key|
new_data_hash[key] = data_hash.delete(key) if data_hash[key] new_data_hash[key.to_sym] = data_hash.delete(key) if data_hash[key]
end end
new_data_hash new_data_hash.deep_symbolize_keys
end end
def in_transaction def in_transaction
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160331133914) do ActiveRecord::Schema.define(version: 20160331223143) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -44,7 +44,6 @@ ActiveRecord::Schema.define(version: 20160331133914) do ...@@ -44,7 +44,6 @@ ActiveRecord::Schema.define(version: 20160331133914) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "home_page_url" t.string "home_page_url"
t.integer "default_branch_protection", default: 2 t.integer "default_branch_protection", default: 2
t.boolean "twitter_sharing_enabled", default: true
t.text "restricted_visibility_levels" t.text "restricted_visibility_levels"
t.boolean "version_check_enabled", default: true t.boolean "version_check_enabled", default: true
t.integer "max_attachment_size", default: 10, null: false t.integer "max_attachment_size", default: 10, null: false
...@@ -417,9 +416,9 @@ ActiveRecord::Schema.define(version: 20160331133914) do ...@@ -417,9 +416,9 @@ ActiveRecord::Schema.define(version: 20160331133914) do
t.string "state" t.string "state"
t.integer "iid" t.integer "iid"
t.integer "updated_by_id" t.integer "updated_by_id"
t.integer "moved_to_id"
t.boolean "confidential", default: false t.boolean "confidential", default: false
t.datetime "deleted_at" t.datetime "deleted_at"
t.integer "moved_to_id"
end end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......
...@@ -6,10 +6,10 @@ module Gitlab ...@@ -6,10 +6,10 @@ module Gitlab
attr_reader :consumer, :api attr_reader :consumer, :api
def self.from_project(project) def self.from_project(project)
credentials = project.import_data.stringified_credentials if project.import_data credentials = project.import_data if project.import_data
if defined?(credentials) && credentials['bb_session'] if credentials && credentials[:bb_session]
token = credentials['bb_session']['bitbucket_access_token'] token = credentials[:bb_session][:bitbucket_access_token]
token_secret = credentials['bb_session']['bitbucket_access_token_secret'] token_secret = credentials[:bb_session][:bitbucket_access_token_secret]
new(token, token_secret) new(token, token_secret)
else else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
import_data = project.import_data import_data = project.import_data
# merge! with a bang doesn't work here # merge! with a bang doesn't work here
import_data.credentials = import_data.credentials.merge("bb_session" => session_data) import_data.credentials = import_data.credentials.merge(bb_session: session_data)
import_data.save import_data.save
project project
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
def execute def execute
return true unless repo.valid? return true unless repo.valid?
client = Gitlab::FogbugzImport::Client.new(token: import_data_credentials['fb_session']['token'], uri: import_data_credentials['fb_session']['uri']) client = Gitlab::FogbugzImport::Client.new(token: import_data_credentials[:fb_session][:token], uri: import_data_credentials[:fb_session][:uri])
@cases = client.cases(@repo.id.to_i) @cases = client.cases(@repo.id.to_i)
@categories = client.categories @categories = client.categories
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
private private
def import_data_credentials def import_data_credentials
@import_data_credentials ||= project.import_data.stringified_credentials if project.import_data @import_data_credentials ||= project.import_data if project.import_data
end end
def user_map def user_map
...@@ -240,8 +240,8 @@ module Gitlab ...@@ -240,8 +240,8 @@ module Gitlab
end end
def build_attachment_url(rel_url) def build_attachment_url(rel_url)
uri = import_data_credentials['fb_session']['uri'] uri = import_data_credentials[:fb_session][:uri]
token = import_data_credentials['fb_session']['token'] token = import_data_credentials[:fb_session][:token]
"#{uri}/#{rel_url}&token=#{token}" "#{uri}/#{rel_url}&token=#{token}"
end end
......
...@@ -28,7 +28,7 @@ module Gitlab ...@@ -28,7 +28,7 @@ module Gitlab
import_data.data = { 'repo' => repo.raw_data, 'user_map' => user_map } import_data.data = { 'repo' => repo.raw_data, 'user_map' => user_map }
# merge! with a bang doesn't work here # merge! with a bang doesn't work here
import_data.credentials = import_data.credentials.merge('fb_session' => fb_session) import_data.credentials = import_data.credentials.merge(fb_session: fb_session)
import_data.save import_data.save
project project
......
...@@ -5,9 +5,9 @@ module Gitlab ...@@ -5,9 +5,9 @@ module Gitlab
def initialize(project) def initialize(project)
@project = project @project = project
credentials = import_data.stringified_credentials credentials = import_data
if credentials && credentials["password"] if credentials && credentials[:password]
@client = Client.new(credentials["password"]) @client = Client.new(credentials[:password])
@formatter = Gitlab::ImportFormatter.new @formatter = Gitlab::ImportFormatter.new
else else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment