2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2021-03-16 08:59:32 +00:00
|
|
|
class MentionInit < ActiveRecord::Migration[5.2]
|
|
|
|
def change
|
|
|
|
|
|
|
|
# return if it's a new setup
|
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
|
|
|
|
|
|
|
create_table :mentions do |t|
|
|
|
|
t.references :mentionable, polymorphic: true, null: false
|
|
|
|
t.column :user_id, :integer, null: false
|
|
|
|
t.column :updated_by_id, :integer, null: false
|
|
|
|
t.column :created_by_id, :integer, null: false
|
|
|
|
t.timestamps limit: 3, null: false
|
|
|
|
end
|
|
|
|
add_index :mentions, %i[mentionable_id mentionable_type user_id], unique: true, name: 'index_mentions_mentionable_user'
|
|
|
|
add_foreign_key :mentions, :users, column: :created_by_id
|
|
|
|
add_foreign_key :mentions, :users, column: :updated_by_id
|
|
|
|
add_foreign_key :mentions, :users, column: :user_id
|
|
|
|
|
|
|
|
Mention.reset_column_information
|
|
|
|
create_overview
|
2021-03-25 22:34:32 +00:00
|
|
|
update_users
|
2021-03-16 08:59:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_overview
|
|
|
|
Overview.create_if_not_exists(
|
2021-03-22 13:25:43 +00:00
|
|
|
name: 'My subscribed Tickets',
|
|
|
|
link: 'my_subscribed_tickets',
|
2021-03-16 08:59:32 +00:00
|
|
|
prio: 1025,
|
|
|
|
role_ids: Role.with_permissions('ticket.agent').pluck(:id),
|
|
|
|
condition: { 'ticket.mention_user_ids'=>{ 'operator' => 'is', 'pre_condition' => 'current_user.id', 'value' => '', 'value_completion' => '' } },
|
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
|
|
|
direction: 'ASC',
|
|
|
|
},
|
|
|
|
view: {
|
|
|
|
d: %w[title customer group created_at],
|
|
|
|
s: %w[title customer group created_at],
|
|
|
|
m: %w[number title customer group created_at],
|
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-03-25 22:34:32 +00:00
|
|
|
def update_users
|
2021-03-16 08:59:32 +00:00
|
|
|
User.with_permissions('ticket.agent').each do |user|
|
|
|
|
next if user.preferences.blank?
|
|
|
|
next if user.preferences['notification_config'].blank?
|
|
|
|
next if user.preferences['notification_config']['matrix'].blank?
|
|
|
|
|
2021-03-25 22:34:32 +00:00
|
|
|
update_matrix(user.preferences['notification_config']['matrix'])
|
|
|
|
|
|
|
|
user.save!
|
2021-03-16 08:59:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-25 22:34:32 +00:00
|
|
|
def update_matrix(matrix)
|
|
|
|
matrix_type_defaults.each do |type, default|
|
|
|
|
matrix[type] ||= {}
|
|
|
|
matrix[type]['criteria'] ||= {}
|
|
|
|
matrix[type]['criteria']['subscribed'] = default
|
2021-03-16 08:59:32 +00:00
|
|
|
end
|
2021-03-25 22:34:32 +00:00
|
|
|
end
|
2021-03-16 08:59:32 +00:00
|
|
|
|
2021-03-25 22:34:32 +00:00
|
|
|
def matrix_type_defaults
|
|
|
|
@matrix_type_defaults ||= {
|
|
|
|
'create' => true,
|
|
|
|
'update' => true,
|
|
|
|
'reminder_reached' => false,
|
|
|
|
'escalation' => false,
|
|
|
|
}
|
2021-03-16 08:59:32 +00:00
|
|
|
end
|
|
|
|
end
|