virtuatable-core 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/core/controllers/base.rb +2 -4
  3. data/lib/core/helpers/applications.rb +2 -2
  4. data/lib/core/helpers/declarators.rb +6 -6
  5. data/lib/core/helpers/routes.rb +2 -2
  6. data/lib/core/helpers/sessions.rb +2 -2
  7. data/lib/core/models/account.rb +2 -2
  8. data/lib/core/models/authentication/session.rb +2 -0
  9. data/lib/core/models/campaign.rb +7 -1
  10. data/lib/core/models/campaigns/invitation.rb +2 -0
  11. data/lib/core/models/campaigns/map.rb +37 -0
  12. data/lib/core/models/campaigns/tag.rb +2 -0
  13. data/lib/core/models/campaigns/token.rb +31 -0
  14. data/lib/core/models/campaigns/token_position.rb +39 -0
  15. data/lib/core/models/campaigns.rb +3 -0
  16. data/lib/core/models/chatrooms/campaign.rb +3 -0
  17. data/lib/core/models/chatrooms/message.rb +3 -1
  18. data/lib/core/models/concerns/activable.rb +1 -1
  19. data/lib/core/models/concerns/premiumable.rb +1 -1
  20. data/lib/core/models/files/document.rb +2 -0
  21. data/lib/core/models/files/permission.rb +2 -0
  22. data/lib/core/models/notification.rb +1 -1
  23. data/lib/core/models/oauth/access_token.rb +2 -0
  24. data/lib/core/models/oauth/application.rb +4 -2
  25. data/lib/core/models/oauth/authorization.rb +2 -0
  26. data/lib/core/models/oauth/refresh_token.rb +2 -0
  27. data/lib/core/models/permissions/category.rb +2 -0
  28. data/lib/core/models/permissions/group.rb +4 -2
  29. data/lib/core/models/permissions/right.rb +2 -0
  30. data/lib/core/models/permissions/route.rb +3 -1
  31. data/lib/core/models/ruleset.rb +2 -0
  32. data/lib/core/services/accounts.rb +16 -0
  33. data/lib/core/services/base.rb +11 -0
  34. data/lib/core/services/registry.rb +15 -0
  35. data/lib/core/services/sessions.rb +33 -0
  36. data/lib/core/services.rb +8 -0
  37. data/lib/core/version.rb +1 -1
  38. data/lib/core.rb +1 -0
  39. metadata +14 -8
  40. data/lib/core/models/chatrooms/conversation.rb +0 -9
  41. data/lib/core/models/chatrooms/membership.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9afbc1d8f75f5d0b94194432b3a379a7b02d90d2490deeed47d46d9c89036b01
4
- data.tar.gz: 56cfd05e3f53df001a852d26b6abf992313d52598902ecb21809cd16708ae266
3
+ metadata.gz: b2c522c5694270544ff7aa08e434bc1af1978dbd4b8c5488eac48158e4ae18c7
4
+ data.tar.gz: 8490c9d478c1cf2d2b505312bd8824ce67bc759fce490ea980517ac8ec4cf1df
5
5
  SHA512:
6
- metadata.gz: 7f4fdde3ecd17bb2b33a535ce22c927783ab5d88c00f639ee9374fcc7b36c6680ed0e2f1ce50071a22e1c4784d453c1b74b0bc71d5b817bd72e0501faf637611
7
- data.tar.gz: 7622404c051938c9cee8567de61f25005e7f178ae4a7dd22146d279aa8413a52c92c25c36db2472a59588c2f0a10db22322d4f0ff8348fc3609124798bcd4587
6
+ metadata.gz: 2dd843cd275f9f9d5b0ee563a500069fa0af65c0ea716ad470147b87acfa62b2d369e122b36080a976567dee381bf2a4625b27b4b17d9faa485315463d945fa8
7
+ data.tar.gz: c0707af825058224eab8297cc92e370ed78be96ebe55876e99010c3a0603f3ea68f848e4f6171839a06a6241c36dcae7a4387cadb921f992f1a3dfc6116d38b6
@@ -55,10 +55,8 @@ module Core
55
55
  api_forbidden exception.message
56
56
  end
57
57
 
58
- if ENV['RACK_ENV'] != 'test'
59
- error StandardError do |error|
60
- api_error 500, "unknown_field.#{error.class.name}"
61
- end
58
+ error StandardError do |error|
59
+ api_error 500, "unknown_field.#{error.class.name}"
62
60
  end
63
61
  end
64
62
  end
@@ -6,7 +6,7 @@ module Core
6
6
  # @author Vincent Courtois <courtois.vincent@outlook.com>
7
7
  module Applications
8
8
  # Looks for the application sending the API's request, and raises error if not found.
