virtuatable-core 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9afbc1d8f75f5d0b94194432b3a379a7b02d90d2490deeed47d46d9c89036b01
4
- data.tar.gz: 56cfd05e3f53df001a852d26b6abf992313d52598902ecb21809cd16708ae266
3
+ metadata.gz: 66ce5b5678adffaaf85ae207353fb60805ebdde74d02c8aa87aedd70109184d6
4
+ data.tar.gz: 70b78998d52d0a8e47938b200500f445287d9d3d0f5cf3749fd856f645140275
5
5
  SHA512:
6
- metadata.gz: 7f4fdde3ecd17bb2b33a535ce22c927783ab5d88c00f639ee9374fcc7b36c6680ed0e2f1ce50071a22e1c4784d453c1b74b0bc71d5b817bd72e0501faf637611
7
- data.tar.gz: 7622404c051938c9cee8567de61f25005e7f178ae4a7dd22146d279aa8413a52c92c25c36db2472a59588c2f0a10db22322d4f0ff8348fc3609124798bcd4587
6
+ metadata.gz: 3547e559af72ec612be70b6423c50c8bb0d2a5ad8ea7cec3e64eef1c47940faa2702a1c4a8f010463f4ac5bc696f91811348e31ace459f206dd875c01ef93677
7
+ data.tar.gz: cc76eb73b5418e74d9215040d334991365d937675bd8af6015cc15b0a93526be4e0c410f03c358ae0f738675adaaaef226ef9af27abc68eed0348e1e476a3f20
@@ -8,6 +8,8 @@ module Core
8
8
  include ActiveModel::SecurePassword
9
9
  include Core::Models::Concerns::Enumerable
10
10
 
11
+ store_in collection: 'accounts'
12
+
11
13
  # @!attribute [rw] username
12
14
  # @return [String] the nickname the user chose at subscription, must be given, unique, and 6 or more characters long.
13
15
  field :username, type: String
@@ -62,8 +64,6 @@ module Core
62
64
  # @return [Array<Core::Models::Chatrooms::Messages>] all the messages ever sent by the user.
63
65
  has_many :messages, class_name: 'Core::Models::Chatrooms::Message', inverse_of: :account
64
66
 
65
- has_many :memberships, class_name: 'Core::Models::Chatrooms::Membership', inverse_of: :account
66
-
67
67
  # @!attribute [rw] notifications
68
68
  # @return [Array<Core::Models::Notification>] the notifications linked to this user.
69
69
  embeds_many :notifications, class_name: 'Core::Models::Notification', inverse_of: :account
@@ -9,6 +9,8 @@ module Core
9
9
  include Mongoid::Document
10
10
  include Mongoid::Timestamps
11
11
 
12
+ store_in collection: 'sessions'
13
+
12
14
  # @!attribute [rw] token
13
15
  # @return [String] the unique token for this session, used to identify it and be sure the user is connected on this application.
14
16
  field :token, type: String
@@ -6,6 +6,8 @@ module Core
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps
8
8
 
9
+ store_in collection: 'campaigns'
10
+
9
11
  # @!attribute [rw] title
10
12
  # @return [String] the title, or name, of the campaign, used to identify it in the list.
11
13
  field :title, type: String
@@ -33,6 +35,10 @@ module Core
33
35
  # @return [Core::Models::Chatrooms::Campaign] the chatroom linked to this campaign.
34
36
  embeds_one :chatroom, class_name: 'Core::Models::Chatrooms::Campaign', inverse_of: :campaign
35
37
 
38
+ # @!attribute [rw] tokens
39
+ # @return [Array<Core::Models::Campaigns::Token>] the tokens declared in this campaign.
40
+ embeds_many :tokens, class_name: 'Core::Models::Campaigns::Token', inverse_of: :campaign
41
+
36
42
  # @!attribute [rw] ruleset
37
43
  # @return [Core::Models::Ruleset] the set of rules this campaign is based upon.
