arkaan 2.8.0 → 3.0.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 +4 -4
- data/lib/arkaan.rb +18 -16
- data/lib/arkaan/account.rb +22 -19
- data/lib/arkaan/authentication.rb +3 -1
- data/lib/arkaan/authentication/session.rb +10 -7
- data/lib/arkaan/campaign.rb +21 -19
- data/lib/arkaan/campaigns.rb +4 -2
- data/lib/arkaan/campaigns/invitation.rb +2 -2
- data/lib/arkaan/chatrooms.rb +7 -5
- data/lib/arkaan/chatrooms/base.rb +3 -1
- data/lib/arkaan/chatrooms/campaign.rb +3 -1
- data/lib/arkaan/chatrooms/conversation.rb +5 -1
- data/lib/arkaan/chatrooms/membership.rb +6 -2
- data/lib/arkaan/chatrooms/message.rb +5 -3
- data/lib/arkaan/concerns.rb +10 -8
- data/lib/arkaan/concerns/activable.rb +6 -4
- data/lib/arkaan/concerns/diagnosticable.rb +7 -5
- data/lib/arkaan/concerns/enumerable.rb +21 -9
- data/lib/arkaan/concerns/historizable.rb +7 -5
- data/lib/arkaan/concerns/mime_typable.rb +18 -10
- data/lib/arkaan/concerns/premiumable.rb +3 -1
- data/lib/arkaan/concerns/sluggable.rb +9 -8
- data/lib/arkaan/concerns/typable.rb +5 -3
- data/lib/arkaan/factories.rb +4 -2
- data/lib/arkaan/files.rb +6 -2
- data/lib/arkaan/files/document.rb +5 -3
- data/lib/arkaan/files/permission.rb +4 -2
- data/lib/arkaan/monitoring.rb +4 -2
- data/lib/arkaan/monitoring/route.rb +6 -3
- data/lib/arkaan/monitoring/service.rb +5 -3
- data/lib/arkaan/notification.rb +5 -2
- data/lib/arkaan/oauth.rb +6 -4
- data/lib/arkaan/oauth/access_token.rb +10 -8
- data/lib/arkaan/oauth/application.rb +17 -11
- data/lib/arkaan/oauth/authorization.rb +8 -6
- data/lib/arkaan/oauth/refresh_token.rb +7 -4
- data/lib/arkaan/permissions.rb +5 -3
- data/lib/arkaan/permissions/category.rb +4 -2
- data/lib/arkaan/permissions/group.rb +4 -2
- data/lib/arkaan/permissions/right.rb +8 -4
- data/lib/arkaan/ruleset.rb +6 -4
- metadata +2 -8
- data/lib/arkaan/decorators/errors.rb +0 -9
- data/lib/arkaan/decorators/errors/env_variable_missing.rb +0 -14
- data/lib/arkaan/decorators/gateway.rb +0 -109
- data/lib/arkaan/factories/errors.rb +0 -9
- data/lib/arkaan/factories/errors/gateway_not_found.rb +0 -14
- data/lib/arkaan/version.rb +0 -3
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
module OAuth
|
3
5
|
# An OAuth authorization is granted by a user to an application to access its personal data.
|
@@ -10,8 +12,8 @@ module Arkaan
|
|
10
12
|
include Mongoid::Timestamps
|
11
13
|
|
12
14
|
# @!attribute [rw] code
|
13
|
-
# @return [String] the value corresponding to the authentication code in the RFC of OAuth2.0
|
14
|
-
field :code, type: String, default: ->{ SecureRandom.hex }
|
15
|
+
# @return [String] the value corresponding to the authentication code in the RFC of OAuth2.0.
|
16
|
+
field :code, type: String, default: -> { SecureRandom.hex }
|
15
17
|
|
16
18
|
# @!attribute [rw] account
|
17
19
|
# @return [Arkaaan::Account] the account granting the authorization to access its data to the application.
|
@@ -20,12 +22,12 @@ module Arkaan
|
|
20
22
|
# @return [Arkaan::OAuth::Application] the application asking to access account's data.
|
21
23
|
belongs_to :application, class_name: 'Arkaan::OAuth::Application', inverse_of: :authorizations
|
22
24
|
# @!attribute [rw] token
|
23
|
-
# @return [Arkaan::OAuth::AccessToken] the access token used further in the application process to access
|
25
|
+
# @return [Arkaan::OAuth::AccessToken] the access token used further in the application process to access data.
|
24
26
|
has_many :tokens, class_name: 'Arkaan::OAuth::AccessToken', inverse_of: :authorization
|
25
27
|
|
26
28
|
validates :code,
|
27
|
-
|
28
|
-
|
29
|
+
presence: { message: 'required' },
|
30
|
+
uniqueness: { message: 'uniq' }
|
29
31
|
end
|
30
32
|
end
|
31
|
-
end
|
33
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
module OAuth
|
3
|
-
# A refresh token is used when an access token is expired, to get a new one.
|
5
|
+
# A refresh token is used when an access token is expired, to get a new one.
|
6
|
+
# It is then recreated for the next expiration.
|
4
7
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
8
|
class RefreshToken
|
6
9
|
include Mongoid::Document
|
@@ -8,11 +11,11 @@ module Arkaan
|
|
8
11
|
|
9
12
|
# @!attribute [rw] value
|
10
13
|
# @return [String] the value of the token, returned to the application when built.
|
11
|
-
field :value, type: String, default: ->{ SecureRandom.hex }
|
14
|
+
field :value, type: String, default: -> { SecureRandom.hex }
|
12
15
|
|
13
16
|
# @!attribute [rw] authorization
|
14
|
-
# @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application
|
17
|
+
# @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application.
|
15
18
|
belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :refresh_token
|
16
19
|
end
|
17
20
|
end
|
18
|
-
end
|
21
|
+
end
|
data/lib/arkaan/permissions.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
# This module holds the logic for all the classes concerning the permissions abd rights for the user.
|
3
5
|
# A permission is restricting the access to one or several features to the users having it.
|
4
6
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
7
|
module Permissions
|
6
|
-
autoload :Right
|
7
|
-
autoload :Group
|
8
|
+
autoload :Right, 'arkaan/permissions/right'
|
9
|
+
autoload :Group, 'arkaan/permissions/group'
|
8
10
|
autoload :Category, 'arkaan/permissions/category'
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
module Permissions
|
3
5
|
# A category of rights regroups one or several rights for convenience purposes.
|
@@ -9,7 +11,7 @@ module Arkaan
|
|
9
11
|
|
10
12
|
has_many :rights, class_name: 'Arkaan::Permissions::Right', inverse_of: :category
|
11
13
|
|
12
|
-
make_sluggable
|
14
|
+
make_sluggable
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
module Permissions
|
3
5
|
# A group gathers one or several users to give them the same rights for conviniency purposes.
|
@@ -24,7 +26,7 @@ module Arkaan
|
|
24
26
|
# @return [Array<Arkaan::Monitoring::Route>] the routes this group can access in the API.
|
25
27
|
has_and_belongs_to_many :routes, class_name: 'Arkaan::Monitoring::Route', inverse_of: :groups
|
26
28
|
|
27
|
-
make_sluggable
|
29
|
+
make_sluggable
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
module Permissions
|
3
|
-
# A right is the access to one or several features in the application.
|
5
|
+
# A right is the access to one or several features in the application.
|
6
|
+
# It's applied to a group, and transitively to an account.
|
4
7
|
# @author Vincent Courtois <courtois;vincent@outlook.com>
|
5
8
|
class Right
|
6
9
|
include Mongoid::Document
|
@@ -8,12 +11,13 @@ module Arkaan
|
|
8
11
|
include Arkaan::Concerns::Sluggable
|
9
12
|
|
10
13
|
# @!attribute [rw] groups
|
11
|
-
# @return [Array<Arkaan::Permissions::Group>] the groups granted with the permission to
|
14
|
+
# @return [Array<Arkaan::Permissions::Group>] the groups granted with the permission to
|
15
|
+
# access features opened by this right.
|
12
16
|
has_and_belongs_to_many :groups, class_name: 'Arkaan::Permissions::Group', inverse_of: :rights
|
13
17
|
|
14
18
|
belongs_to :category, class_name: 'Arkaan::Permissions::Category', inverse_of: :rights
|
15
19
|
|
16
|
-
make_sluggable
|
20
|
+
make_sluggable
|
17
21
|
end
|
18
22
|
end
|
19
|
-
end
|
23
|
+
end
|
data/lib/arkaan/ruleset.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arkaan
|
2
4
|
# A set of rules is describing how a specific game system works (eg. Dungeons and Dragons 5th Edition, or Fate)
|
3
5
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
@@ -23,8 +25,8 @@ module Arkaan
|
|
23
25
|
has_many :campaigns, class_name: 'Arkaan::Campaign', inverse_of: :ruleset
|
24
26
|
|
25
27
|
validates :name,
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
presence: { message: 'required' },
|
29
|
+
length: { minimum: 4, message: 'minlength', if: :name? },
|
30
|
+
uniqueness: { message: 'uniq', if: :name? }
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
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:
|
4
|
+
version: 3.0.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: 2020-10-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_cleaner
|
@@ -333,13 +333,8 @@ files:
|
|
333
333
|
- lib/arkaan/concerns/premiumable.rb
|
334
334
|
- lib/arkaan/concerns/sluggable.rb
|
335
335
|
- lib/arkaan/concerns/typable.rb
|
336
|
-
- lib/arkaan/decorators/errors.rb
|
337
|
-
- lib/arkaan/decorators/errors/env_variable_missing.rb
|
338
|
-
- lib/arkaan/decorators/gateway.rb
|
339
336
|
- lib/arkaan/event.rb
|
340
337
|
- lib/arkaan/factories.rb
|
341
|
-
- lib/arkaan/factories/errors.rb
|
342
|
-
- lib/arkaan/factories/errors/gateway_not_found.rb
|
343
338
|
- lib/arkaan/files.rb
|
344
339
|
- lib/arkaan/files/document.rb
|
345
340
|
- lib/arkaan/files/permission.rb
|
@@ -357,7 +352,6 @@ files:
|
|
357
352
|
- lib/arkaan/permissions/group.rb
|
358
353
|
- lib/arkaan/permissions/right.rb
|
359
354
|
- lib/arkaan/ruleset.rb
|
360
|
-
- lib/arkaan/version.rb
|
361
355
|
homepage: https://rubygems.org/gems/arkaan
|
362
356
|
licenses:
|
363
357
|
- MIT
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Decorators
|
3
|
-
# Module holding all the errors concerning the code of the decorators.
|
4
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
-
module Errors
|
6
|
-
autoload :EnvVariableMissing, 'arkaan/decorators/errors/env_variable_missing'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Decorators
|
3
|
-
module Errors
|
4
|
-
# Error raised if the application key variable is missing.
|
5
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
-
class EnvVariableMissing < Arkaan::Utils::Errors::HTTPError
|
7
|
-
|
8
|
-
def initialize(action:)
|
9
|
-
super(action, 'app_key', 'not_found', 404)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Decorators
|
3
|
-
# Decorator for a service, providing methods to make requests on it.
|
4
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
-
class Gateway < Draper::Decorator
|
6
|
-
delegate_all
|
7
|
-
|
8
|
-
# @!attribute [rw] action
|
9
|
-
# @return [String] the action of the route using this API.
|
10
|
-
attr_accessor :action
|
11
|
-
|
12
|
-
attr_accessor :logger
|
13
|
-
|
14
|
-
def initialize(action, _object)
|
15
|
-
super(_object)
|
16
|
-
@logger = Logger.new(STDOUT)
|
17
|
-
@action = action
|
18
|
-
end
|
19
|
-
|
20
|
-
# Shortcut to make a DELETE request on the API.
|
21
|
-
# @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
|
22
|
-
# @param url [String] the URL you want to reach on the service.
|
23
|
-
# @param params [Hash] the additional parameters to pass in the JSON body.
|
24
|
-
def delete(session:, url:, params:)
|
25
|
-
return make_request_without_body(verb: 'delete', session: session, url: url, params: params)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Shortcut to make a GET request on the API.
|
29
|
-
# @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
|
30
|
-
# @param url [String] the URL you want to reach on the service.
|
31
|
-
# @param params [Hash] the additional parameters to pass in the JSON body.
|
32
|
-
def get(session:, url:, params:)
|
33
|
-
return make_request_without_body(verb: 'get', session: session, url: url, params: params)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Shortcut to make a POST request on the API.
|
37
|
-
# @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
|
38
|
-
# @param url [String] the URL you want to reach on the service.
|
39
|
-
# @param params [Hash] the additional parameters to pass in the JSON body.
|
40
|
-
def post(session:, url:, params:)
|
41
|
-
return make_request(verb: 'post', session: session, url: url, params: params)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Shortcut to make a PUT request on the API.
|
45
|
-
# @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
|
46
|
-
# @param url [String] the URL you want to reach on the service.
|
47
|
-
# @param params [Hash] the additional parameters to pass in the JSON body.
|
48
|
-
def put(session:, url:, params:)
|
49
|
-
return make_request(verb: 'put', session: session, url: url, params: params)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Makes a POST request to the given service with the following steps :
|
55
|
-
# 1. Gets an active and running instance of the service to make the request.
|
56
|
-
# 2. Creates a Faraday connection to use it as a pipeline for the request.
|
57
|
-
# 3. Makes the actual request and returns an object with the status and body of the response.
|
58
|
-
#
|
59
|
-
# @param verb [String] the HTTP verb to use for this request.
|
60
|
-
# @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
|
61
|
-
# @param url [String] the URL you want to reach on the service.
|
62
|
-
# @param params [Hash] the additional parameters to pass in the JSON body.
|
63
|
-
#
|
64
|
-
# @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
|
65
|
-
# to the status and body of the response to the request
|
66
|
-
def make_request(verb:, session:, url:, params:)
|
67
|
-
params = before_requests(session, params)
|
68
|
-
connection = get_connection
|
69
|
-
|
70
|
-
response = connection.send(verb) do |req|
|
71
|
-
req.url url
|
72
|
-
req.headers['Content-Type'] = 'application/json'
|
73
|
-
req.body = params.to_json
|
74
|
-
end
|
75
|
-
|
76
|
-
return {
|
77
|
-
status: response.status,
|
78
|
-
body: JSON.parse(response.body)
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
def make_request_without_body(verb:, session:, url:, params:)
|
83
|
-
params = before_requests(session, params)
|
84
|
-
connection = get_connection
|
85
|
-
response = connection.send(verb) do |req|
|
86
|
-
req.url url, params
|
87
|
-
req.headers['Content-Type'] = 'application/json'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def before_requests(session, params)
|
92
|
-
if ENV['APP_KEY'].nil?
|
93
|
-
raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action: action)
|
94
|
-
end
|
95
|
-
params[:app_key] = ENV['APP_KEY']
|
96
|
-
params[:session_id] = session.token
|
97
|
-
return params
|
98
|
-
end
|
99
|
-
|
100
|
-
def get_connection
|
101
|
-
Faraday.new(object.url) do |faraday|
|
102
|
-
faraday.request :url_encoded
|
103
|
-
faraday.response :logger
|
104
|
-
faraday.adapter Faraday.default_adapter
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Factories
|
3
|
-
# Module holding all the errors concerning the code of the factories.
|
4
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
-
module Errors
|
6
|
-
autoload :GatewayNotFound, 'arkaan/factories/errors/gateway_not_found'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Arkaan
|
2
|
-
module Factories
|
3
|
-
module Errors
|
4
|
-
# Error raised when not gateway active and running is found in the factory.
|
5
|
-
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
-
class GatewayNotFound < Arkaan::Utils::Errors::HTTPError
|
7
|
-
|
8
|
-
def initialize(action:)
|
9
|
-
super(action, 'gateway_id', 'not_found', 404)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/arkaan/version.rb
DELETED