9
- # @param [Arkaan::OAuth::Application] the application requesting the service.
9
+ # @param [Core::Models::OAuth::Application] the application requesting the service.
10
10
  def application(premium: false)
11
11
  return @application unless @application.nil?
12
12
 
@@ -19,7 +19,7 @@ module Core
19
19
  end
20
20
 
21
21
  def application_model
22
- Arkaan::OAuth::Application
22
+ Core::Models::OAuth::Application
23
23
  end
24
24
  end
25
25
  end
@@ -7,7 +7,7 @@ module Core
7
7
  # @author Vincent Courtois <courtois.vincent@outlook.com>
8
8
  module Declarators
9
9
  # @!attribute [r] routes
10
- # @return [Array<Arkaan::Monitoring::Route>] the currently declared routes.
10
+ # @return [Array<Core::Models::Permissions::Route>] the currently declared routes.
11
11
  attr_reader :api_routes
12
12
 
13
13
  # Main method to declare new routes, persisting them in the database and
@@ -33,9 +33,9 @@ module Core
33
33
  # Add a route to the database, then to the routes array.
34
34
  # @param verb [String] the HTTP method used to request this route.
35
35
  # @param path [String] the path used to request this route.
36
- # @return [Arkaan::Monitoring::Route] the created route.
36
+ # @return [Core::Models::Permissions::Route] the created route.
37
37
  def add_route(verb:, path:, options:)
38
- route = Arkaan::Monitoring::Route.find_or_create_by!(
38
+ route = Core::Models::Permissions::Route.find_or_create_by!(
39
39
  path: path,
40
40
  verb: verb.downcase,
41
41
  premium: options[:premium],
@@ -47,7 +47,7 @@ module Core
47
47
  end
48
48
 
49
49
  # Pushes the route in the api routes list, by creating it if needed
50
- # @param route [Arkaan::Monitoring::Route] the route to push in the list of routes.
50
+ # @param route [Core::Models::Permissions::Route] the route to push in the list of routes.
51
51
  def push_route(route)
52
52
  @api_routes << route if api_routes.none? do |tmp_route|
53
53
  route.id == tmp_route.id
@@ -56,9 +56,9 @@ module Core
56
56
 
57
57
  # Add the default access permissions to a route. Any group tagged superuser
58
58
  # can automatically access any newly declared_route.
59
- # params route [Arkaan::Monitoring::Route] the route to add the permissions to.
59
+ # params route [Core::Models::Permissions::Route] the route to add the permissions to.
60
60
  def add_permissions(route)
61
- groups = Arkaan::Permissions::Group.where(is_superuser: true)
61
+ groups = Core::Models::Permissions::Group.where(is_superuser: true)
62
62
  groups.each do |group|
63
63
  unless route.groups.where(id: group.id).exists?
64
64
  route.groups << group
@@ -3,12 +3,12 @@
3
3
  module Core
4
4
  module Helpers
5
5
  # This module provides the #current_route method to get the current
6
- # Arkaan::Monitoring::Route object from whithin sinatra routes.
6
+ # Core::Models::Monitoring::Route object from whithin sinatra routes.
7
7
  # @author Vincent Courtois <courtois.vincent@outlook.com>
8
8
  module Routes
9
9
  # The currently requested API route, used to see inside the block
10
10
  # if the route is premium or not, authenticated or not.
11
- # @return [Arkaan::Monitoring::Route] the currently requested route.
11
+ # @return [Core::Models::Monitoring::Route] the currently requested route.
12
12
  def current_route
13
13
  splitted = request.env['sinatra.route'].split(' ')
14
14
  verb = splitted.first.downcase
@@ -13,7 +13,7 @@ module Core
13
13
  # @raise [Virtuatable::API::Errors::BadRequest] if the session token is
14
14
  # not correctly given in the parameters.
15
15
  #
16
- # @return [Arkaan::Authentication::Session] the current session of the user.
16
+ # @return [Core::Models::Authentication::Session] the current session of the user.
17
17
  def session
18
18
  return @session unless @session.nil?
19
19
 
@@ -23,7 +23,7 @@ module Core
23
23
  end
24
24
 
25
25
  def session_model
26
- Arkaan::Authentication::Session
26
+ Core::Models::Authentication::Session
27
27
  end
28
28
  end
29
29
  end
@@ -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
@@ -14,7 +16,7 @@ module Core
14
16
  field :description, type: String
15
17
  # @!attribute [rw] is_private
16
18
  # @return [Boolean] TRUE if the campaign can be joined only by being invited by the creator, FALSE if it's publicly displayed and accessible.
17
- field :is_private, type: Boolean, default: true
19
+ field :is_private, type: Mongoid::Boolean, default: true
18
20
  # @!attribute [rw] tags
19
21
  # @return [Array<String>] an array of tags describing characteristics of this campaign.
20
22
  field :tags, type: Array, default: []
@@ -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
@@ -19,7 +21,7 @@ module Core
19
21
  field :raw, type: String, default: ''
20
22
  # @!attribute [rw] deleted
21
23
  # @return [Boolean] TRUE if the message has been marked as deleted by its user, FALSE otherwise.
22
- field :deleted, type: Boolean, default: false
24
+ field :deleted, type: Mongoid::Boolean, default: false
23
25
 
24
26
  # @!attribute [rw] campaign
25
27
  # @return [Core::Models::Chatrooms::Campaign] the chatroom in which the message has been emitted.
@@ -9,7 +9,7 @@ module Core
9
9
  included do
10
10
  # @!attribute [rw] active
11
11
  # @return [Boolean] the active status of the instance, indicating if someone has deactivated it or not.
12
- field :active, type: Boolean, default: true
12
+ field :active, type: Mongoid::Boolean, default: true
13
13
 
14
14
  scope :active , ->{ where(active: true) }
15
15
  scope :inactive, ->{ where(active: false) }
@@ -9,7 +9,7 @@ module Core
9
9
  included do
10
10
  # @!attribute [rw] premium
11
11
  # @return [Boolean] TRUE if the entity is made to be accessible only to premiuma pplications, FALSE otherwise.
12
- field :premium, type: Boolean, default: false
12
+ field :premium, type: Mongoid::Boolean, default: false
13
13
  end
14
14
  end
15
15
  end
@@ -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]
@@ -11,7 +11,7 @@ module Core
11
11
  field :type, type: String, default: 'NOTIFICATIONS.DEFAULT'
12
12
  # @!attribute [rw] read
13
13
  # @return [Boolean] TRUE if the notification has been read (seen by the user), FALSE otherwise.
14
- field :read, type: Boolean, default: false
14
+ field :read, type: Mongoid::Boolean, default: false
15
15
  # @!attribute [rw] data
16
16
  # @return [Hash] the custom data that can be attached to this notification, for example for an invitation it can be the invited username.
17
17
  field :data, type: Hash, default: {}
@@ -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
@@ -15,7 +17,7 @@ module Core
15
17
  field :key, type: String, default: ->{ SecureRandom.hex }
16
18
  # @!attribute [rw] premium
17
19
  # @return [Boolean] a value indicating whether the application should automatically receive a token when an account is created, or not.
18
- field :premium, type: Boolean, default: false
20
+ field :premium, type: Mongoid::Boolean, default: false
19
21
  # @!attirbute [rw] redirect_uris
20
22
  # @return [Array<String>] the redirection URIs used for this application.
21
23
  field :redirect_uris, type: Array, default: []
@@ -46,7 +48,7 @@ module Core
46
48
  if !uri.is_a? String
47
49
  errors.add(:redirect_uris, 'type')
48
50
  break
49
- elsif uri.match(/\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z/).nil?
51
+ elsif uri.match(/\Ahttps?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)\z/).nil?
50
52
  errors.add(:redirect_uris, 'format')