38
44
  belongs_to :ruleset, class_name: 'Core::Models::Ruleset', inverse_of: :campaigns, optional: true
@@ -13,6 +13,8 @@ module Core
13
13
  include Core::Models::Concerns::Enumerable
14
14
  include Core::Models::Concerns::Historizable
15
15
 
16
+ store_in collection: 'invitations'
17
+
16
18
  # @!attribute [rw] account
17
19
  # @return [Core::Models::Account] the account the invitation has been issued to.
18
20
  belongs_to :account, class_name: 'Core::Models::Account', inverse_of: :invitations
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Core
4
+ module Models
5
+ module Campaigns
6
+ # A map is a battleground where the players can place tokens and live the adventure.
7
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
8
+ class Map
9
+ include Mongoid::Document
10
+ include Mongoid::Timestamps
11
+
12
+ store_in collection: 'maps'
13
+
14
+ # @!attribute [rw] height
15
+ # @return [Integer] the number of lines in the map matric.
16
+ field :height, type: Integer, default: 1
17
+ # @!attribute [rw] width
18
+ # @return [Integer] the number of columns in the map matric.
19
+ field :width, type: Integer, default: 1
20
+
21
+ # @!attribute [rw] campaign
22
+ # @return [Core::Models::Campaign] the campaign in which the map can be found.
23
+ belongs_to :campaign, class_name: 'Core::Models::Campaign', inverse_of: :maps
24
+
25
+ # @!attribute [rw] positions
26
+ # @return [Array<Core::Model::Campaigns::TokenPosition>] the instanciated tokens on this map.
27
+ embeds_many :positions, class_name: 'Core::Models::Campaigns::TokenPosition', inverse_of: :map
28
+
29
+ validates :height,
30
+ numericality: { greater_than: 0, message: 'minimum' }
31
+
32
+ validates :width,
33
+ numericality: { greater_than: 0, message: 'minimum' }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -9,6 +9,8 @@ module Core
9
9
  include Mongoid::Document
10
10
  include Mongoid::Timestamps
11
11
 
12
+ store_in collection: 'tags'
13
+
12
14
  # @!attribute [rw] content
13
15
  # @return [String] the string content of the tag, describing a characteristic.
14
16
  field :content, type: String
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Core
4
+ module Models
5
+ module Campaigns
6
+ # A token represents an player or a monster in the game. It can be placed as a TokenPosition.
7
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
8
+ class Token
9
+ include Mongoid::Document
10
+ include Mongoid::Timestamps
11
+
12
+ store_in collection: 'tokens'
13
+
14
+ # @!attribute [rw] name
15
+ # @return [String] the name of the token that will be displayed on the map
16
+ field :name, type: String
17
+
18
+ # @!attribute [rw] campaign
19
+ # @return [Core::Models::Campaign] the campaign in which this token can be used
20
+ embedded_in :campaign, class_name: 'Core::Models::Campaign', inverse_of: :tokens
21
+ # @!attribute [rw] creator
22
+ # @return [Core::Models::Account] the account of the player creating the token
23
+ belongs_to :creator, class_name: 'Core::Models::Account', inverse_of: :tokens
24
+
25
+ validates :name,
26
+ presence: {message: 'required'},
27
+ length: {minimum: 6, message: 'minlength', if: :name?}
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Core
4
+ module Models
5
+ module Campaigns
6
+ # This is the instanciation of a token in one of the map of the campaign
7
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
8
+ class TokenPosition
9
+ include Mongoid::Document
10
+ include Mongoid::Timestamps
11
+
12
+ store_in collection: 'token_positions'
13
+
14
+ # @!attribute [rw] x
15
+ # @return [Integer] the number of cells from the left before this token
16
+ field :x, type: Integer, default: 0
17
+ # @!attribute [rw] y
18
+ # @return [Integer] the number of cells from the top before this token
19
+ field :y, type: Integer, default: 0
20
+
21
+ # @!attribute [rw] map
22
+ # @return [Core::Models::Campaigns::Map] the map where this token is instanciated.
23
+ embedded_in :map, class_name: 'Core::Models::Campaigns::Map', inverse_of: :positions
24
+
25
+ # @!attribute [rw] token
26
+ # @return [Core::Models::Campaigns::Token] the source of the token, used to determine its appearance.
27
+ belongs_to :token, class_name: 'Core::Models::Campaigns::Token', inverse_of: :positions
28
+
29
+ validate :coordinates_bounds
30
+
31
+ # Validates that the coordinates of the token position are in the map bounds.
32
+ def coordinates_bounds
33
+ errors.add(:x, 'bounds') if map.nil? or x < 0 or x >= map.width
34
+ errors.add(:y, 'bounds') if map.nil? or y < 0 or y >= map.height
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -4,7 +4,10 @@ module Core
4
4
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
5
  module Campaigns
