morpho 1.0.1 → 1.1.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: 3536e547cc737f7badcac9844606c355f2fd28a60e26cc7c5cbc877e269e4bb8
4
- data.tar.gz: 524baa415ee30782dc65cb722683688bf3ee931be52394a1ca80f7c3dd40ae87
3
+ metadata.gz: c7caf113b827232f529da9eae464def330b46e1f507d0a1e440aedc5325cf690
4
+ data.tar.gz: 9a8163a9bd725cd0f525ab3bbfe50f084d91e2c98f92a4811641e2a39e08b5c2
5
5
  SHA512:
6
- metadata.gz: 02431c3b8fa188adbbd2efa4335375fa4754ff829eff1525a8e94a631ccd9f7c6075e11dcfd6aa29fee6e6eb846cdb195595debfe6328e076ad2358e28cfc686
7
- data.tar.gz: e01fc5410f8d5e0f291378db7ce32dcc72664e988a77f6368219a9bdc645b367e1366af042f5499a981f955d7faf19c14d002a113a3e06a1153d782531e4c497
6
+ metadata.gz: 6a446b9690227aa894fe7497a03e0c3d6ba743b2547b275a6c11c56eefe8361a05ccf5f5db1c3e690c4144dfd9d6216a8990c6470ae01637fb148ca31c44b093
7
+ data.tar.gz: 2066ae49183978f79be5f0ba700657acee923d9e94807609a3a71305532b14f33e02fdeb94886eb413b53a3e53324e2e8ca7b6e6d9f340ebb2572b1ce229c2b6
@@ -2,7 +2,7 @@ module Morpho
2
2
  module Entities
3
3
  class Error < ::Grape::Entity
4
4
  expose :message, documentation: { type: 'string', desc: 'Error standard message', required: true }
5
- expose :errors, safe: true, documentation: { type: 'string', desc: 'Error message details', is_array: true }
5
+ expose :errors, safe: true, documentation: { type: 'object', desc: 'Error message details' }
6
6
  end
7
7
  end
8
8
  end
@@ -1,9 +1,9 @@
1
1
  module Morpho
2
2
  module Entities
3
3
  class External < ::Morpho::Entities::Base
4
- expose :email, documentation: { type: 'string', desc: 'User email address' }
5
- expose :provider, documentation: { type: 'string', desc: 'User authentication provider' }
6
- expose :uid, documentation: { type: 'string', desc: 'User provider uid' }
4
+ expose :email, documentation: { type: 'string', desc: 'User email address', required: true }
5
+ expose :provider, documentation: { type: 'string', desc: 'User authentication provider', required: true }
6
+ expose :uid, documentation: { type: 'string', desc: 'User provider uid', required: true }
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Morpho
3
3
  module HTTPResponses
4
4
  protected
5
5
 
6
- def render_bad_request(errors = [])
6
+ def render_bad_request(errors = {})
7
7
  error!({
8
8
  message: I18n.t('morpho.api.messages.bad_request'),
9
9
  errors: errors,
@@ -11,7 +11,7 @@ module Morpho
11
11
  }, 400)
12
12
  end
13
13
 
14
- def render_unauthorized(errors = [])
14
+ def render_unauthorized(errors = {})
15
15
  error!({
16
16
  message: I18n.t('morpho.api.messages.unauthorized'),
17
17
  errors: errors,
@@ -19,11 +19,11 @@ module Morpho
19
19
  }, 401)
20
20
  end
21
21
 
22
- def render_unauthorized_detailed(errors = [])
22
+ def render_unauthorized_detailed(errors = {})
23
23
  render_unauthorized(errors)
24
24
  end
25
25
 
26
- def render_payment_required(errors = [])
26
+ def render_payment_required(errors = {})
27
27
  error!({
28
28
  message: I18n.t('morpho.api.messages.payment_required'),
29
29
  errors: errors,
@@ -31,7 +31,7 @@ module Morpho
31
31
  }, 402)
32
32
  end
33
33
 
34
- def render_forbidden(errors = [])
34
+ def render_forbidden(errors = {})
35
35
  error!({
36
36
  message: I18n.t('morpho.api.messages.forbidden'),
37
37
  errors: errors,
@@ -39,7 +39,7 @@ module Morpho
39
39
  }, 403)
40
40
  end
41
41
 
42
- def render_not_found(errors = [])
42
+ def render_not_found(errors = {})
43
43
  error!({
44
44
  message: I18n.t('morpho.api.messages.not_found'),
45
45
  errors: errors,
@@ -47,7 +47,7 @@ module Morpho
47
47
  }, 404)
48
48
  end
49
49
 
