nexo 0.1.4 → 0.1.5

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: 8e9cc07511456093aa96d53df983acf4bfc770ba3de05df5bacfb683f80840ca
4
- data.tar.gz: 5b1918e753e917ac5e0331aa5d49fe03a5d0fcb87d64fc36bab85af638b79246
3
+ metadata.gz: ba5c579264ba2dddff0d51feddf0f28a92947c507852131030f958bc3b4911a5
4
+ data.tar.gz: 2f1e9ef346625a560dbc98ee357684422b5d9170ae123f82130d2e5ced7e01bb
5
5
  SHA512:
6
- metadata.gz: 973db6311a60eb0534b3ca072976190bb3b5be953bc3b8f6cbb6e39207ba127b54711dd5ec0adbcc3f2c5cc4c4272302ca558ad0572c687f6864402e7bec4bde
7
- data.tar.gz: 79ba89ed8a6dbbd17bdf8c6c055df802fb9ec4cca686075d2f5e2653c776d1b38599371158bd58fb3779aef6dffd8718bd9ea8b5c42e2403a30d917a5aa72505
6
+ metadata.gz: abdd4355a1dab11e798acca2c37bda4c4b0c133fd8e6a36e6ae8eadbb79ea1c6522d325333ba2f54461e37383a042632fb3599bfb5fcfc0526c46b661b2d1ffc
7
+ data.tar.gz: 073eed8eac35693101915193ee7493581ca483c37cf297a6d7adbb9313bc13005184a697002d6a4fede2876d8e487b6b50fa6e971d386571f7ae338fe3077307
@@ -17,7 +17,7 @@ module Nexo
17
17
  def store(integration, token)
18
18
  ActiveRecord::Base.transaction do
19
19
  # Maybe these should be destroyed
20
- integration.tokens.active.update_all(tpt_status: :expired)
20
+ integration.tokens.active.update_all(nt_status: :expired)
21
21
 
22
22
  Token.create!(integration:, secret: token)
23
23
  end
@@ -28,7 +28,7 @@ module Nexo
28
28
  token = find_by_id(id)
29
29
 
30
30
  if token.present?
31
- token.update!(tpt_status: :revoked)
31
+ token.update!(nt_status: :revoked)
32
32
  else
33
33
  # TODO: pg_warn("Couldn't find token for revocation: #{id}")
34
34
  end
@@ -37,7 +37,7 @@ module Nexo
37
37
  private
38
38
 
39
39
  def find_by_id(id)
40
- Token.where(environment: Rails.env, integration: id, tpt_status: :active).last
40
+ Token.where(environment: Rails.env, integration: id, nt_status: :active).last
41
41
  end
42
42
  end
43
43
  end
@@ -53,9 +53,13 @@ module Nexo
53
53
  # Guarda el Token
54
54
  # Si el client tiene más permisos que los que el user solicitó
55
55
  def get_credentials(request = nil)
56
- if request.present? && request.session["code_verifier"].present?
56
+ if request.present?
57
57
  # :nocov: tricky
58
- authorizer.code_verifier = request.session["code_verifier"]
58
+ if request.session["code_verifier"].present?
59
+ authorizer.code_verifier = request.session["code_verifier"]
60
+ else
61
+ Rails.logger.warn("Request has no code_verifier")
62
+ end
59
63
  # :nocov:
60
64
  end
61
65
  authorizer.get_credentials @integration, request
@@ -63,11 +67,11 @@ module Nexo
63
67
  # TODO: log
64
68
  end
65
69
 
66
- def get_authorization_url(request)
70
+ def get_authorization_url(request, login_hint: nil)
67
71
  request.session["code_verifier"] ||= Google::Auth::WebUserAuthorizer.generate_code_verifier
68
72
  authorizer.code_verifier = request.session["code_verifier"]
69
- authorizer.get_authorization_url(request:)
70
- # authorizer.get_authorization_url(request:, login_hint: "bla@gmail.com")
73
+ # authorizer.get_authorization_url(request:)
74
+ authorizer.get_authorization_url(request:, login_hint:)
71
75
  end
72
76
 
73
77
  private
@@ -41,6 +41,10 @@ module Nexo
41
41
 
42
42
  # Create a Google calendar