6
6
  autoload :Invitation, 'core/models/campaigns/invitation'
7
+ autoload :Map , 'core/models/campaigns/map'
7
8
  autoload :Tag , 'core/models/campaigns/tag'
9
+ autoload :Token , 'core/models/campaigns/token'
10
+ autoload :TokenPosition, 'core/models/campaigns/token_position'
8
11
  end
9
12
  end
10
13
  end
@@ -7,6 +7,9 @@ module Core
7
7
  # @!attribute [rw] campaign
8
8
  # @return [Core::Models::Campaign] the campaign the chatroom is linked to.
9
9
  embedded_in :campaign, class_name: 'Core::Models::Campaign', inverse_of: :chatroom
10
+ # @!attribute [rw] messages
11
+ # @return [Array<Core::Models::Chatrooms::Messages>] the messages said in this conversation
12
+ has_many :messages, class_name: 'Core::Models::Chatrooms::Message', inverse_of: :chatroom
10
13
  end
11
14
  end
12
15
  end
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Timestamps
9
9
  include Core::Models::Concerns::Enumerable
10
10
 
11
+ store_in collection: 'chatrooms'
12
+
11
13
  # @!attribute [rw] type
12
14
  # @return [Symbol] the type of message (plain text or command) contained in the data, used to parse and display it.
13
15
  enum_field :type, [:text, :command], default: :text
@@ -7,6 +7,8 @@ module Core
7
7
  include Mongoid::Document
8
8
  include Mongoid::Timestamps
9
9
 
10
+ store_in collection: 'documents'
11
+
10
12
  # @!attribute [rw] name
11
13
  # @return [String] the filename the user entered when uploading the file.
12
14
  field :name, type: String
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Timestamps
9
9
  include Core::Models::Concerns::Enumerable
10
10
 
11
+ store_in collection: 'document_permissions'
12
+
11
13
  # @!attribute [rw] type
12
14
  # @return [Symbol] the type of permission granted (is the user able to delete the file ?)
13
15
  enum_field :type, [:read, :read_write]
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Document
9
9
  include Mongoid::Timestamps
10
10
 
11
+ store_in collection: 'oauth_access_token'
12
+
11
13
  # @!attribute [rw] value
12
14
  # @return [String] the value of the token, returned to the application when built.
13
15
  field :value, type: String, default: ->{ SecureRandom.hex }
@@ -7,6 +7,8 @@ module Core
7
7
  include Mongoid::Document
8
8
  include Mongoid::Timestamps
9
9
 
10
+ store_in collection: 'oauth_application'
11
+
10
12
  # @!attribute [rw] name
11
13
  # @return [String] the unique name of the application, mainly used to identify and display it.
12
14
  field :name, type: String
@@ -10,6 +10,8 @@ module Core
10
10
  include Mongoid::Document
11
11
  include Mongoid::Timestamps
12
12
 
13
+ store_in collection: 'oauth_authorization'
14
+
13
15
  # @!attribute [rw] code
14
16
  # @return [String] the value corresponding to the authentication code in the RFC of OAuth2.0, kep for historic purpose.
