arkaan 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arkaan/campaign.rb +20 -1
- data/lib/arkaan/campaigns.rb +1 -0
- data/lib/arkaan/campaigns/character.rb +52 -0
- data/lib/arkaan/campaigns/files.rb +0 -2
- data/lib/arkaan/campaigns/files/concerns/nameable.rb +0 -45
- data/lib/arkaan/campaigns/files/document.rb +50 -4
- data/lib/arkaan/campaigns/files/permission.rb +1 -1
- data/lib/arkaan/campaigns/invitation.rb +13 -3
- data/lib/arkaan/utils/controllers/base.rb +4 -2
- data/lib/arkaan/version.rb +1 -1
- metadata +3 -5
- data/lib/arkaan/campaigns/files/base.rb +0 -56
- data/lib/arkaan/campaigns/files/character.rb +0 -48
- data/lib/arkaan/campaigns/files/note.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e70b9b135c0ac5b57d31e26c224937b2ed9ca69bd902f10f2cc4f7c2bddd339f
|
4
|
+
data.tar.gz: 61b68c995672ff514cecf8c022a30e9231c05e9f5ed55b468e17fe528068d3a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94729cac55877bb9da88d9d4a7824ff99158480fe16afe1e2eee6f4732e64039ddce67fbbcef74b6f943c88b1e1ea0b88e6568955e58d22541d6c8b6365a1047
|
7
|
+
data.tar.gz: 0b83a9933b47a4c47285c50bcb9aa87288e0a449068d3ae17b901497148d8998fd71a13bcfc1ecff40466df10b810ddc0b5ada68d72f1d329a465d9c49a7bd9a
|
data/lib/arkaan/campaign.rb
CHANGED
@@ -72,14 +72,33 @@ module Arkaan
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
# Validation for the max number of players for a campaign.
|
76
|
+
# If there is a max number of players, and the current number of
|
77
|
+
# players is above it, or the max number of players is 0, raises an error.
|
75
78
|
def max_players_minimum
|
76
79
|
if max_players? && (max_players < players_count || max_players < 1)
|
77
80
|
errors.add(:max_players, 'minimum')
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
84
|
+
# @return [Array<Arkaan::Campaigns::Invitation>] the players in this campaign.
|
85
|
+
def players
|
86
|
+
invitations.where(enum_status: :accepted)
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [Integer] the number of players in this campaign.
|
81
90
|
def players_count
|
82
|
-
|
91
|
+
players.count
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [Array<Arkaan::Campaigns::Character>] a flattened list of characters for this campaign.
|
95
|
+
def characters
|
96
|
+
players.map(&:characters).flatten
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Array<Arkaan::Campaigns::Files::Document>] the document of this campaign as a flattened array.
|
100
|
+
def documents
|
101
|
+
invitations.map(&:documents).flatten
|
83
102
|
end
|
84
103
|
end
|
85
104
|
end
|
data/lib/arkaan/campaigns.rb
CHANGED
@@ -2,6 +2,7 @@ module Arkaan
|
|
2
2
|
# The campaigns module is holding the logic for some objects related to campaigns.
|
3
3
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
4
4
|
module Campaigns
|
5
|
+
autoload :Character , 'arkaan/campaigns/character'
|
5
6
|
autoload :Files , 'arkaan/campaigns/files'
|
6
7
|
autoload :Invitation, 'arkaan/campaigns/invitation'
|
7
8
|
autoload :Message , 'arkaan/campaigns/message'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Campaigns
|
3
|
+
# A character sheet represents a character played by a player in a campaign.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
+
class Character
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
include Arkaan::Concerns::MimeTypable
|
9
|
+
include Arkaan::Campaigns::Files::Concerns::Nameable
|
10
|
+
|
11
|
+
# @!attribute [rw] selected
|
12
|
+
# @return [Boolean] TRUE if the sheet is currently selected by the player, FALSE otherwise.
|
13
|
+
field :selected, type: Boolean, default: false
|
14
|
+
# @!attribute [rw] mime_type
|
15
|
+
# @return [String] the mime_type of the character sheet, MUST be an authorized MIME type for
|
16
|
+
# the ruleset the campaign is set to be in.
|
17
|
+
mime_type :available_mime_types
|
18
|
+
|
19
|
+
# @!attribute [rw] invitation
|
20
|
+
# @return [Arkaan::Campaigns::Invitation] the invitation of the player playing this character.
|
21
|
+
belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :characters
|
22
|
+
|
23
|
+
# Returns the player linked to this character.
|
24
|
+
# @return [Arkaan::Account] the account of the player incarnating this character.
|
25
|
+
def player
|
26
|
+
invitation.account
|
27
|
+
end
|
28
|
+
|
29
|
+
# Method used to dinamically determine what MIME types are allowed for this character sheet
|
30
|
+
# If the campaign this character is in has no ruleset, every MIME type is allowed.
|
31
|
+
# @return [Array<String>] the available MIME type for the campaign linked to this character.
|
32
|
+
def available_mime_types
|
33
|
+
invitation.campaign.ruleset.mime_types
|
34
|
+
end
|
35
|
+
|
36
|
+
def campaign
|
37
|
+
invitation.campaign
|
38
|
+
end
|
39
|
+
|
40
|
+
# Puts the selected flag to TRUE for this character and to FALSE for all the
|
41
|
+
# other characters for the same player in the same campaign.
|
42
|
+
def select!
|
43
|
+
invitation.characters.each do |character|
|
44
|
+
character.update_attribute(:selected, false)
|
45
|
+
character.save!
|
46
|
+
end
|
47
|
+
update_attribute(:selected, true)
|
48
|
+
save!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Campaigns
|
3
3
|
module Files
|
4
|
-
autoload :Base , 'arkaan/campaigns/files/base'
|
5
4
|
autoload :Character , 'arkaan/campaigns/files/character'
|
6
5
|
autoload :Concerns , 'arkaan/campaigns/files/concerns'
|
7
6
|
autoload :Document , 'arkaan/campaigns/files/document'
|
8
|
-
autoload :Note , 'arkaan/campaigns/files/note'
|
9
7
|
autoload :Permission, 'arkaan/campaigns/files/permission'
|
10
8
|
end
|
11
9
|
end
|
@@ -11,51 +11,6 @@ module Arkaan
|
|
11
11
|
field :name, type: String
|
12
12
|
|
13
13
|
validates :name, presence: {message: 'required'}
|
14
|
-
|
15
|
-
validate :name_unicity
|
16
|
-
|
17
|
-
# Checks if the name is unique in the campaign, and if it is not then modifies it.
|
18
|
-
# The modifications are the same than in a windows or UNIX system :
|
19
|
-
# - if the name exists as it is given, the system adds the suffix "(1)" to it.
|
20
|
-
# - if the name with the suffix still exists, the system tries to increment it until an available name is found.
|
21
|
-
# - the found name is then afected to the name of the current file.
|
22
|
-
def name_unicity
|
23
|
-
if !campaign.nil? && !self[:name].nil?
|
24
|
-
if exists_in_campaign(self[:name])
|
25
|
-
suffix = 1
|
26
|
-
while exists_in_campaign(merge_suffix(suffix))
|
27
|
-
suffix = suffix + 1
|
28
|
-
end
|
29
|
-
self[:name] = merge_suffix(suffix)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Merges the given suffix with the name correctly.
|
35
|
-
# @param suffix [String] the suffix to append between perenthesis at the end of the file name, but before the extension.
|
36
|
-
# @return [String] the complete name for the file, with the suffix correctly appended.
|
37
|
-
def merge_suffix(suffix)
|
38
|
-
return "#{raw_name} (#{suffix}).#{extension}"
|
39
|
-
end
|
40
|
-
|
41
|
-
# Checks if the given name already exists for a file in the campaign.
|
42
|
-
# @param tmp_name [String] the name to check the existence of in the campaign.
|
43
|
-
# @return [Boolean] TRUE if the file exists in the campaign, FALSE otherwise.
|
44
|
-
def exists_in_campaign(tmp_name)
|
45
|
-
campaign.files.where(name: tmp_name, :id.ne => id).exists?
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns the file name without the extension for the current file.
|
49
|
-
# @return [String] the name of the file without the extension.
|
50
|
-
def raw_name
|
51
|
-
return self[:name].gsub(".#{extension}", '')
|
52
|
-
end
|
53
|
-
|
54
|
-
# Returns the extension of the file, without the dot.
|
55
|
-
# @return [String] the text representation for this file extension, without the leading dot.
|
56
|
-
def extension
|
57
|
-
return self[:name].split('.').last
|
58
|
-
end
|
59
14
|
end
|
60
15
|
end
|
61
16
|
end
|
@@ -1,17 +1,63 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Campaigns
|
3
3
|
module Files
|
4
|
-
#
|
4
|
+
# 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.
|
5
5
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
-
class Document
|
6
|
+
class Document
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::Timestamps
|
7
9
|
include Arkaan::Concerns::MimeTypable
|
8
10
|
include Arkaan::Campaigns::Files::Concerns::Nameable
|
9
|
-
|
11
|
+
|
10
12
|
# @!attribute [rw] size
|
11
|
-
# @return [Integer] the size of the
|
13
|
+
# @return [Integer] the size of the document in bytes.
|
12
14
|
field :size, type: Integer, default: 0
|
13
15
|
|
14
16
|
mime_type ['image/*', 'text/plain']
|
17
|
+
|
18
|
+
# @!attribute [rw] permission
|
19
|
+
# @return [Arkaan::Campaigns::Permission] the permissions granted to the different users of the campaign concerning this document.
|
20
|
+
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :document
|
21
|
+
|
22
|
+
# Custom setter for the creator of the document so that it can be used as a normal field.
|
23
|
+
# @param invitation [Arkaan::Campaigns::Invitation] the invitation of the player creating this document.
|
24
|
+
def creator=(invitation)
|
25
|
+
if !permissions.where(invitation: invitation).exists?
|
26
|
+
Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, document: self, invitation: invitation)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Custom getter for the creator of the campaign.
|
31
|
+
# @return [Arkaan::Account] the account of the player that created this document.
|
32
|
+
def creator
|
33
|
+
return permissions.where(enum_level: :creator).first.invitation.account
|
34
|
+
end
|
35
|
+
|
36
|
+
# Checks if an account is allowed to access this document, accounts must have one of the following characteristics to read a document :
|
37
|
+
# - Be the creator of the document
|
38
|
+
# - Be the game master of the campaign in which the document is declared
|
39
|
+
# - Have been granted the permission to access the document
|
40
|
+
#
|
41
|
+
# @param account [Arkaan::Account] the account trying to access the document.
|
42
|
+
# @return [Boolean] TRUE if this account has the right to access the document, FALSe otherwise.
|
43
|
+
def is_allowed?(account)
|
44
|
+
return true if campaign.creator.id == account.id
|
45
|
+
return true if creator.id == account.id
|
46
|
+
return true if has_permission?(account)
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
# Checks if the account has the permission to access the designated document.
|
51
|
+
# @param account [Arkaan::Account] the account to check the existence of a permission for.
|
52
|
+
# @return [Boolean] TRUE if the account has a permission to access this document, FALSE otherwise.
|
53
|
+
def has_permission?(account)
|
54
|
+
invitation = campaign.invitations.where(account: account).first
|
55
|
+
return !invitation.nil? && permissions.where(invitation: invitation).exists?
|
56
|
+
end
|
57
|
+
|
58
|
+
def campaign
|
59
|
+
permissions.first.invitation.campaign rescue nil
|
60
|
+
end
|
15
61
|
end
|
16
62
|
end
|
17
63
|
end
|
@@ -19,7 +19,7 @@ module Arkaan
|
|
19
19
|
belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :permissions
|
20
20
|
# @!attribute [rw] file
|
21
21
|
# @return [Arkaan::Campaigns::Files::Document] the file on which the permissions are granted.
|
22
|
-
belongs_to :
|
22
|
+
belongs_to :document, class_name: 'Arkaan::Campaigns::Files::Document', inverse_of: :permissions
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -20,16 +20,26 @@ module Arkaan
|
|
20
20
|
|
21
21
|
# @!attribute [rw] files
|
22
22
|
# @return [Array<Arkaan::Campaigns::Files::Document>] the files uploaded in this campaign by the user linked to this invitation.
|
23
|
-
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::
|
23
|
+
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :invitation
|
24
24
|
# @!attribute [rw] characters
|
25
|
-
# @return [Array<Arkaan::Campaigns::
|
26
|
-
has_many :characters, class_name: 'Arkaan::Campaigns::
|
25
|
+
# @return [Array<Arkaan::Campaigns::Character>] the character sheets for this player.
|
26
|
+
has_many :characters, class_name: 'Arkaan::Campaigns::Character', inverse_of: :invitation
|
27
27
|
|
28
28
|
# Gets the currently selected character in a convenient way.
|
29
29
|
# @return [Arkaan::Campaigns::Files::Character] the character currently selected by the player.
|
30
30
|
def character
|
31
31
|
characters.where(selected: true).first
|
32
32
|
end
|
33
|
+
|
34
|
+
def documents
|
35
|
+
permissions.map(&:document)
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_file?(filename)
|
39
|
+
return permissions.map(&:document).map(&:name).any? do |name|
|
40
|
+
name == filename
|
41
|
+
end
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -204,8 +204,10 @@ module Arkaan
|
|
204
204
|
handle_arkaan_exception(exception)
|
205
205
|
end
|
206
206
|
|
207
|
-
|
208
|
-
|
207
|
+
if ENV['RACK_ENV'] != 'test'
|
208
|
+
error StandardError do |exception|
|
209
|
+
custom_error(500, 'system_error.unknown_field.unknown_error')
|
210
|
+
end
|
209
211
|
end
|
210
212
|
end
|
211
213
|
end
|
data/lib/arkaan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -302,13 +302,11 @@ files:
|
|
302
302
|
- lib/arkaan/authentication/session.rb
|
303
303
|
- lib/arkaan/campaign.rb
|
304
304
|
- lib/arkaan/campaigns.rb
|
305
|
+
- lib/arkaan/campaigns/character.rb
|
305
306
|
- lib/arkaan/campaigns/files.rb
|
306
|
-
- lib/arkaan/campaigns/files/base.rb
|
307
|
-
- lib/arkaan/campaigns/files/character.rb
|
308
307
|
- lib/arkaan/campaigns/files/concerns.rb
|
309
308
|
- lib/arkaan/campaigns/files/concerns/nameable.rb
|
310
309
|
- lib/arkaan/campaigns/files/document.rb
|
311
|
-
- lib/arkaan/campaigns/files/note.rb
|
312
310
|
- lib/arkaan/campaigns/files/permission.rb
|
313
311
|
- lib/arkaan/campaigns/invitation.rb
|
314
312
|
- lib/arkaan/campaigns/message.rb
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Campaigns
|
3
|
-
module Files
|
4
|
-
# 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.
|
5
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
-
class Base
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Timestamps
|
9
|
-
|
10
|
-
# @!attribute [rw] permission
|
11
|
-
# @return [Arkaan::Campaigns::Permission] the permissions granted to the different users of the campaign concerning this file.
|
12
|
-
has_many :permissions, class_name: 'Arkaan::Campaigns::Files::Permission', inverse_of: :file
|
13
|
-
|
14
|
-
# @!attribute [rw] campaign
|
15
|
-
# @return [Arkaan::Campaign] the campaign in which this file was uploaded.
|
16
|
-
belongs_to :campaign, class_name: 'Arkaan::Campaign', inverse_of: :files
|
17
|
-
|
18
|
-
# Custom setter for the creator of the file so that it can be used as a normal field.
|
19
|
-
# @param invitation [Arkaan::Campaigns::Invitation] the invitation of the player creating this file.
|
20
|
-
def creator=(invitation)
|
21
|
-
if !permissions.where(invitation: invitation).exists?
|
22
|
-
Arkaan::Campaigns::Files::Permission.create(enum_level: :creator, file: self, invitation: invitation)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Custom getter for the creator of the campaign.
|
27
|
-
# @return [Arkaan::Account] the account of the player that created this file.
|
28
|
-
def creator
|
29
|
-
return permissions.where(enum_level: :creator).first.invitation.account
|
30
|
-
end
|
31
|
-
|
32
|
-
# Checks if an account is allowed to access this file, accounts must have one of the following characteristics to read a file :
|
33
|
-
# - Be the creator of the file
|
34
|
-
# - Be the game master of the campaign in which the file is declared
|
35
|
-
# - Have been granted the permission to access the file
|
36
|
-
#
|
37
|
-
# @param account [Arkaan::Account] the account trying to access the file.
|
38
|
-
# @return [Boolean] TRUE if this account has the right to access the file, FALSe otherwise.
|
39
|
-
def is_allowed?(account)
|
40
|
-
return true if campaign.creator.id == account.id
|
41
|
-
return true if creator.id == account.id
|
42
|
-
return true if has_permission?(account)
|
43
|
-
return false
|
44
|
-
end
|
45
|
-
|
46
|
-
# Checks if the account has the permission to access the designated file.
|
47
|
-
# @param account [Arkaan::Account] the account to check the existence of a permission for.
|
48
|
-
# @return [Boolean] TRUE if the account has a permission to access this file, FALSE otherwise.
|
49
|
-
def has_permission?(account)
|
50
|
-
invitation = campaign.invitations.where(account: account).first
|
51
|
-
return !invitation.nil? && permissions.where(invitation: invitation).exists?
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Campaigns
|
3
|
-
module Files
|
4
|
-
# A character sheet represents a character played by a player in a campaign.
|
5
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
-
class Character < Arkaan::Campaigns::Files::Base
|
7
|
-
include Arkaan::Campaigns::Files::Concerns::Nameable
|
8
|
-
include Arkaan::Concerns::MimeTypable
|
9
|
-
|
10
|
-
# @!attribute [rw] selected
|
11
|
-
# @return [Boolean] TRUE if the sheet is currently selected by the player, FALSE otherwise.
|
12
|
-
field :selected, type: Boolean, default: false
|
13
|
-
# @!attribute [rw] mime_type
|
14
|
-
# @return [String] the mime_type of the character sheet, MUST be an authorized MIME type for
|
15
|
-
# the ruleset the campaign is set to be in.
|
16
|
-
mime_type :available_mime_types
|
17
|
-
|
18
|
-
# @!attribute [rw] invitation
|
19
|
-
# @return [Arkaan::Campaigns::Invitation] the invitation of the player playing this character.
|
20
|
-
belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :characters
|
21
|
-
|
22
|
-
# Returns the player linked to this character.
|
23
|
-
# @return [Arkaan::Account] the account of the player incarnating this character.
|
24
|
-
def player
|
25
|
-
invitation.account
|
26
|
-
end
|
27
|
-
|
28
|
-
# Method used to dinamically determine what MIME types are allowed for this character sheet
|
29
|
-
# If the campaign this character is in has no ruleset, every MIME type is allowed.
|
30
|
-
# @return [Array<String>] the available MIME type for the campaign linked to this character.
|
31
|
-
def available_mime_types
|
32
|
-
invitation.campaign.ruleset.mime_types
|
33
|
-
end
|
34
|
-
|
35
|
-
# Puts the selected flag to TRUE for this character and to FALSE for all the
|
36
|
-
# other characters for the same player in the same campaign.
|
37
|
-
def select!
|
38
|
-
invitation.characters.each do |character|
|
39
|
-
character.update_attribute(:selected, false)
|
40
|
-
character.save!
|
41
|
-
end
|
42
|
-
update_attribute(:selected, true)
|
43
|
-
save!
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|