43
43
  def insert_calendar(folder)
44
+ unless folder.integration.token?
45
+ raise Errors::Error, "folder has no token"
46
+ end
47
+
44
48
  cal = build_calendar(folder)
45
49
  response = client.insert_calendar(cal)
46
50
  ApiResponse.new(payload: response.to_json, status: :ok, etag: response.etag, id: response.id)
@@ -48,8 +52,12 @@ module Nexo
48
52
 
49
53
  # Create a Google calendar
50
54
  def update_calendar(folder)
55
+ unless folder.integration.token?
56
+ raise Errors::Error, "folder has no token"
57
+ end
58
+
51
59
  cal = build_calendar(folder)
52
- response = client.update_calendar(cal)
60
+ response = client.update_calendar(folder.external_identifier, cal)
53
61
  ApiResponse.new(payload: response.to_json, status: :ok, etag: response.etag, id: response.id)
54
62
  end
55
63
 
@@ -74,6 +82,10 @@ module Nexo
74
82
  private
75
83
 
76
84
  def validate_folder_state!(folder)
85
+ unless folder.integration.token?
86
+ raise Errors::Error, "folder has no token"
87
+ end
88
+
77
89
  if folder.external_identifier.blank?
78
90
  raise Errors::InvalidFolderState, folder
79
91
  end
@@ -2,14 +2,13 @@
2
2
  #
3
3
  # Table name: nexo_clients
4
4
  #
5
- # id :bigint not null, primary key
6
- # service :integer
7
- # secret :string
8
- # tcp_status :integer
9
- # brand_name :integer
10
- # user_integrations_allowed :boolean
11
- # created_at :datetime not null
12
- # updated_at :datetime not null
5
+ # id :bigint not null, primary key
6
+ # service :integer
7
+ # secret :string
8
+ # nc_status :integer
9
+ # brand_name :integer
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
13
12
  #
14
13
  require "google-apis-calendar_v3"
15
14
  require "google-apis-oauth2_v2"
@@ -27,9 +26,9 @@ module Nexo
27
26
  encrypts :secret
28
27
 
29
28
  enum :service, google: 0
30
- enum :tcp_status, authorized: 0, disabled: 1, expired: 2
29
+ enum :nc_status, authorized: 0, disabled: 1, expired: 2
31
30
 
32
- validates :service, :tcp_status, :secret, presence: true
31
+ validates :service, :nc_status, :secret, presence: true
33
32
 
34
33
  serialize :secret, coder: JSON
35
34
 
@@ -7,8 +7,8 @@
7
7
  # synchronizable_id :integer not null
8
8
  # synchronizable_type :string not null
9
9
  # uuid :string
10
- # flag_deletion :boolean not null
11
- # deletion_reason :integer
10
+ # flagged_for_removal :boolean not null
11
+ # removal_reason :integer
12
12
  # conflicted :boolean default(FALSE), not null
13
13
  # discarded_at :datetime
14
14
  # created_at :datetime not null
@@ -22,12 +22,12 @@ module Nexo
22
22
 
23
23
  after_initialize do
24
24
  # TODO: https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
25
- self.flag_deletion = false if flag_deletion.nil?
25
+ self.flagged_for_removal = false if flagged_for_removal.nil?
26
26
  end
27
27
 
28
28
  scope :kept, -> { where(discarded_at: nil) }
29
29
 
30
- enum :deletion_reason, no_longer_included_in_folder: 0, synchronizable_destroyed: 1
30
+ enum :removal_reason, no_longer_included_in_folder: 0, synchronizable_destroyed: 1
31
31
 
32
32
  scope :conflicted, -> { where(conflicted: true) }
33
33
 
@@ -47,12 +47,12 @@ module Nexo
47
47
  element_versions.where(sequence: nil).order(created_at: :desc).first
48
48
  end
49
49
 
50
- def flag_for_deletion!(deletion_reason)
51
- update!(flag_deletion: true, deletion_reason:)
50
+ def flag_for_deletion!(removal_reason)
51
+ update!(flagged_for_removal: true, removal_reason:)
52
52
  end
53
53
 
54
54
  def flagged_for_deletion?
55
- flag_deletion?
55
+ flagged_for_removal?
56
56
  end