15
17
  field :code, type: String, default: ->{ SecureRandom.hex }
@@ -7,6 +7,8 @@ module Core
7
7
  include Mongoid::Document
8
8
  include Mongoid::Timestamps
9
9
 
10
+ store_in collection: 'oauth_refresh_token'
11
+
10
12
  # @!attribute [rw] value
11
13
  # @return [String] the value of the token, returned to the application when built.
12
14
  field :value, type: String, default: ->{ SecureRandom.hex }
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Timestamps
9
9
  include Core::Models::Concerns::Sluggable
10
10
 
11
+ store_in collection: 'categories'
12
+
11
13
  has_many :rights, class_name: 'Core::Models::Permissions::Right', inverse_of: :category
12
14
 
13
15
  make_sluggable 'category'
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Timestamps
9
9
  include Core::Models::Concerns::Sluggable
10
10
 
11
+ store_in collection: 'groups'
12
+
11
13
  # @!attribute [rw] is_default
12
14
  # @return [Boolean] a boolean indicating whether this group is given when a new user registered or not.
13
15
  field :is_default, type: Boolean, default: false
@@ -8,6 +8,8 @@ module Core
8
8
  include Mongoid::Timestamps
9
9
  include Core::Models::Concerns::Sluggable
10
10
 
11
+ store_in collection: 'rights'
12
+
11
13
  # @!attribute [rw] groups
12
14
  # @return [Array<Core::Models::Permissions::Group>] the groups granted with the permission to access features opened by this right.
13
15
  has_and_belongs_to_many :groups, class_name: 'Core::Models::Permissions::Group', inverse_of: :rights
@@ -9,6 +9,8 @@ module Core
9
9
  include Core::Models::Concerns::Premiumable
10
10
  include Core::Models::Concerns::Activable
11
11
 
12
+ store_in collection: 'routes'
13
+
12
14
  # @!attribute [rw] path
13
15
  # @return [String] the path (URI) of the route in the API.
14
16
  field :path, type: String, default: '/'
@@ -6,6 +6,8 @@ module Core
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps
8
8
 
9
+ store_in collection: 'rulesets'
10
+
9
11
  # @!attribute [rw] name
10
12
  # @return [String] the name of the ruleset (eq. "Dungeons and Dragons 4th Edition")
11
13
  field :name, type: String
