2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'carrierwave/orm/activerecord'
|
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
class ProjectImportData < ApplicationRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
belongs_to :project, inverse_of: :import_data
|
2016-06-02 11:05:42 +05:30
|
|
|
attr_encrypted :credentials,
|
2018-11-08 19:23:39 +05:30
|
|
|
key: Settings.attr_encrypted_db_key_base,
|
2016-06-02 11:05:42 +05:30
|
|
|
marshal: true,
|
|
|
|
encode: true,
|
2016-06-16 23:09:34 +05:30
|
|
|
mode: :per_attribute_iv_and_salt,
|
2016-08-24 12:49:21 +05:30
|
|
|
insecure_mode: true,
|
2016-06-16 23:09:34 +05:30
|
|
|
algorithm: 'aes-256-cbc'
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
serialize :data, JSON # rubocop:disable Cop/ActiveRecordSerialize
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
validates :project, presence: true
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
before_validation :symbolize_credentials
|
|
|
|
|
|
|
|
def symbolize_credentials
|
|
|
|
# bang doesn't work here - attr_encrypted makes it not to work
|
|
|
|
self.credentials = self.credentials.deep_symbolize_keys unless self.credentials.blank?
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
def merge_data(hash)
|
|
|
|
self.data = data.to_h.merge(hash) unless hash.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_credentials(hash)
|
|
|
|
self.credentials = credentials.to_h.merge(hash) unless hash.empty?
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
def clear_credentials
|
|
|
|
self.credentials = {}
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|