51
53
  break
52
54
  end
@@ -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,12 +8,14 @@ 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
- field :is_default, type: Boolean, default: false
15
+ field :is_default, type: Mongoid::Boolean, default: false
14
16
  # @!attribute [rw] is_superuser
15
17
  # @return [Boolean] a boolean indicating whether this group should have access to all groups and rights or not.
16
- field :is_superuser, type: Boolean, default: false
18
+ field :is_superuser, type: Mongoid::Boolean, default: false
17
19
 
18
20
  # @!attribute [rw] accounts
19
21
  # @return [Array<Core::Models::Account>] the accounts having the rights granted by this group.
@@ -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: '/'
@@ -17,7 +19,7 @@ module Core
17
19
  field :verb, type: String, default: 'get'
18
20
  # @!attribute [rw] authenticated
19
21
  # @return [Boolean] if true, the session_id is needed for this route, if false it is not.
20
- field :authenticated, type: Boolean, default: true
22
+ field :authenticated, type: Mongoid::Boolean, default: true
21
23
  # @!attribute [rw] groups
22
24
  # @return [Array<Core::Models::Permissions::Group>] the groups having permission to access this route.
23
25
  has_and_belongs_to_many :groups, class_name: 'Core::Models::Permissions::Group', inverse_of: :groups
@@ -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.2'
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.2
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_cleaner
@@ -240,26 +240,26 @@ dependencies:
240
240
  requirements:
241
241
  - - '='
242
242
  - !ruby/object:Gem::Version
243
- version: 7.1.0
243
+ version: 7.4.0
244
244
  type: :runtime
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - '='
249
249
  - !ruby/object:Gem::Version
250
- version: 7.1.0
250
+ version: 7.4.0
251
251
  - !ruby/object:Gem::Dependency
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