* feat: add customizable signature position and separator options * fix: correct default value note for signatureSeparator and ensure reactivity * fix: correct watcher boolean conversion and add immediate ui_settings updates - Fix watchers to convert string props to boolean values for reactive refs - Add immediate event handlers for switch changes to update ui_settings in real-time - Ensure proper synchronization between switch states and user.ui_settings Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: split signature content and ui_settings updates to resolve persistence bug - Use updateUISettings store action for signature_position and signature_separator - Keep updateProfile for message_signature content only - Fixes FormData serialization issue that corrupted nested ui_settings object - Add diagnostic logging to verify data flow Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * clean: remove diagnostic console logging from updateSignature method - Remove temporary console.log statements added for verification - Keep core implementation that splits signature content and ui_settings updates - Keep console.error for proper error handling with eslint-disable comment - Implementation now ready for production use Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: updateUISettings call in updateSignature method * chore: move signature application to send-time and add button highlighting (#79) * fix: move signature application from editor manipulation to send-time - Remove addSignature/removeSignature/toggleSignatureInEditor from WootWriter - Remove signature logic from draft handling and canned response insertion - Apply signatures only in getMessagePayload during message sending - Add button highlighting for signature toggle when activated - Prevents signature duplication and persistence in editor content - Fixes signature position toggle bug Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: escape signature separator to prevent markdown setext heading interpretation - Escape '--' separator as '\--' in appendSignature to prevent H2 heading creation - Update removeSignature to handle escaped separators correctly - Fixes signature separator being rendered as markdown instead of plain text - Refactor nested ternary to fix ESLint error Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: prevent signature separator markdown interpretation in message processing - Add fix_signature_separator_markdown method to escape '--' separators - Update ensure_processed_message_content to fix separators before saving - Prevents signature separators from being interpreted as setext headings - Ensures correct message display in channels and email notifications Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: update separator format to use \n--\n instead of escaping - Change separator delimiter from '\--' to '\n--\n' format - Update removeSignature function to handle new separator format correctly - Simplify message processing since separators are already properly formatted - Ensures consistent separator handling across frontend and backend Co-Authored-By: cayo@fazer.ai <cayoproliveira@gmail.com> * fix: update signature delimiter format to include extra new lines * chore: remove comment about signature application logic * refactor: remove unused method and comments related to signature separator markdown processing * chore: simplify slash command detection by using updatedMessage directly * refactor: remove signature logic from draft message handling * refactor: simplify body empty check by removing signature manipulation logic --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: cayo@fazer.ai <cayoproliveira@gmail.com> * refactor: extract signature settings logic into a separate method * fix: handle nil ui_settings in signature position and separator methods * fix: update return value of findSignatureInBody to include position information * fix: update signature handling in findSignatureInBody and related methods * fix: adjust delimiter length handling in removeSignature function * test: add cases for appending, removing, and replacing signatures with various separators * test: add cases for signature position and separator handling * test: add cases for updating signature position and separator in ui_settings * fix: correct typo in comment for findSignatureInBody function * refactor: simplify translation function calls in MessageSignature component * chore: refactoring * chore: refactor * feat: switch -> select * chore: refactor and undo changes * chore: refactor and undo changes * chore: refactor * fix: remove old select component usage * chore: remove useless style --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
183 lines
5.9 KiB
Ruby
183 lines
5.9 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: users
|
|
#
|
|
# id :integer not null, primary key
|
|
# availability :integer default("online")
|
|
# confirmation_sent_at :datetime
|
|
# confirmation_token :string
|
|
# confirmed_at :datetime
|
|
# current_sign_in_at :datetime
|
|
# current_sign_in_ip :string
|
|
# custom_attributes :jsonb
|
|
# display_name :string
|
|
# email :string
|
|
# encrypted_password :string default(""), not null
|
|
# last_sign_in_at :datetime
|
|
# last_sign_in_ip :string
|
|
# message_signature :text
|
|
# name :string not null
|
|
# provider :string default("email"), not null
|
|
# pubsub_token :string
|
|
# remember_created_at :datetime
|
|
# reset_password_sent_at :datetime
|
|
# reset_password_token :string
|
|
# sign_in_count :integer default(0), not null
|
|
# tokens :json
|
|
# type :string
|
|
# ui_settings :jsonb
|
|
# uid :string default(""), not null
|
|
# unconfirmed_email :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_users_on_email (email)
|
|
# index_users_on_pubsub_token (pubsub_token) UNIQUE
|
|
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
|
# index_users_on_uid_and_provider (uid,provider) UNIQUE
|
|
#
|
|
|
|
class User < ApplicationRecord
|
|
include AccessTokenable
|
|
include Avatarable
|
|
# Include default devise modules.
|
|
include DeviseTokenAuth::Concerns::User
|
|
include Pubsubable
|
|
include Rails.application.routes.url_helpers
|
|
include Reportable
|
|
include SsoAuthenticatable
|
|
include UserAttributeHelpers
|
|
|
|
devise :database_authenticatable,
|
|
:registerable,
|
|
:recoverable,
|
|
:rememberable,
|
|
:trackable,
|
|
:validatable,
|
|
:confirmable,
|
|
:password_has_required_content,
|
|
:omniauthable, omniauth_providers: [:google_oauth2]
|
|
|
|
# TODO: remove in a future version once online status is moved to account users
|
|
# remove the column availability from users
|
|
enum availability: { online: 0, offline: 1, busy: 2 }
|
|
|
|
# The validation below has been commented out as it does not
|
|
# work because :validatable in devise overrides this.
|
|
# validates_uniqueness_of :email, scope: :account_id
|
|
|
|
validates :email, presence: true
|
|
|
|
has_many :account_users, dependent: :destroy_async
|
|
has_many :accounts, through: :account_users
|
|
accepts_nested_attributes_for :account_users
|
|
|
|
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify, inverse_of: :assignee
|
|
alias_attribute :conversations, :assigned_conversations
|
|
has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify, inverse_of: :assigned_agent
|
|
has_many :conversation_participants, dependent: :destroy_async
|
|
has_many :participating_conversations, through: :conversation_participants, source: :conversation
|
|
|
|
has_many :inbox_members, dependent: :destroy_async
|
|
has_many :inboxes, through: :inbox_members, source: :inbox
|
|
has_many :messages, as: :sender, dependent: :nullify
|
|
has_many :invitees, through: :account_users, class_name: 'User', foreign_key: 'inviter_id', source: :inviter, dependent: :nullify
|
|
|
|
has_many :custom_filters, dependent: :destroy_async
|
|
has_many :dashboard_apps, dependent: :nullify
|
|
has_many :mentions, dependent: :destroy_async
|
|
has_many :notes, dependent: :nullify
|
|
has_many :notification_settings, dependent: :destroy_async
|
|
has_many :notification_subscriptions, dependent: :destroy_async
|
|
has_many :notifications, dependent: :destroy_async
|
|
has_many :team_members, dependent: :destroy_async
|
|
has_many :teams, through: :team_members
|
|
has_many :articles, foreign_key: 'author_id', dependent: :nullify, inverse_of: :author
|
|
# rubocop:disable Rails/HasManyOrHasOneDependent
|
|
# we are handling this in `remove_macros` callback
|
|
has_many :macros, foreign_key: 'created_by_id', inverse_of: :created_by
|
|
# rubocop:enable Rails/HasManyOrHasOneDependent
|
|
|
|
before_validation :set_password_and_uid, on: :create
|
|
after_destroy :remove_macros
|
|
|
|
scope :order_by_full_name, -> { order('lower(name) ASC') }
|
|
|
|
before_validation do
|
|
self.email = email.try(:downcase)
|
|
end
|
|
|
|
def send_devise_notification(notification, *)
|
|
devise_mailer.with(account: Current.account).send(notification, self, *).deliver_later
|
|
end
|
|
|
|
def set_password_and_uid
|
|
self.uid = email
|
|
end
|
|
|
|
def assigned_inboxes
|
|
administrator? ? Current.account.inboxes : inboxes.where(account_id: Current.account.id)
|
|
end
|
|
|
|
def serializable_hash(options = nil)
|
|
super(options).merge(confirmed: confirmed?)
|
|
end
|
|
|
|
def push_event_data
|
|
{
|
|
id: id,
|
|
name: name,
|
|
available_name: available_name,
|
|
avatar_url: avatar_url,
|
|
type: 'user',
|
|
availability_status: availability_status,
|
|
thumbnail: avatar_url
|
|
}
|
|
end
|
|
|
|
def webhook_data
|
|
{
|
|
id: id,
|
|
name: name,
|
|
email: email,
|
|
type: 'user'
|
|
}
|
|
end
|
|
|
|
# https://github.com/lynndylanhurley/devise_token_auth/blob/6d7780ee0b9750687e7e2871b9a1c6368f2085a9/app/models/devise_token_auth/concerns/user.rb#L45
|
|
# Since this method is overriden in devise_token_auth it breaks the email reconfirmation flow.
|
|
def will_save_change_to_email?
|
|
mutations_from_database.changed?('email')
|
|
end
|
|
|
|
def self.from_email(email)
|
|
find_by(email: email&.downcase)
|
|
end
|
|
|
|
def signature_position
|
|
ui_settings&.fetch('signature_position', 'top') || 'top'
|
|
end
|
|
|
|
def signature_separator
|
|
ui_settings&.fetch('signature_separator', 'blank') || 'blank'
|
|
end
|
|
|
|
def signature_settings_with_defaults
|
|
{
|
|
'position' => signature_position,
|
|
'separator' => signature_separator
|
|
}
|
|
end
|
|
|
|
private
|
|
|
|
def remove_macros
|
|
macros.personal.destroy_all
|
|
end
|
|
end
|
|
|
|
User.include_mod_with('Audit::User')
|
|
User.include_mod_with('Concerns::User')
|