@@ -0,0 +1,16 @@
1
+ module Core
2
+ module Services
3
+ class Accounts < Core::Services::Base
4
+ def get_by_username(username)
5
+ account = Core::Models::Account.find_by(username: username)
6
+ if account.nil?
7
+ raise Core::Helpers::Errors::NotFound.new(
8
+ field: 'username',
9
+ error: 'unknown'
10
+ )
11
+ end
12
+ account
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Core
2
+ module Services
3
+ class Base
4
+ attr_reader :services
5
+
6
+ def initialize(registry)
7
+ @services = registry
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Core
2
+ module Services
3
+ # The registry holds references to all the services accessible in the library. To access
4
+ # all services and be able to manage resources easily, just instanciate the
5
+ class Registry
6
+
7
+ attr_reader :accounts, :sessions
8
+
9
+ def initialize
10
+ @accounts = Core::Services::Accounts.new(self)
11
+ @sessions = Core::Services::Sessions.new(self)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ require 'bcrypt'
2
+ require 'securerandom'
3
+
4
+ module Core
5
+ module Services
6
+ # Service concerning sessions (log in and log out)
7
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
8
+ class Sessions < Core::Services::Base
9
+ # Creates a new session from the given user credentials. IT will
10
+ # * check that the user exists in the database
11
+ # * check that the password matches the user encrypted password
12
+ # If both steps are correctly passed, it will create and return
13
+ # a session object so that the user can have a login token.
14
+ #
15
+ # @param username [string] the name of the user trying to log in
16
+ # @param password [string] the password the user has provided
17
+ # @return [Core::Models::Authentication::Session] the login session
18
+ def create(username, password)
19
+ account = services.accounts.get_by_username(username)
20
+ if BCrypt::Password.new(account.password_digest) != password
21
+ raise Core::Helpers::Errors::Forbidden.new(
22
+ field: 'password',
23
+ error: 'wrong'
24
+ )
25
+ end
26
+ return Core::Models::Authentication::Session.create(
27
+ account: account,
28
+ token: SecureRandom.uuid
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Core
2
+ module Services
3
+ autoload :Accounts, 'core/services/accounts'
4
+ autoload :Base, 'core/services/base'
5
+ autoload :Registry, 'core/services/registry'
6
+ autoload :Sessions, 'core/services/sessions'
7
+ end
8
+ end
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Core
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/core.rb CHANGED
@@ -9,4 +9,5 @@ module Core
9
9
  autoload :Controllers, 'core/controllers'
10
10
  autoload :Helpers, 'core/helpers'
11
11
  autoload :Models, 'core/models'
12
+ autoload :Services, 'core/services'
12
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtuatable-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_cleaner
@@ -252,14 +252,14 @@ dependencies:
252
252
  name: sinatra
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - ">="
255
+ - - '='
256
256
  - !ruby/object:Gem::Version
257
257
  version: 2.1.0
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - ">="
262
+ - - '='
263
263
  - !ruby/object:Gem::Version
264
264
  version: 2.1.0
265
265
  - !ruby/object:Gem::Dependency
@@ -306,12 +306,13 @@ files:
306
306
  - lib/core/models/campaign.rb
307
307
  - lib/core/models/campaigns.rb
308
308
  - lib/core/models/campaigns/invitation.rb
309
+ - lib/core/models/campaigns/map.rb
309
310
  - lib/core/models/campaigns/tag.rb
311
+ - lib/core/models/campaigns/token.rb
312
+ - lib/core/models/campaigns/token_position.rb
310
313
  - lib/core/models/chatrooms.rb
311
314
  - lib/core/models/chatrooms/base.rb
312
315
  - lib/core/models/chatrooms/campaign.rb
313
- - lib/core/models/chatrooms/conversation.rb
314
- - lib/core/models/chatrooms/membership.rb
315
316
  - lib/core/models/chatrooms/message.rb
316
317
  - lib/core/models/concerns.rb
317
318
  - lib/core/models/concerns/activable.rb
@@ -337,6 +338,11 @@ files:
337
338
  - lib/core/models/permissions/right.rb
338
339
  - lib/core/models/permissions/route.rb
339
340
  - lib/core/models/ruleset.rb
341
+ - lib/core/services.rb
342
+ - lib/core/services/accounts.rb
343
+ - lib/core/services/base.rb
344
+ - lib/core/services/registry.rb
345
+ - lib/core/services/sessions.rb
340
346
  - lib/core/version.rb
341
347
  homepage: https://rubygems.org/gems/virtuatable-core
342
348
  licenses:
@@ -1,9 +0,0 @@
1
- module Core
2
- module Models
3
- module Chatrooms
4
- class Conversation < Core::Models::Chatrooms::Base
5
- has_many :memberships, class_name: 'Core::Models::Chatrooms::Membership', inverse_of: :chatroom
6
- end
7
- end
8
- end
9
- end
@@ -1,17 +0,0 @@
1
- module Core
2
- module Models
3
- module Chatrooms
4
- class Membership
5
- include Mongoid::Document
6
- include Mongoid::Timestamps
7
- include Core::Models::Concerns::Enumerable
8
-
9
- enum_field :status, [:shown, :hidden], default: :shown
10
-
11
- belongs_to :chatroom, class_name: 'Core::Models::Chatrooms::Private', inverse_of: :memberships
12
-
13
- belongs_to :account, class_name: 'Core::Models::Account', inverse_of: :memberships
14
- end
15
- end
16
- end
17
- end