virtuatable-core 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core/decorators/campaign.rb +20 -0
- data/lib/core/decorators.rb +5 -0
- data/lib/core/helpers/declarators.rb +2 -2
- data/lib/core/services/accounts.rb +3 -1
- data/lib/core/services/campaigns.rb +26 -0
- data/lib/core/services/registry.rb +5 -3
- data/lib/core/services/sessions.rb +3 -2
- data/lib/core/services.rb +1 -1
- data/lib/core/version.rb +1 -1
- data/lib/core.rb +7 -1
- metadata +19 -3
- data/lib/core/services/base.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d95c03cd13525c1a5326004d88c62a806c0e991ef8dd0766f0f2465078f2b23e
|
4
|
+
data.tar.gz: d217b7fd979676aa8b61cd58fb8ad54a3abd352fe105713700c12edc39abfdd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c180ac1d407073cc75d81a8d08f9394ef6d025cb899c4971a94ee6daa213ca5bcf4d240bd491b2374c60c7e2abfab80729226af37b0b7bdc60c0d7c3b2af326
|
7
|
+
data.tar.gz: d2c695ecb5ad843dc18789f84e6028bde42fb74949351f9f3308018d2c57cd29ef87a9ecc1d2cc8b4cf29a87c6ac73eab12b29177c32c6f0ba915798bc24bbd3
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Core
|
2
|
+
module Decorators
|
3
|
+
class Campaign < Draper::Decorator
|
4
|
+
delegate_all
|
5
|
+
|
6
|
+
def to_simple_h
|
7
|
+
{
|
8
|
+
id: id.to_s,
|
9
|
+
title: title,
|
10
|
+
description: description,
|
11
|
+
tags: tags,
|
12
|
+
players: {
|
13
|
+
current: invitations.where(status: :accepted).count,
|
14
|
+
max: max_players
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -13,9 +13,9 @@ module Core
|
|
13
13
|
# @param verb [String] the HTTP method for the route.
|
14
14
|
# @param path [String] the whole URI with parameters for the route.
|
15
15
|
# @param options [Hash] the additional options for the route.
|
16
|
-
def api_route(verb, path, premium: false, scopes: [
|
16
|
+
def api_route(verb, path, premium: false, scopes: [], &block)
|
17
17
|
send(verb, path) do
|
18
|
-
scope_objects = fetch_scopes(scopes)
|
18
|
+
scope_objects = fetch_scopes(scopes + ['data::usage'])
|
19
19
|
appli = application(premium: premium)
|
20
20
|
check_app_scopes(appli, scope_objects)
|
21
21
|
check_token_scopes(token, scope_objects)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Core
|
2
|
+
module Services
|
3
|
+
class Campaigns
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
# Lists all the campaigns of a user identified by its account.
|
7
|
+
#
|
8
|
+
# @param account [Core::Models::Account] the user requesting its campaigns.
|
9
|
+
# @param page [Integer] the page in the list of campaigns to return to the users.
|
10
|
+
# @param per_page [Integer] the number of campaigns per page.
|
11
|
+
#
|
12
|
+
# @return [Array<Hash>] an array of hash representing campaigns.
|
13
|
+
def list(account, page: 0, per_page: 20, **ignored)
|
14
|
+
campaigns = campaigns(account).skip(page * per_page).limit(per_page)
|
15
|
+
campaigns.map do |campaign|
|
16
|
+
Core::Decorators::Campaign.new(campaign).to_simple_h
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def campaigns(account)
|
21
|
+
invitations = account.invitations.where(enum_status: 'creator')
|
22
|
+
Core::Models::Campaign.where(:id.in => invitations.map(&:campaign_id))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,12 +3,14 @@ module Core
|
|
3
3
|
# The registry holds references to all the services accessible in the library. To access
|
4
4
|
# all services and be able to manage resources easily, just instanciate the
|
5
5
|
class Registry
|
6
|
+
include Singleton
|
6
7
|
|
7
|
-
attr_reader :accounts, :sessions
|
8
|
+
attr_reader :accounts, :sessions, :campaigns
|
8
9
|
|
9
10
|
def initialize
|
10
|
-
@accounts = Core::Services::Accounts.
|
11
|
-
@sessions = Core::Services::Sessions.
|
11
|
+
@accounts = Core::Services::Accounts.instance
|
12
|
+
@sessions = Core::Services::Sessions.instance
|
13
|
+
@campaigns = Core::Services::Campaigns.instance
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -5,7 +5,8 @@ module Core
|
|
5
5
|
module Services
|
6
6
|
# Service concerning sessions (log in and log out)
|
7
7
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
8
|
-
class Sessions
|
8
|
+
class Sessions
|
9
|
+
include Singleton
|
9
10
|
# Creates a new session from the given user credentials. IT will
|
10
11
|
# * check that the user exists in the database
|
11
12
|
# * check that the password matches the user encrypted password
|
@@ -16,7 +17,7 @@ module Core
|
|
16
17
|
# @param password [string] the password the user has provided
|
17
18
|
# @return [Core::Models::Authentication::Session] the login session
|
18
19
|
def create(username, password)
|
19
|
-
account =
|
20
|
+
account = Core.svc.accounts.get_by_username(username)
|
20
21
|
if BCrypt::Password.new(account.password_digest) != password
|
21
22
|
raise Core::Helpers::Errors::Forbidden.new(
|
22
23
|
field: 'password',
|
data/lib/core/services.rb
CHANGED
@@ -5,8 +5,8 @@ module Core
|
|
5
5
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
6
|
module Services
|
7
7
|
autoload :Accounts, 'core/services/accounts'
|
8
|
-
autoload :Base, 'core/services/base'
|
9
8
|
autoload :Registry, 'core/services/registry'
|
10
9
|
autoload :Sessions, 'core/services/sessions'
|
10
|
+
autoload :Campaigns, 'core/services/campaigns'
|
11
11
|
end
|
12
12
|
end
|
data/lib/core/version.rb
CHANGED
data/lib/core.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
%w[active_model mongoid active_support].each { |g| require g }
|
3
|
+
%w[active_model mongoid active_support draper].each { |g| require g }
|
4
4
|
|
5
5
|
# Main module of the application, holding all the subsequent classes.
|
6
6
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
7
7
|
module Core
|
8
8
|
autoload :Controllers, 'core/controllers'
|
9
|
+
autoload :Decorators, 'core/decorators'
|
9
10
|
autoload :Helpers, 'core/helpers'
|
10
11
|
autoload :Models, 'core/models'
|
11
12
|
autoload :Services, 'core/services'
|
13
|
+
|
14
|
+
# Returns the registry of services for easier access to each of them.
|
15
|
+
def self.svc
|
16
|
+
Core::Services::Registry.instance
|
17
|
+
end
|
12
18
|
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.
|
4
|
+
version: 1.5.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-05-
|
11
|
+
date: 2022-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_cleaner
|
@@ -276,6 +276,20 @@ dependencies:
|
|
276
276
|
- - '='
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: 2.1.0
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: draper
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - ">="
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
286
|
+
type: :runtime
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - ">="
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0'
|
279
293
|
description: This gem holds the model layer for my table-top RPG games application.
|
280
294
|
email: courtois.vincent@outlook.com
|
281
295
|
executables: []
|
@@ -285,6 +299,8 @@ files:
|
|
285
299
|
- lib/core.rb
|
286
300
|
- lib/core/controllers.rb
|
287
301
|
- lib/core/controllers/base.rb
|
302
|
+
- lib/core/decorators.rb
|
303
|
+
- lib/core/decorators/campaign.rb
|
288
304
|
- lib/core/helpers.rb
|
289
305
|
- lib/core/helpers/accounts.rb
|
290
306
|
- lib/core/helpers/applications.rb
|
@@ -337,7 +353,7 @@ files:
|
|
337
353
|
- lib/core/models/ruleset.rb
|
338
354
|
- lib/core/services.rb
|
339
355
|
- lib/core/services/accounts.rb
|
340
|
-
- lib/core/services/
|
356
|
+
- lib/core/services/campaigns.rb
|
341
357
|
- lib/core/services/registry.rb
|
342
358
|
- lib/core/services/sessions.rb
|
343
359
|
- lib/core/version.rb
|