50
- def render_method_not_allowed(errors = [])
50
+ def render_method_not_allowed(errors = {})
51
51
  error!({
52
52
  message: I18n.t('morpho.api.messages.method_not_allowed'),
53
53
  errors: errors,
@@ -55,7 +55,7 @@ module Morpho
55
55
  }, 405)
56
56
  end
57
57
 
58
- def render_unprocessable_entity(errors = [])
58
+ def render_unprocessable_entity(errors = {})
59
59
  error!({
60
60
  message: I18n.t('morpho.api.messages.unprocessable_entity'),
61
61
  errors: errors,
@@ -63,7 +63,7 @@ module Morpho
63
63
  }, 422)
64
64
  end
65
65
 
66
- def render_locked(errors = [])
66
+ def render_locked(errors = {})
67
67
  error!({
68
68
  message: I18n.t('morpho.api.messages.locked'),
69
69
  errors: errors,
@@ -71,7 +71,7 @@ module Morpho
71
71
  }, 423)
72
72
  end
73
73
 
74
- def render_unprocessable_entity_detailed(errors = [])
74
+ def render_unprocessable_entity_detailed(errors = {})
75
75
  render_unprocessable_entity(errors)
76
76
  end
77
77
 
@@ -22,14 +22,12 @@ module Morpho
22
22
  present result['model'], with: Morpho::Entities::User
23
23
  else
24
24
  case result['error']
25
- when :not_valid
25
+ when :unprocessable_entity
26
26
  render_unprocessable_entity(result['contract'].errors)
27
27
  when :not_found
28
- render_not_found
29
- when :not_allowed
30
- render_method_not_allowed
31
- when :not_delivered
32
- render_unprocessable_entity
28
+ render_not_found({ base: I18n.t('morpho.api.messages.activate.not_found') })
29
+ when :method_not_allowed
30
+ render_method_not_allowed({ base: I18n.t('morpho.api.messages.activate.method_not_allowed') })
33
31
  else
34
32
  render_unprocessable_entity
35
33
  end
@@ -17,7 +17,7 @@ module Morpho
17
17
  present result['token'], with: Morpho::Entities::AuthenticationToken
18
18
  else
19
19
  case result['error']
20
- when :not_valid
20
+ when :unprocessable_entity
21
21
  render_unprocessable_entity(result['contract'].errors)
22
22
  else
23
23
  render_unprocessable_entity
@@ -1,8 +1,7 @@
1
1
  module Morpho
2
2
  module Resources
3
3
  class Tokens < ::Grape::API
4
- helpers Morpho::Helpers::HTTPResponses,
5
- Morpho::Helpers::JWTUtils
4
+ helpers Morpho::Helpers::HTTPResponses
6
5
 
7
6
  namespace :tokens do
8
7
  desc 'Request user authentication token' do
@@ -25,16 +24,16 @@ module Morpho
25
24
  present result['token'], with: Morpho::Entities::AuthenticationToken
26
25
  else
27
26
  case result['error']
28
- when :not_valid
27
+ when :unprocessable_entity
29
28
  render_unprocessable_entity(result['contract'].errors)
30
29
  when :not_found
31
- render_not_found([I18n.t('morpho.api.messages.sign_in.unexistent')])
32
- when :not_active
33
- render_forbidden([I18n.t('morpho.api.messages.sign_in.unconfirmed')])
30
+ render_not_found({ base: I18n.t('morpho.api.messages.sign_in.not_found') })
31
+ when :forbidden
32
+ render_forbidden({ base: I18n.t('morpho.api.messages.sign_in.not_active') })
34
33
  when :locked
35
- render_locked([I18n.t('morpho.api.messages.sign_in.locked')])
36
- when :wrong_password
37
- render_unauthorized([I18n.t('morpho.api.messages.sign_in.bad_credentials')])
34
+ render_locked({ base: I18n.t('morpho.api.messages.sign_in.locked') })
35
+ when :unauthorized
36
+ render_unauthorized({ base: I18n.t('morpho.api.messages.sign_in.unauthorized') })
38
37
  else
39
38
  render_unprocessable_entity
40
39
  end
@@ -58,10 +57,10 @@ module Morpho
58
57
  present result['token'], with: Morpho::Entities::AuthenticationToken
59
58
  else
60
59
  case result['error']
61
- when :not_valid
60
+ when :unprocessable_entity
62
61
  render_unprocessable_entity(result['contract'].errors)
63
62
  when :not_found
64
- render_not_found([I18n.t('morpho.api.messages.refresh_token.invalid')])
63
+ render_not_found({ base: I18n.t('morpho.api.messages.refresh_token.not_found') })
65
64
  else
