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 =
Access levels.
%w[viewer collaborator].freeze
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#access_level ⇒ Object (readonly)
41 |
# File 'app/models/assistant_conversation_share.rb', line 41 validates :access_level, inclusion: { in: ACCESS_LEVELS } |
Class Method Details
.collaborators ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are collaborators. Active Record Scope
47 |
# File 'app/models/assistant_conversation_share.rb', line 47 scope :collaborators, -> { where(access_level: 'collaborator') } |
.for_roles ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for roles. Active Record Scope
45 |
# File 'app/models/assistant_conversation_share.rb', line 45 scope :for_roles, -> { where.not(role_id: nil) } |
.for_users ⇒ ActiveRecord::Relation<AssistantConversationShare>
A relation of AssistantConversationShares that are for users. Active Record Scope
44 |
# File 'app/models/assistant_conversation_share.rb', line 44 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
50 51 52 53 |
# File 'app/models/assistant_conversation_share.rb', line 50 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
46 |
# File 'app/models/assistant_conversation_share.rb', line 46 scope :viewers, -> { where(access_level: 'viewer') } |
Instance Method Details
#assistant_conversation ⇒ AssistantConversation
36 |
# File 'app/models/assistant_conversation_share.rb', line 36 belongs_to :assistant_conversation |
#collaborator? ⇒ Boolean
59 60 61 |
# File 'app/models/assistant_conversation_share.rb', line 59 def collaborator? access_level == 'collaborator' end |
#role ⇒ Role
38 |
# File 'app/models/assistant_conversation_share.rb', line 38 belongs_to :role, optional: true |
#shared_by ⇒ Party
39 |
# File 'app/models/assistant_conversation_share.rb', line 39 belongs_to :shared_by, class_name: 'Party' |
#target_name ⇒ Object
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 |
#user ⇒ Party
37 |
# File 'app/models/assistant_conversation_share.rb', line 37 belongs_to :user, class_name: 'Party', foreign_key: :party_id, optional: true |
#viewer? ⇒ Boolean
55 56 57 |
# File 'app/models/assistant_conversation_share.rb', line 55 def viewer? access_level == 'viewer' end |