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 +4 -4
- data/app/lib/nexo/active_record_google_token_store.rb +3 -3
- data/app/lib/nexo/api_client/google_auth_service.rb +9 -5
- data/app/lib/nexo/api_client/google_calendar_service.rb +13 -1
- data/app/models/nexo/client.rb +9 -10
- data/app/models/nexo/element.rb +7 -7
- data/app/models/nexo/folder.rb +1 -1
- data/app/models/nexo/integration.rb +4 -0
- data/app/models/nexo/token.rb +4 -4
- data/db/migrate/20250505192315_create_nexo_clients.rb +1 -1
- data/db/migrate/20250506125057_create_nexo_tokens.rb +1 -1
- data/db/migrate/20250512025950_create_nexo_elements.rb +2 -2
- data/db/seeds.rb +2 -2
- data/lib/nexo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba5c579264ba2dddff0d51feddf0f28a92947c507852131030f958bc3b4911a5
|
4
|
+
data.tar.gz: 2f1e9ef346625a560dbc98ee357684422b5d9170ae123f82130d2e5ced7e01bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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!(
|
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,
|
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?
|
56
|
+
if request.present?
|
57
57
|
# :nocov: tricky
|
58
|
-
|
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
|
-
|
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
|
data/app/models/nexo/client.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
#
|
3
3
|
# Table name: nexo_clients
|
4
4
|
#
|
5
|
-
# id
|
6
|
-
# service
|
7
|
-
# secret
|
8
|
-
#
|
9
|
-
# brand_name
|
10
|
-
#
|
11
|
-
#
|
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 :
|
29
|
+
enum :nc_status, authorized: 0, disabled: 1, expired: 2
|
31
30
|
|
32
|
-
validates :service, :
|
31
|
+
validates :service, :nc_status, :secret, presence: true
|
33
32
|
|
34
33
|
serialize :secret, coder: JSON
|
35
34
|
|
data/app/models/nexo/element.rb
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
# synchronizable_id :integer not null
|
8
8
|
# synchronizable_type :string not null
|
9
9
|
# uuid :string
|
10
|
-
#
|
11
|
-
#
|
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.
|
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 :
|
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!(
|
51
|
-
update!(
|
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
|
-
|
55
|
+
flagged_for_removal?
|
56
56
|
end
|
57
57
|
|
58
58
|
# :nocov: TODO, not yet being called
|
data/app/models/nexo/folder.rb
CHANGED
data/app/models/nexo/token.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# id :bigint not null, primary key
|
6
6
|
# integration_id :bigint not null
|
7
7
|
# secret :string
|
8
|
-
#
|
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.
|
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 :
|
25
|
+
enum :nt_status, active: 0, revoked: 1, expired: 2
|
26
26
|
|
27
|
-
validates :secret, :
|
27
|
+
validates :secret, :nt_status, :environment, presence: true
|
28
28
|
end
|
29
29
|
end
|
@@ -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 :
|
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 :
|
9
|
-
t.integer :
|
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
|
-
|
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
|
-
|
23
|
+
nt_status: :active,
|
24
24
|
environment: "development"
|
25
25
|
)
|
26
26
|
end
|
data/lib/nexo/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2025-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|