Class: Arkaan::Campaigns::Files::Document
- Inherits:
-
Object
- Object
- Arkaan::Campaigns::Files::Document
- Includes:
- Concerns::Nameable, Arkaan::Concerns::MimeTypable, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/arkaan/campaigns/files/document.rb
Overview
A document is any piece of data added by a user to a campaign. It can either be a direct text note, or an uploaded document for example.
Instance Attribute Summary collapse
-
#permission ⇒ Arkaan::Campaigns::Permission
The permissions granted to the different users of the campaign concerning this document.
-
#size ⇒ Integer
The size of the document in bytes.
Instance Method Summary collapse
- #campaign ⇒ Object
-
#creator ⇒ Arkaan::Account
Custom getter for the creator of the campaign.
-
#creator=(invitation) ⇒ Object
Custom setter for the creator of the document so that it can be used as a normal field.
-
#has_permission?(account) ⇒ Boolean
Checks if the account has the permission to access the designated document.
-
#is_allowed?(account) ⇒ Boolean
Checks if an account is allowed to access this document, accounts must have one of the following characteristics to read a document : - Be the creator of the document - Be the game master of the campaign in which the document is declared - Have been granted the permission to access the document.
Instance Attribute Details
#permission ⇒ Arkaan::Campaigns::Permission
Returns the permissions granted to the different users of the campaign concerning this document.
20 |
# File 'lib/arkaan/campaigns/files/document.rb', line 20 has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :document |
#size ⇒ Integer
Returns the size of the document in bytes.
14 |
# File 'lib/arkaan/campaigns/files/document.rb', line 14 field :size, type: Integer, default: 0 |
Instance Method Details
#campaign ⇒ Object
58 59 60 |
# File 'lib/arkaan/campaigns/files/document.rb', line 58 def campaign .first.invitation.campaign rescue nil end |
#creator ⇒ Arkaan::Account
Custom getter for the creator of the campaign.
32 33 34 |
# File 'lib/arkaan/campaigns/files/document.rb', line 32 def creator return .where(enum_level: :creator).first.invitation.account end |
#creator=(invitation) ⇒ Object
Custom setter for the creator of the document so that it can be used as a normal field.
24 25 26 27 28 |
# File 'lib/arkaan/campaigns/files/document.rb', line 24 def creator=(invitation) if !.where(invitation: invitation).exists? Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, document: self, invitation: invitation) end end |
#has_permission?(account) ⇒ Boolean
Checks if the account has the permission to access the designated document.
53 54 55 56 |
# File 'lib/arkaan/campaigns/files/document.rb', line 53 def (account) invitation = campaign.invitations.where(account: account).first return !invitation.nil? && .where(invitation: invitation).exists? end |
#is_allowed?(account) ⇒ Boolean
Checks if an account is allowed to access this document, accounts must have one of the following characteristics to read a document :
-
Be the creator of the document
-
Be the game master of the campaign in which the document is declared
-
Have been granted the permission to access the document
43 44 45 46 47 48 |
# File 'lib/arkaan/campaigns/files/document.rb', line 43 def is_allowed?(account) return true if campaign.creator.id == account.id return true if creator.id == account.id return true if (account) return false end |