Class: Arkaan::Campaigns::Document
- Inherits:
-
Object
- Object
- Arkaan::Campaigns::Document
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/arkaan/campaigns/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 file for example.
Instance Attribute Summary collapse
-
#campaign ⇒ Arkaan::Campaign
The campaign in which this file was uploaded.
-
#permission ⇒ Arkaan::Campaigns::Permission
The permissions granted to the different users of the campaign concerning this file.
Instance Method Summary collapse
-
#creator ⇒ Arkaan::Account
Custom getter for the creator of the campaign.
-
#creator=(invitation) ⇒ Object
Custom setter for the creator of the file 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 file.
-
#is_allowed?(account) ⇒ Boolean
Checks if an account is allowed to access this file, accounts must have one of the following characteristics to read a file : - Be the creator of the file - Be the game master of the campaign in which the file is declared - Have been granted the permission to access the file.
Instance Attribute Details
#campaign ⇒ Arkaan::Campaign
Returns the campaign in which this file was uploaded.
15 |
# File 'lib/arkaan/campaigns/document.rb', line 15 belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :files |
#permission ⇒ Arkaan::Campaigns::Permission
Returns the permissions granted to the different users of the campaign concerning this file.
11 |
# File 'lib/arkaan/campaigns/document.rb', line 11 has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :file |
Instance Method Details
#creator ⇒ Arkaan::Account
Custom getter for the creator of the campaign.
27 28 29 |
# File 'lib/arkaan/campaigns/document.rb', line 27 def creator return .where(enum_level: :creator).first.invitation.account end |
#creator=(invitation) ⇒ Object
Custom setter for the creator of the file so that it can be used as a normal field.
19 20 21 22 23 |
# File 'lib/arkaan/campaigns/document.rb', line 19 def creator=(invitation) if !.where(invitation: invitation).exists? Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, file: self, invitation: invitation) end end |
#has_permission?(account) ⇒ Boolean
Checks if the account has the permission to access the designated file.
48 49 50 51 |
# File 'lib/arkaan/campaigns/document.rb', line 48 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 file, accounts must have one of the following characteristics to read a file :
-
Be the creator of the file
-
Be the game master of the campaign in which the file is declared
-
Have been granted the permission to access the file
38 39 40 41 42 43 |
# File 'lib/arkaan/campaigns/document.rb', line 38 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 |