66
65
  render_unprocessable_entity
67
66
  end
@@ -22,14 +22,12 @@ module Morpho
22
22
  present result['model'], with: Morpho::Entities::User
23
23
  else
24
24
  case result['error']
25
- when :not_valid
25
+ when :unprocessable_entity
26
26
  render_unprocessable_entity(result['contract'].errors)
27
27
  when :not_found
28
- render_not_found
29
- when :not_allowed
30
- render_method_not_allowed
31
- when :not_delivered
32
- render_unprocessable_entity
28
+ render_not_found({ base: I18n.t('morpho.api.messages.unlock.not_found') })
29
+ when :method_not_allowed
30
+ render_method_not_allowed({ base: I18n.t('morpho.api.messages.unlock.method_not_allowed') })
33
31
  else
34
32
  render_unprocessable_entity
35
33
  end
@@ -1,5 +1,3 @@
1
- require 'reform/form/validation/unique_validator'
2
-
3
1
  module Morpho
4
2
  class User::Contract::ExternalSignIn < Reform::Form
5
3
  include Reform::Form::ActiveRecord
@@ -1,13 +1,12 @@
1
1
  module Morpho
2
2
  class User::Operation::Activate < Trailblazer::Operation
3
3
  step :validate
4
- fail :not_valid, fail_fast: true
4
+ fail :unprocessable_entity, fail_fast: true
5
5
  step :find
6
6
  fail :not_found, fail_fast: true
7
7
  step :check
8
- fail :not_allowed, fail_fast: true
9
- step :activation_email
10
- fail :not_delivered, fail_fast: true
8
+ fail :method_not_allowed, fail_fast: true
9
+ pass :activation_email
11
10
 
12
11
  def validate (options, **)
13
12
  options['contract'] = Morpho::User::Contract::Activate.new(OpenStruct.new)
@@ -26,20 +25,16 @@ module Morpho
26
25
  options['model'].resend_activation_needed_email!
27
26
  end
28
27
 
29
- def not_valid (options, **)
30
- options['error'] = :not_valid
28
+ def unprocessable_entity (options, **)
29
+ options['error'] = :unprocessable_entity
31
30
  end
32
31
 
33
32
  def not_found (options, **)
34
33
  options['error'] = :not_found
35
34
  end
36
35
 
37
- def not_allowed (options, **)
38
- options['error'] = :not_allowed
39
- end
40
-
41
- def not_delivered (options, **)
42
- options['error'] = :not_delivered
36
+ def method_not_allowed (options, **)
37
+ options['error'] = :method_not_allowed
43
38
  end
44
39
  end
45
40
  end
@@ -1,7 +1,7 @@
1
1
  module Morpho
2
2
  class User::Operation::ExternalSignIn < Trailblazer::Operation
3
3
  step :validate
4
- fail :not_valid, fail_fast: true
4
+ fail :unprocessable_entity, fail_fast: true
5
5
  pass :find_authentication
6
6
  pass :find_user
7
7
  pass :sign_in
@@ -59,20 +59,8 @@ module Morpho
59
59
  options['user.model'].register_last_login_activity!(options['ip'])
60
60
  end
61
61
 
62
- def not_valid (options, **)
63
- options['error'] = :not_valid
64
- end
65
-
66
- def not_signed_in (options, **)
67
- options['error'] = :not_signed_in
68
- end
69
-
70
- def not_registered (options, **)
71
- options['error'] = :not_registered
72
- end
73
-
74
- def not_signed_up (options, **)
75
- options['error'] = :not_signed_up
62
+ def unprocessable_entity (options, **)
63
+ options['error'] = :unprocessable_entity
76
64
  end
77
65
 
78
66
  def authentication_token (options, **)
@@ -1,7 +1,7 @@
1
1
  module Morpho
2
2
  class User::Operation::RefreshToken < Trailblazer::Operation
3
3
  step :validate
4
- fail :not_valid, fail_fast: true
4
+ fail :unprocessable_entity, fail_fast: true
5
5
  step :find
6
6
  fail :not_found, fail_fast: true
7
7
  step :generate_refresh_token
@@ -20,8 +20,8 @@ module Morpho
20
20
  options['model'].generate_refresh_token!
21
21
  end
22
22
 
23
- def not_valid (options, **)
24
- options['error'] = :not_valid
23
+ def unprocessable_entity (options, **)
24
+ options['error'] = :unprocessable_entity
25
25
  end
26
26
 
27
27
  def not_found (options, **)
@@ -1,15 +1,15 @@
1
1
  module Morpho
2
2
  class User::Operation::SignIn < Trailblazer::Operation
3
3
  step :validate
