Maintenance: Removed incomplete/obsolete TextModules and Templates references implementation to single User.
This commit is contained in:
parent
f766dc7164
commit
acd98bd214
6 changed files with 12 additions and 18 deletions
|
@ -3,8 +3,6 @@
|
||||||
class Template < ApplicationModel
|
class Template < ApplicationModel
|
||||||
include ChecksClientNotification
|
include ChecksClientNotification
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
|
||||||
|
|
||||||
store :options
|
store :options
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ class TextModule < ApplicationModel
|
||||||
include ChecksHtmlSanitized
|
include ChecksHtmlSanitized
|
||||||
include CanCsvImport
|
include CanCsvImport
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :content, presence: true
|
validates :content, presence: true
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ class User < ApplicationModel
|
||||||
has_many :tokens, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy
|
has_many :tokens, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy
|
||||||
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy
|
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy
|
||||||
has_many :online_notifications, dependent: :destroy
|
has_many :online_notifications, dependent: :destroy
|
||||||
has_many :templates, dependent: :destroy
|
|
||||||
has_many :taskbars, dependent: :destroy
|
has_many :taskbars, dependent: :destroy
|
||||||
has_many :user_devices, dependent: :destroy
|
has_many :user_devices, dependent: :destroy
|
||||||
has_one :chat_agent_created_by, class_name: 'Chat::Agent', foreign_key: :created_by_id, dependent: :destroy, inverse_of: :created_by
|
has_one :chat_agent_created_by, class_name: 'Chat::Agent', foreign_key: :created_by_id, dependent: :destroy, inverse_of: :created_by
|
||||||
|
@ -34,7 +33,6 @@ class User < ApplicationModel
|
||||||
has_many :karma_user, class_name: 'Karma::User', dependent: :destroy
|
has_many :karma_user, class_name: 'Karma::User', dependent: :destroy
|
||||||
has_many :karma_activity_logs, class_name: 'Karma::ActivityLog', dependent: :destroy
|
has_many :karma_activity_logs, class_name: 'Karma::ActivityLog', dependent: :destroy
|
||||||
has_many :cti_caller_ids, class_name: 'Cti::CallerId', dependent: :destroy
|
has_many :cti_caller_ids, class_name: 'Cti::CallerId', dependent: :destroy
|
||||||
has_many :text_modules, dependent: :destroy
|
|
||||||
has_many :customer_tickets, class_name: 'Ticket', foreign_key: :customer_id, dependent: :destroy, inverse_of: :customer
|
has_many :customer_tickets, class_name: 'Ticket', foreign_key: :customer_id, dependent: :destroy, inverse_of: :customer
|
||||||
has_many :owner_tickets, class_name: 'Ticket', foreign_key: :owner_id, inverse_of: :owner
|
has_many :owner_tickets, class_name: 'Ticket', foreign_key: :owner_id, inverse_of: :owner
|
||||||
has_many :created_recent_views, class_name: 'RecentView', foreign_key: :created_by_id, dependent: :destroy, inverse_of: :created_by
|
has_many :created_recent_views, class_name: 'RecentView', foreign_key: :created_by_id, dependent: :destroy, inverse_of: :created_by
|
||||||
|
|
|
@ -378,7 +378,6 @@ class CreateTicket < ActiveRecord::Migration[4.2]
|
||||||
add_foreign_key :postmaster_filters, :users, column: :updated_by_id
|
add_foreign_key :postmaster_filters, :users, column: :updated_by_id
|
||||||
|
|
||||||
create_table :text_modules do |t|
|
create_table :text_modules do |t|
|
||||||
t.references :user, null: true
|
|
||||||
t.column :name, :string, limit: 250, null: false
|
t.column :name, :string, limit: 250, null: false
|
||||||
t.column :keywords, :string, limit: 500, null: true
|
t.column :keywords, :string, limit: 500, null: true
|
||||||
t.column :content, :text, limit: 10.megabytes + 1, null: false
|
t.column :content, :text, limit: 10.megabytes + 1, null: false
|
||||||
|
@ -389,9 +388,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
|
||||||
t.column :created_by_id, :integer, null: false
|
t.column :created_by_id, :integer, null: false
|
||||||
t.timestamps limit: 3, null: false
|
t.timestamps limit: 3, null: false
|
||||||
end
|
end
|
||||||
add_index :text_modules, [:user_id]
|
|
||||||
add_index :text_modules, [:name]
|
add_index :text_modules, [:name]
|
||||||
add_foreign_key :text_modules, :users
|
|
||||||
add_foreign_key :text_modules, :users, column: :created_by_id
|
add_foreign_key :text_modules, :users, column: :created_by_id
|
||||||
add_foreign_key :text_modules, :users, column: :updated_by_id
|
add_foreign_key :text_modules, :users, column: :updated_by_id
|
||||||
|
|
||||||
|
@ -405,16 +402,13 @@ class CreateTicket < ActiveRecord::Migration[4.2]
|
||||||
add_foreign_key :text_modules_groups, :groups
|
add_foreign_key :text_modules_groups, :groups
|
||||||
|
|
||||||
create_table :templates do |t|
|
create_table :templates do |t|
|
||||||
t.references :user, null: true
|
|
||||||
t.column :name, :string, limit: 250, null: false
|
t.column :name, :string, limit: 250, null: false
|
||||||
t.column :options, :text, limit: 10.megabytes + 1, null: false
|
t.column :options, :text, limit: 10.megabytes + 1, null: false
|
||||||
t.column :updated_by_id, :integer, null: false
|
t.column :updated_by_id, :integer, null: false
|
||||||
t.column :created_by_id, :integer, null: false
|
t.column :created_by_id, :integer, null: false
|
||||||
t.timestamps limit: 3, null: false
|
t.timestamps limit: 3, null: false
|
||||||
end
|
end
|
||||||
add_index :templates, [:user_id]
|
|
||||||
add_index :templates, [:name]
|
add_index :templates, [:name]
|
||||||
add_foreign_key :templates, :users
|
|
||||||
add_foreign_key :templates, :users, column: :created_by_id
|
add_foreign_key :templates, :users, column: :created_by_id
|
||||||
add_foreign_key :templates, :users, column: :updated_by_id
|
add_foreign_key :templates, :users, column: :updated_by_id
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class MaintenanceAssociationsCleanup < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.exists?(name: 'system_init_done')
|
||||||
|
|
||||||
|
remove_reference :templates, :user, index: true, foreign_key: true
|
||||||
|
remove_reference :text_modules, :user, index: true, foreign_key: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -835,7 +835,7 @@ RSpec.describe User, type: :model do
|
||||||
'OnlineNotification' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'OnlineNotification' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'Ticket' =>
|
'Ticket' =>
|
||||||
{ 'created_by_id' => 0, 'updated_by_id' => 0, 'owner_id' => 1, 'customer_id' => 3 },
|
{ 'created_by_id' => 0, 'updated_by_id' => 0, 'owner_id' => 1, 'customer_id' => 3 },
|
||||||
'Template' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Template' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'Avatar' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Avatar' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'Scheduler' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Scheduler' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'Chat' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Chat' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
|
@ -873,7 +873,7 @@ RSpec.describe User, type: :model do
|
||||||
'Overview' => { 'created_by_id' => 1, 'updated_by_id' => 0 },
|
'Overview' => { 'created_by_id' => 1, 'updated_by_id' => 0 },
|
||||||
'ActivityStream' => { 'created_by_id' => 0 },
|
'ActivityStream' => { 'created_by_id' => 0 },
|
||||||
'StatsStore' => { 'created_by_id' => 0 },
|
'StatsStore' => { 'created_by_id' => 0 },
|
||||||
'TextModule' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'TextModule' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'Calendar' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Calendar' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
'UserGroup' => { 'user_id' => 1 },
|
'UserGroup' => { 'user_id' => 1 },
|
||||||
'Signature' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
'Signature' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||||
|
@ -882,12 +882,10 @@ RSpec.describe User, type: :model do
|
||||||
# delete objects
|
# delete objects
|
||||||
token = create(:token, user: user)
|
token = create(:token, user: user)
|
||||||
online_notification = create(:online_notification, user: user)
|
online_notification = create(:online_notification, user: user)
|
||||||
template = create(:template, :dummy_data, user: user)
|
|
||||||
taskbar = create(:taskbar, user: user)
|
taskbar = create(:taskbar, user: user)
|
||||||
user_device = create(:user_device, user: user)
|
user_device = create(:user_device, user: user)
|
||||||
karma_activity_log = create(:karma_activity_log, user: user)
|
karma_activity_log = create(:karma_activity_log, user: user)
|
||||||
cti_caller_id = create(:cti_caller_id, user: user)
|
cti_caller_id = create(:cti_caller_id, user: user)
|
||||||
text_module = create(:text_module, user: user)
|
|
||||||
authorization = create(:twitter_authorization, user: user)
|
authorization = create(:twitter_authorization, user: user)
|
||||||
recent_view = create(:recent_view, created_by: user)
|
recent_view = create(:recent_view, created_by: user)
|
||||||
avatar = create(:avatar, o_id: user.id)
|
avatar = create(:avatar, o_id: user.id)
|
||||||
|
@ -918,12 +916,10 @@ RSpec.describe User, type: :model do
|
||||||
|
|
||||||
expect { token.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { token.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { online_notification.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { online_notification.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { template.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
||||||
expect { taskbar.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { taskbar.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { user_device.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { user_device.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { karma_activity_log.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { karma_activity_log.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { cti_caller_id.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { cti_caller_id.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { text_module.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
|
||||||
expect { authorization.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { authorization.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { recent_view.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { recent_view.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
expect { avatar.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
expect { avatar.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||||
|
|
Loading…
Reference in a new issue