Class: Arkaan::Campaigns::Document

Inherits:
Object
  • Object
show all
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.

Author:

Direct Known Subclasses

File, Note

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#campaignArkaan::Campaign

Returns the campaign in which this file was uploaded.

Returns:



15
# File 'lib/arkaan/campaigns/document.rb', line 15

belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :files

#permissionArkaan::Campaigns::Permission

Returns the permissions granted to the different users of the campaign concerning this file.

Returns:

  • (Arkaan::Campaigns::Permission)

    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

#creatorArkaan::Account

Custom getter for the creator of the campaign.

Returns:



27
28
29
# File 'lib/arkaan/campaigns/document.rb', line 27

def creator
  return permissions.where(enum_level: :creator).first.invitation.
end

#creator=(invitation) ⇒ Object

Custom setter for the creator of the file so that it can be used as a normal field.

Parameters:



19
20
21
22
23
# File 'lib/arkaan/campaigns/document.rb', line 19

def creator=(invitation)
  if !permissions.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.

Parameters:

  • account (Arkaan::Account)

    the account to check the existence of a permission for.

Returns:

  • (Boolean)

    TRUE if the account has a permission to access this file, FALSE otherwise.



48
49
50
51
# File 'lib/arkaan/campaigns/document.rb', line 48

def has_permission?()
  invitation = campaign.invitations.where(account: ).first
  return !invitation.nil? && permissions.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

Parameters:

Returns:

  • (Boolean)

    TRUE if this account has the right to access the file, FALSe otherwise.



38
39
40
41
42
43
# File 'lib/arkaan/campaigns/document.rb', line 38

def is_allowed?()
  return true if campaign.creator.id == .id
  return true if creator.id == .id
  return true if has_permission?()
  return false
end