4
- fail :not_valid, fail_fast: true
4
+ fail :unprocessable_entity, fail_fast: true
5
5
  step :find
6
6
  fail :not_found, fail_fast: true
7
7
  step :check_active
8
- fail :not_active, fail_fast: true
8
+ fail :forbidden, fail_fast: true
9
9
  step :check_unlocked
10
10
  fail :locked, fail_fast: true
11
11
  step :check_password
12
- fail :wrong_password, fail_fast: true
12
+ fail :unauthorized, fail_fast: true
13
13
  step :generate_refresh_token
14
14
  step :register_last_login_activity
15
15
  step :authentication_token
@@ -43,25 +43,25 @@ module Morpho
43
43
  options['model'].register_last_login_activity!(options['ip'])
44
44
  end
45
45
 
46
- def not_valid (options, **)
47
- options['error'] = :not_valid
46
+ def unprocessable_entity (options, **)
47
+ options['error'] = :unprocessable_entity
48
48
  end
49
49
 
50
50
  def not_found (options, **)
51
51
  options['error'] = :not_found
52
52
  end
53
53
 
54
- def not_active (options, **)
55
- options['error'] = :not_active
54
+ def forbidden (options, **)
55
+ options['error'] = :forbidden
56
56
  end
57
57
 
58
58
  def locked (options, **)
59
59
  options['error'] = :locked
60
60
  end
61
61
 
62
- def wrong_password (options, **)
62
+ def unauthorized (options, **)
63
63
  options['model'].register_failed_login!
64
- options['error'] = :wrong_password
64
+ options['error'] = :unauthorized
65
65
  end
66
66
 
67
67
  def authentication_token (options, **)
@@ -1,13 +1,12 @@
1
1
  module Morpho
2
2
  class User::Operation::Unlock < Trailblazer::Operation
3
3
  step :validate
4
- fail :not_valid, fail_fast: true
4
+ fail :unprocessable_entity, fail_fast: true
5
5
  step :find
6
6
  fail :not_found, fail_fast: true
7
7
  step :check
8
- fail :not_allowed, fail_fast: true
9
- step :unlock_token_email
10
- fail :not_delivered, fail_fast: true
8
+ fail :method_not_allowed, fail_fast: true
9
+ pass :unlock_token_email
11
10
 
12
11
  def validate (options, **)
13
12
  options['contract'] = Morpho::User::Contract::Unlock.new(OpenStruct.new)
@@ -26,20 +25,16 @@ module Morpho
26
25
  options['model'].resend_unlock_token_email!
27
26
  end
28
27
 
29
- def not_valid (options, **)
30
- options['error'] = :not_valid
28
+ def unprocessable_entity (options, **)
29
+ options['error'] = :unprocessable_entity
31
30
  end
32
31
 
33
32
  def not_found (options, **)
34
33
  options['error'] = :not_found
35
34
  end
36
35
 
37
- def not_allowed (options, **)
38
- options['error'] = :not_allowed
39
- end
40
-
41
- def not_delivered (options, **)
42
- options['error'] = :not_delivered
36
+ def method_not_allowed (options, **)
37
+ options['error'] = :method_not_allowed
43
38
  end
44
39
  end
45
40
  end
@@ -138,15 +138,19 @@ en:
138
138
  method_not_allowed: 'Method not allowed'
139
139
  unprocessable_entity: 'Unprocessable entity'
140
140
  locked: 'Locked'
141
+ activate:
142
+ not_found: 'Email address does not belongs to a registered account'
143
+ method_not_allowed: 'User account has already been confirmed'
141
144
  sign_in:
142
- unexistent: 'Email address does not belongs to a registered account'
143
- bad_credentials: 'User email and/or password is incorrect'
144
- unconfirmed: 'User account has not been confirmed'
145
+ not_found: 'Email address does not belongs to a registered account'
146
+ forbidden: 'User account has not been confirmed'
147
+ unauthorized: 'User email and/or password is incorrect'
145
148
  locked: 'User account has been locked'
146
149
  refresh_token:
147
- invalid: 'Invalid token'
148
- provider:
149
- unregistered: 'Could not register user authentication provider'
150
+ not_found: 'Invalid token'
151
+ unlock:
152
+ not_found: 'Email address does not belongs to a registered account'
153
+ method_not_allowed: 'User account has not been locked'
150
154
  simple_form:
151
155
  'yes': 'Yes'
152
156
  'no': 'No'
@@ -161,3 +165,26 @@ en:
161
165
  password: 'Password'
162
166
  password_confirmation: 'Confirm your password'
163
167
  remember_me: 'Remember me'
