Commit 4f2b7940 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'sh-redact-links-remove-circular-dependency' into 'master'

Remove circular dependency on Redactable in migration

See merge request gitlab-org/gitlab-ee!8387
parents c756b66b 057c094d
# frozen_string_literal: true # frozen_string_literal: true
# rubocop:disable Style/Documentation # rubocop:disable Style/Documentation
require_relative 'redact_links/redactable'
module Gitlab module Gitlab
module BackgroundMigration module BackgroundMigration
class RedactLinks class RedactLinks
prepend EE::Gitlab::BackgroundMigration::RedactLinks prepend EE::Gitlab::BackgroundMigration::RedactLinks
module Redactable
extend ActiveSupport::Concern
def redact_field!(field)
self[field].gsub!(%r{/sent_notifications/\h{32}/unsubscribe}, '/sent_notifications/REDACTED/unsubscribe')
if self.changed?
self.update_columns(field => self[field],
"#{field}_html" => nil)
end
end
end
class Note < ActiveRecord::Base class Note < ActiveRecord::Base
include EachBatch include EachBatch
include Redactable include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'notes' self.table_name = 'notes'
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
...@@ -29,7 +18,7 @@ module Gitlab ...@@ -29,7 +18,7 @@ module Gitlab
class Issue < ActiveRecord::Base class Issue < ActiveRecord::Base
include EachBatch include EachBatch
include Redactable include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'issues' self.table_name = 'issues'
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
...@@ -37,7 +26,7 @@ module Gitlab ...@@ -37,7 +26,7 @@ module Gitlab
class MergeRequest < ActiveRecord::Base class MergeRequest < ActiveRecord::Base
include EachBatch include EachBatch
include Redactable include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'merge_requests' self.table_name = 'merge_requests'
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
...@@ -45,7 +34,7 @@ module Gitlab ...@@ -45,7 +34,7 @@ module Gitlab
class Snippet < ActiveRecord::Base class Snippet < ActiveRecord::Base
include EachBatch include EachBatch
include Redactable include ::Gitlab::BackgroundMigration::RedactLinks::Redactable
self.table_name = 'snippets' self.table_name = 'snippets'
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
......
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
class RedactLinks
module Redactable
extend ActiveSupport::Concern
def redact_field!(field)
self[field].gsub!(%r{/sent_notifications/\h{32}/unsubscribe}, '/sent_notifications/REDACTED/unsubscribe')
if self.changed?
self.update_columns(field => self[field],
"#{field}_html" => nil)
end
end
end
end
end
end
...@@ -4,6 +4,7 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141 ...@@ -4,6 +4,7 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:issues) { table(:issues) } let(:issues) { table(:issues) }
let(:epics) { table(:epics) }
let(:notes) { table(:notes) } let(:notes) { table(:notes) }
let(:snippets) { table(:snippets) } let(:snippets) { table(:snippets) }
let(:users) { table(:users) } let(:users) { table(:users) }
...@@ -41,6 +42,12 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141 ...@@ -41,6 +42,12 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
snippets.create(params) snippets.create(params)
end end
def create_epic(id, params)
params.merge!(id: id, iid: id, title: "epic#{id}", title_html: "epic#{id}", author_id: user.id, group_id: namespace.id)
epics.create(params)
end
def create_resource(model, id, params) def create_resource(model, id, params)
send("create_#{model.name.underscore}", id, params) send("create_#{model.name.underscore}", id, params)
end end
...@@ -93,4 +100,11 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141 ...@@ -93,4 +100,11 @@ describe Gitlab::BackgroundMigration::RedactLinks, :migration, schema: 201810141
let(:field) { :description } let(:field) { :description }
end end
end end
context 'resource is Epic' do
it_behaves_like 'redactable resource' do
let(:model) { Epic }
let(:field) { :description }
end
end
end end
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