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
validates :project, presence: true
def stringified_credentials
JSON[credentials.to_json]
# TODO: This doesnt play well with attr_encrypted. Perhaps consider extending Marshall and specify a different Marshaller
before_validation :symbolize_credentials
def symbolize_credentials
return if credentials.blank?
credentials.deep_symbolize_keys!
end
end
......@@ -51,9 +51,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
def encrypt_data(data_hash, credentials_keys)
new_data_hash = {}
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
new_data_hash
new_data_hash.deep_symbolize_keys
end
def in_transaction
......
......@@ -11,7 +11,7 @@
#
# 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
enable_extension "plpgsql"
......@@ -44,7 +44,6 @@ ActiveRecord::Schema.define(version: 20160331133914) do
t.datetime "updated_at"
t.string "home_page_url"
t.integer "default_branch_protection", default: 2
t.boolean "twitter_sharing_enabled", default: true
t.text "restricted_visibility_levels"
t.boolean "version_check_enabled", default: true
t.integer "max_attachment_size", default: 10, null: false
......@@ -417,9 +416,9 @@ ActiveRecord::Schema.define(version: 20160331133914) do
t.string "state"
t.integer "iid"
t.integer "updated_by_id"
t.integer "moved_to_id"
t.boolean "confidential", default: false
t.datetime "deleted_at"
t.integer "moved_to_id"
end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......
......@@ -6,10 +6,10 @@ module Gitlab
attr_reader :consumer, :api
def self.from_project(project)
credentials = project.import_data.stringified_credentials if project.import_data
if defined?(credentials) && credentials['bb_session']
token = credentials['bb_session']['bitbucket_access_token']
token_secret = credentials['bb_session']['bitbucket_access_token_secret']
credentials = project.import_data if project.import_data
if credentials && credentials[:bb_session]
token = credentials[:bb_session][:bitbucket_access_token]
token_secret = credentials[:bb_session][:bitbucket_access_token_secret]
new(token, token_secret)
else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
......
......@@ -25,7 +25,7 @@ module Gitlab
import_data = project.import_data
# 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
project
......
......@@ -18,7 +18,7 @@ module Gitlab
def execute
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)
@categories = client.categories
......@@ -31,7 +31,7 @@ module Gitlab
private
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
def user_map
......@@ -240,8 +240,8 @@ module Gitlab
end
def build_attachment_url(rel_url)
uri = import_data_credentials['fb_session']['uri']
token = import_data_credentials['fb_session']['token']
uri = import_data_credentials[:fb_session][:uri]
token = import_data_credentials[:fb_session][:token]
"#{uri}/#{rel_url}&token=#{token}"
end
......
......@@ -28,7 +28,7 @@ module Gitlab
import_data.data = { 'repo' => repo.raw_data, 'user_map' => user_map }
# 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
project
......
......@@ -5,9 +5,9 @@ module Gitlab
def initialize(project)
@project = project
credentials = import_data.stringified_credentials
if credentials && credentials["password"]
@client = Client.new(credentials["password"])
credentials = import_data
if credentials && credentials[:password]
@client = Client.new(credentials[:password])
@formatter = Gitlab::ImportFormatter.new
else
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