Class: AssistantConversationShare

Inherits:
ApplicationRecord show all
Defined in:
app/models/assistant_conversation_share.rb

Overview

== Schema Information

Table name: assistant_conversation_shares
Database name: primary

id :bigint not null, primary key
access_level :string default("viewer"), not null
created_at :datetime not null
updated_at :datetime not null
assistant_conversation_id :bigint not null
party_id :bigint
role_id :bigint
shared_by_id :bigint not null

Indexes

idx_conv_shares_conversation (assistant_conversation_id)
idx_conv_shares_party (party_id) WHERE (party_id IS NOT NULL)
idx_conv_shares_role (role_id) WHERE (role_id IS NOT NULL)
idx_conv_shares_unique_role (assistant_conversation_id,role_id) UNIQUE WHERE (role_id IS NOT NULL)
idx_conv_shares_unique_user (assistant_conversation_id,party_id) UNIQUE WHERE (party_id IS NOT NULL)

Foreign Keys

fk_rails_... (assistant_conversation_id => assistant_conversations.id)
fk_rails_... (party_id => parties.id)
fk_rails_... (role_id => roles.id)
fk_rails_... (shared_by_id => parties.id)

Constant Summary collapse

ACCESS_LEVELS =

Access levels.

%w[viewer collaborator].freeze

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#access_levelObject (readonly)



41
# File 'app/models/assistant_conversation_share.rb', line 41

validates :access_level, inclusion: { in: ACCESS_LEVELS }

Class Method Details

.collaboratorsActiveRecord::Relation<AssistantConversationShare>

A relation of AssistantConversationShares that are collaborators. Active Record Scope

Returns:

See Also:



47
# File 'app/models/assistant_conversation_share.rb', line 47

scope :collaborators, -> { where(access_level: 'collaborator') }

.for_rolesActiveRecord::Relation<AssistantConversationShare>

A relation of AssistantConversationShares that are for roles. Active Record Scope

Returns:

See Also:



45
# File 'app/models/assistant_conversation_share.rb', line 45

scope :for_roles, -> { where.not(role_id: nil) }

.for_usersActiveRecord::Relation<AssistantConversationShare>

A relation of AssistantConversationShares that are for users. Active Record Scope

Returns:

See Also:



44
# File 'app/models/assistant_conversation_share.rb', line 44

scope :for_users, -> { where.not(party_id: nil) }

.granting_access_toActiveRecord::Relation<AssistantConversationShare>

A relation of AssistantConversationShares that are granting access to. Active Record Scope

Returns:

See Also:



50
51
52
53
# File 'app/models/assistant_conversation_share.rb', line 50

scope :granting_access_to, ->(party, ) {
  where(party_id: party.id)
    .or(where(role_id: .inherited_role_ids))
}

.viewersActiveRecord::Relation<AssistantConversationShare>

A relation of AssistantConversationShares that are viewers. Active Record Scope

Returns:

See Also:



46
# File 'app/models/assistant_conversation_share.rb', line 46

scope :viewers,      -> { where(access_level: 'viewer') }

Instance Method Details

#assistant_conversationAssistantConversation



36
# File 'app/models/assistant_conversation_share.rb', line 36

belongs_to :assistant_conversation

#collaborator?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/assistant_conversation_share.rb', line 59

def collaborator?
  access_level == 'collaborator'
end

#roleRole

Returns:

See Also:



38
# File 'app/models/assistant_conversation_share.rb', line 38

belongs_to :role, optional: true

#shared_byParty

Returns:

See Also:



39
# File 'app/models/assistant_conversation_share.rb', line 39

belongs_to :shared_by, class_name: 'Party'

#target_nameObject

Human-readable target name for display



64
65
66
67
68
69
70
# File 'app/models/assistant_conversation_share.rb', line 64

def target_name
  if party_id.present?
    user&.full_name || "User ##{party_id}"
  else
    role&.name&.titleize || "Role ##{role_id}"
  end
end

#userParty

Returns:

See Also:



37
# File 'app/models/assistant_conversation_share.rb', line 37

belongs_to :user, class_name: 'Party', foreign_key: :party_id, optional: true

#viewer?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/assistant_conversation_share.rb', line 55

def viewer?
  access_level == 'viewer'
end