57
57
 
58
58
  # :nocov: TODO, not yet being called
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # id :bigint not null, primary key
6
6
  # integration_id :bigint not null
7
- # protocol :integer not null
7
+ # nexo_protocol :integer not null
8
8
  # external_identifier :string
9
9
  # name :string
10
10
  # description :string
@@ -57,6 +57,10 @@ module Nexo
57
57
  end
58
58
  end
59
59
 
60
+ def token?
61
+ token_status.in? [ :active_token, :expired_token ]
62
+ end
63
+
60
64
  def credentials
61
65
  service = ServiceBuilder.instance.build_auth_service(self)
62
66
  @credentials ||= service.get_credentials
@@ -5,7 +5,7 @@
5
5
  # id :bigint not null, primary key
6
6
  # integration_id :bigint not null
7
7
  # secret :string
8
- # tpt_status :integer not null
8
+ # nt_status :integer not null
9
9
  # environment :string not null
10
10
  # created_at :datetime not null
11
11
  # updated_at :datetime not null
@@ -16,14 +16,14 @@ module Nexo
16
16
 
17
17
  after_initialize do
18
18
  # TODO: https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
19
- self.tpt_status = :active if tpt_status.nil?
19
+ self.nt_status = :active if nt_status.nil?
20
20
  self.environment = Rails.env if environment.nil?
21
21
  end
22
22
 
23
23
  encrypts :secret
24
24
 
25
- enum :tpt_status, active: 0, revoked: 1, expired: 2
25
+ enum :nt_status, active: 0, revoked: 1, expired: 2
26
26
 
27
- validates :secret, :tpt_status, :environment, presence: true
27
+ validates :secret, :nt_status, :environment, presence: true
28
28
  end
29
29
  end
@@ -3,7 +3,7 @@ class CreateNexoClients < ActiveRecord::Migration[7.2]
3
3
  create_table :nexo_clients do |t|
4
4
  t.integer :service
5
5
  t.string :secret
6
- t.integer :tcp_status
6
+ t.integer :nc_status
7
7
  t.integer :brand_name
8
8
 
9
9
  t.timestamps
@@ -3,7 +3,7 @@ class CreateNexoTokens < ActiveRecord::Migration[7.2]
3
3
  create_table :nexo_tokens do |t|
4
4
  t.references :integration, null: false, foreign_key: { to_table: :nexo_integrations }
5
5
  t.string :secret
6
- t.integer :tpt_status, null: false
6
+ t.integer :nt_status, null: false
7
7
  t.string :environment, null: false
8
8
 
9
9
  t.timestamps
@@ -5,8 +5,8 @@ class CreateNexoElements < ActiveRecord::Migration[7.2]
5
5
  t.integer :synchronizable_id, null: false, index: true
6
6
  t.string :synchronizable_type, null: false, index: true
7
7
  t.string :uuid
8
- t.boolean :flag_deletion, null: false
9
- t.integer :deletion_reason
8
+ t.boolean :flagged_for_removal, null: false
9
+ t.integer :removal_reason
10
10
  t.boolean :conflicted, null: false, default: false
11
11
  t.datetime :discarded_at, index: true
12
12
 
data/db/seeds.rb CHANGED
@@ -4,7 +4,7 @@ module Nexo
4
4
 
5
5
  if ENV.fetch('SEED_GOOGLE_APIS_CLIENT_SECRET', nil)
6
6
  client = Client.create!(
7
- tcp_status: 0,
7
+ nc_status: 0,
8
8
  service: "google",
9
9
  secret: JSON.parse(ENV.fetch('SEED_GOOGLE_APIS_CLIENT_SECRET'))
10
10
  )
@@ -20,7 +20,7 @@ module Nexo
20
20
  Nexo::Token.create!(
21
21
  integration:,
22
22
  secret: ENV.fetch('SEED_GOOGLE_APIS_TOKEN'),
23
- tpt_status: :active,
23
+ nt_status: :active,
24
24
  environment: "development"
25
25
  )
26
26
  end
data/lib/nexo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # :nocov: non-viable
2
2
  module Nexo
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  # :nocov:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-23 00:00:00.000000000 Z
11
+ date: 2025-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails