Class: AssistantConversationShare
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AssistantConversationShare
- 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 =
%w[viewer collaborator].freeze
Instance Attribute Summary collapse
- #access_level ⇒ Object readonly
Belongs to collapse
Class Method Summary collapse
-
.collaborators ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are collaborators.
-
.for_roles ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for roles.
-
.for_users ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for users.
-
.granting_access_to ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are granting access to.
-
.viewers ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are viewers.
Instance Method Summary collapse
- #collaborator? ⇒ Boolean
-
#target_name ⇒ Object
Human-readable target name for display.
- #viewer? ⇒ Boolean
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#access_level ⇒ Object (readonly)
39 |
# File 'app/models/assistant_conversation_share.rb', line 39 validates :access_level, inclusion: { in: ACCESS_LEVELS } |
Class Method Details
.collaborators ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are collaborators. Active Record Scope
45 |
# File 'app/models/assistant_conversation_share.rb', line 45 scope :collaborators, -> { where(access_level: 'collaborator') } |
.for_roles ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for roles. Active Record Scope
43 |
# File 'app/models/assistant_conversation_share.rb', line 43 scope :for_roles, -> { where.not(role_id: nil) } |
.for_users ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for users. Active Record Scope
42 |
# File 'app/models/assistant_conversation_share.rb', line 42 scope :for_users, -> { where.not(party_id: nil) } |
.granting_access_to ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are granting access to. Active Record Scope
48 49 50 51 |
# File 'app/models/assistant_conversation_share.rb', line 48 scope :granting_access_to, ->(party, account) { where(party_id: party.id) .or(where(role_id: account.inherited_role_ids)) } |
.viewers ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are viewers. Active Record Scope
44 |
# File 'app/models/assistant_conversation_share.rb', line 44 scope :viewers, -> { where(access_level: 'viewer') } |
Instance Method Details
#assistant_conversation ⇒ AssistantConversation
34 |
# File 'app/models/assistant_conversation_share.rb', line 34 belongs_to :assistant_conversation |
#collaborator? ⇒ Boolean
57 58 59 |
# File 'app/models/assistant_conversation_share.rb', line 57 def collaborator? access_level == 'collaborator' end |
#role ⇒ Role
36 |
# File 'app/models/assistant_conversation_share.rb', line 36 belongs_to :role, optional: true |
#shared_by ⇒ Party
37 |
# File 'app/models/assistant_conversation_share.rb', line 37 belongs_to :shared_by, class_name: 'Party' |
#target_name ⇒ Object
Human-readable target name for display
62 63 64 65 66 67 68 |
# File 'app/models/assistant_conversation_share.rb', line 62 def target_name if party_id.present? user&.full_name || "User ##{party_id}" else role&.name&.titleize || "Role ##{role_id}" end end |
#user ⇒ Party
35 |
# File 'app/models/assistant_conversation_share.rb', line 35 belongs_to :user, class_name: 'Party', foreign_key: :party_id, optional: true |
#viewer? ⇒ Boolean
53 54 55 |
# File 'app/models/assistant_conversation_share.rb', line 53 def viewer? access_level == 'viewer' end |