168
+ activemodel:
169
+ errors:
170
+ models:
171
+ morpho/user/contract/activate:
172
+ attributes:
173
+ email:
174
+ invalid_email_address: 'invalid'
175
+ morpho/user/contract/external_sign_in:
176
+ attributes:
177
+ email:
178
+ invalid_email_address: 'invalid'
179
+ morpho/user/contract/sign_in:
180
+ attributes:
181
+ email:
182
+ invalid_email_address: 'invalid'
183
+ morpho/user/contract/sign_up:
184
+ attributes:
185
+ email:
186
+ invalid_email_address: 'invalid'
187
+ morpho/user/contract/unlock:
188
+ attributes:
189
+ email:
190
+ invalid_email_address: 'invalid'
@@ -138,15 +138,19 @@ es:
138
138
  method_not_allowed: 'Método no permitido'
139
139
  unprocessable_entity: 'Entidad no procesable'
140
140
  locked: 'Bloqueado'
141
+ activate:
142
+ not_found: 'Correo electrónico no pertenece a un usuario registrado'
143
+ method_not_allowed: 'Cuenta de usuario ya ha sido confirmada'
141
144
  sign_in:
142
- unexistent: 'Correo electrónico no pertenece a un usuario registrado'
143
- bad_credentials: 'Correo electrónico y/o contraseña es incorrecto(a)'
144
- unconfirmed: 'Cuenta de usuario no ha sido confirmada'
145
+ not_found: 'Correo electrónico no pertenece a un usuario registrado'
146
+ forbidden: 'Cuenta de usuario no ha sido confirmada'
147
+ unauthorized: 'Correo electrónico y/o contraseña es incorrecto(a)'
145
148
  locked: 'Cuenta de usuario ha sido bloqueada'
146
149
  refresh_token:
147
- invalid: 'El token es inválido'
148
- provider:
149
- unregistered: 'No se ha podido registrar a el proveedor'
150
+ not_found: 'El token es inválido'
151
+ unlock:
152
+ not_found: 'Correo electrónico no pertenece a un usuario registrado'
153
+ method_not_allowed: 'Cuenta de usuario no ha sido bloqueada'
150
154
  simple_form:
151
155
  'yes': 'Si'
152
156
  'no': 'No'
@@ -161,3 +165,26 @@ es:
161
165
  password: 'Contraseña'
162
166
  password_confirmation: 'Confirmar la contraseña'
163
167
  remember_me: 'Recuérdame'
168
+ activemodel:
169
+ errors:
170
+ models:
171
+ morpho/user/contract/activate:
172
+ attributes:
173
+ email:
174
+ invalid_email_address: 'no es válido'
175
+ morpho/user/contract/external_sign_in:
176
+ attributes:
177
+ email:
178
+ invalid_email_address: 'no es válido'
179
+ morpho/user/contract/sign_in:
180
+ attributes:
181
+ email:
182
+ invalid_email_address: 'no es válido'
183
+ morpho/user/contract/sign_up:
184
+ attributes:
185
+ email:
186
+ invalid_email_address: 'no es válido'
187
+ morpho/user/contract/unlock:
188
+ attributes:
189
+ email:
190
+ invalid_email_address: 'no es válido'
data/lib/morpho/engine.rb CHANGED
@@ -16,9 +16,7 @@ module Morpho
16
16
  initializer 'morpho.configurations', after: :load_config_initializers do |app|
17
17
  mailer = ActionMailer::Base
18
18
  mailer.delivery_method = Morpho.config.mailer.delivery_method
19
- .to_s.to_sym
20
- mailer.perform_deliveries = Morpho.config.mailer
21
- .perform_deliveries
19
+ mailer.perform_deliveries = Morpho.config.mailer.perform_deliveries
22
20
 
23
21
  mailer.default_options = {
24
22
  from: Morpho.config.mailer.from
@@ -1,3 +1,3 @@
1
1
  module Morpho
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpho
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Gilmar Erazo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -238,42 +238,42 @@ dependencies:
238
238
  name: sqlite3
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
- - - ">="
241
+ - - ">"
242
242
  - !ruby/object:Gem::Version
243
243
  version: '0'
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - ">="
248
+ - - ">"
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  - !ruby/object:Gem::Dependency
252
252
  name: rubocop
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - ">="
255
+ - - ">"
256
256
  - !ruby/object:Gem::Version
257
257
  version: '0'
258
258
  type: :development
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: '0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: simplecov
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
- - - ">="
269
+ - - ">"
270
270
  - !ruby/object:Gem::Version
271
271
  version: '0'
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - ">="
276
+ - - ">"
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  description: Skeleton rails engine for modular development.