aven 0.0.1 → 0.0.2
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/Rakefile +1 -1
- data/app/components/aven/views/oauth/error/component.html.erb +44 -0
- data/app/components/aven/views/oauth/error/component.rb +30 -0
- data/app/components/aven/views/static/index/component.html.erb +4 -4
- data/app/components/aven/views/static/index/component.rb +11 -0
- data/app/controllers/aven/admin/base.rb +4 -4
- data/app/controllers/aven/application_controller.rb +22 -0
- data/app/controllers/aven/auth_controller.rb +6 -58
- data/app/controllers/aven/oauth/auth0_controller.rb +84 -0
- data/app/controllers/aven/oauth/base_controller.rb +183 -0
- data/app/controllers/aven/oauth/documentation/auth0.md +387 -0
- data/app/controllers/aven/oauth/documentation/entra_id.md +608 -0
- data/app/controllers/aven/oauth/documentation/github.md +329 -0
- data/app/controllers/aven/oauth/documentation/google.md +253 -0
- data/app/controllers/aven/oauth/entra_id_controller.rb +92 -0
- data/app/controllers/aven/oauth/github_controller.rb +91 -0
- data/app/controllers/aven/oauth/google_controller.rb +64 -0
- data/app/controllers/aven/workspaces_controller.rb +20 -0
- data/app/controllers/concerns/aven/authentication.rb +49 -0
- data/app/controllers/concerns/aven/controller_helpers.rb +38 -0
- data/app/helpers/aven/application_helper.rb +2 -6
- data/app/models/aven/app_record.rb +1 -1
- data/app/models/aven/app_record_schema.rb +0 -1
- data/app/models/aven/log.rb +0 -1
- data/app/models/aven/loggable.rb +2 -3
- data/app/models/aven/user.rb +0 -23
- data/app/models/aven/workspace.rb +49 -5
- data/app/models/aven/workspace_role.rb +0 -1
- data/app/models/aven/workspace_user.rb +0 -1
- data/app/models/aven/workspace_user_role.rb +0 -1
- data/config/routes.rb +22 -7
- data/db/migrate/{20251003090752_create_aven_users.rb → 20200101000001_create_aven_users.rb} +1 -1
- data/db/migrate/{20251004182010_create_aven_workspace_users.rb → 20200101000003_create_aven_workspace_users.rb} +1 -1
- data/db/migrate/{20251004182020_create_aven_workspace_roles.rb → 20200101000004_create_aven_workspace_roles.rb} +1 -1
- data/db/migrate/{20251004182030_create_aven_workspace_user_roles.rb → 20200101000005_create_aven_workspace_user_roles.rb} +1 -1
- data/db/migrate/{20251004190000_create_aven_logs.rb → 20200101000006_create_aven_logs.rb} +2 -3
- data/db/migrate/{20251004190100_create_aven_app_record_schemas.rb → 20200101000007_create_aven_app_record_schemas.rb} +0 -1
- data/db/migrate/{20251004190110_create_aven_app_records.rb → 20200101000008_create_aven_app_records.rb} +0 -1
- data/lib/aven/configuration.rb +26 -10
- data/lib/aven/engine.rb +15 -16
- data/lib/aven/model/tenant_model.rb +91 -0
- data/lib/aven/model.rb +6 -0
- data/lib/aven/version.rb +1 -1
- metadata +42 -69
- data/config/initializers/devise.rb +0 -43
- /data/db/migrate/{20251004182000_create_aven_workspaces.rb → 20200101000002_create_aven_workspaces.rb} +0 -0
- /data/lib/tasks/{sqema_tasks.rake → aven_tasks.rake} +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module Aven
|
|
2
|
+
module Model
|
|
3
|
+
# TenantModel provides workspace multi-tenancy support for ActiveRecord models.
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# class Server < ApplicationRecord
|
|
7
|
+
# include Aven::TenantModel
|
|
8
|
+
# end
|
|
9
|
+
#
|
|
10
|
+
# This will:
|
|
11
|
+
# - Add belongs_to :workspace association
|
|
12
|
+
# - Validate workspace_id column exists
|
|
13
|
+
# - Register model with Aven::Workspace
|
|
14
|
+
# - Add workspace scoping helpers
|
|
15
|
+
#
|
|
16
|
+
# Inspired by Flipper's Model::ActiveRecord pattern.
|
|
17
|
+
module TenantModel
|
|
18
|
+
extend ActiveSupport::Concern
|
|
19
|
+
|
|
20
|
+
included do
|
|
21
|
+
# Validate workspace_id column exists at include time
|
|
22
|
+
unless column_names.include?("workspace_id")
|
|
23
|
+
raise ArgumentError,
|
|
24
|
+
"#{name} includes Aven::TenantModel but does not have a workspace_id column. " \
|
|
25
|
+
"Add a workspace_id column to #{table_name} first."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Add belongs_to association if not already defined
|
|
29
|
+
unless reflect_on_association(:workspace)
|
|
30
|
+
belongs_to :workspace, class_name: "Aven::Workspace"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Register this model as a tenant model
|
|
34
|
+
Aven::Workspace.register_tenant_model(self)
|
|
35
|
+
|
|
36
|
+
# Add scopes for workspace querying
|
|
37
|
+
scope :in_workspace, ->(workspace) { where(workspace_id: workspace.id) }
|
|
38
|
+
scope :for_workspace, ->(workspace) { where(workspace_id: workspace.id) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns a unique identifier combining class name and workspace_id
|
|
42
|
+
# Useful for caching keys, logging, permissions, etc.
|
|
43
|
+
#
|
|
44
|
+
# Example:
|
|
45
|
+
# server.workspace_tenant_id #=> "Server;123"
|
|
46
|
+
def workspace_tenant_id
|
|
47
|
+
"#{self.class.base_class.name};#{workspace_id}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Check if this model is workspace-scoped
|
|
51
|
+
def workspace_scoped?
|
|
52
|
+
true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns workspace association name for this model type
|
|
56
|
+
def workspace_association_name
|
|
57
|
+
self.class.workspace_association_name
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
module ClassMethods
|
|
61
|
+
# Make workspace association optional
|
|
62
|
+
# Call this in your model if workspace can be nil
|
|
63
|
+
#
|
|
64
|
+
# Example:
|
|
65
|
+
# class DnsCredential < ApplicationRecord
|
|
66
|
+
# include Aven::TenantModel
|
|
67
|
+
# workspace_optional!
|
|
68
|
+
# end
|
|
69
|
+
def workspace_optional!
|
|
70
|
+
_reflect_on_association(:workspace).options[:optional] = true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Returns the association name that Workspace will use for this model
|
|
74
|
+
# Example: Server => :servers, DnsCredential => :dns_credentials
|
|
75
|
+
def workspace_association_name
|
|
76
|
+
name.underscore.pluralize.to_sym
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Check if this model has a unique workspace constraint
|
|
80
|
+
# Used to determine if Workspace should use has_one vs has_many
|
|
81
|
+
def unique_per_workspace?
|
|
82
|
+
return false unless table_exists?
|
|
83
|
+
|
|
84
|
+
connection.indexes(table_name).any? { |idx|
|
|
85
|
+
idx.unique && idx.columns == [ "workspace_id" ]
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/aven/model.rb
ADDED
data/lib/aven/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aven
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben
|
|
@@ -23,62 +23,6 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: 8.0.3
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: devise
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - "~>"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '4.9'
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - "~>"
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '4.9'
|
|
40
|
-
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: omniauth
|
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
|
43
|
-
requirements:
|
|
44
|
-
- - "~>"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '2.1'
|
|
47
|
-
type: :runtime
|
|
48
|
-
prerelease: false
|
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
-
requirements:
|
|
51
|
-
- - "~>"
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: '2.1'
|
|
54
|
-
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: omniauth-rails_csrf_protection
|
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
|
57
|
-
requirements:
|
|
58
|
-
- - "~>"
|
|
59
|
-
- !ruby/object:Gem::Version
|
|
60
|
-
version: 1.0.0
|
|
61
|
-
type: :runtime
|
|
62
|
-
prerelease: false
|
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
-
requirements:
|
|
65
|
-
- - "~>"
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: 1.0.0
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: repost
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - "~>"
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: 0.4.2
|
|
75
|
-
type: :runtime
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - "~>"
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: 0.4.2
|
|
82
26
|
- !ruby/object:Gem::Dependency
|
|
83
27
|
name: importmap-rails
|
|
84
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -233,8 +177,22 @@ dependencies:
|
|
|
233
177
|
- - ">="
|
|
234
178
|
- !ruby/object:Gem::Version
|
|
235
179
|
version: '0'
|
|
236
|
-
|
|
237
|
-
|
|
180
|
+
- !ruby/object:Gem::Dependency
|
|
181
|
+
name: friendly_id
|
|
182
|
+
requirement: !ruby/object:Gem::Requirement
|
|
183
|
+
requirements:
|
|
184
|
+
- - "~>"
|
|
185
|
+
- !ruby/object:Gem::Version
|
|
186
|
+
version: '5.5'
|
|
187
|
+
type: :runtime
|
|
188
|
+
prerelease: false
|
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - "~>"
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: '5.5'
|
|
194
|
+
description: A Rails engine providing authentication with OAuth support (GitHub, Google,
|
|
195
|
+
Auth0).
|
|
238
196
|
email:
|
|
239
197
|
- ben@dee.mx
|
|
240
198
|
executables: []
|
|
@@ -250,6 +208,8 @@ files:
|
|
|
250
208
|
- app/components/aven/application_view_component.rb
|
|
251
209
|
- app/components/aven/views/admin/dashboard/index/component.html.erb
|
|
252
210
|
- app/components/aven/views/admin/dashboard/index/component.rb
|
|
211
|
+
- app/components/aven/views/oauth/error/component.html.erb
|
|
212
|
+
- app/components/aven/views/oauth/error/component.rb
|
|
253
213
|
- app/components/aven/views/static/index/component.html.erb
|
|
254
214
|
- app/components/aven/views/static/index/component.rb
|
|
255
215
|
- app/components/aven/views/static/index/controller.js
|
|
@@ -257,7 +217,19 @@ files:
|
|
|
257
217
|
- app/controllers/aven/admin/dashboard_controller.rb
|
|
258
218
|
- app/controllers/aven/application_controller.rb
|
|
259
219
|
- app/controllers/aven/auth_controller.rb
|
|
220
|
+
- app/controllers/aven/oauth/auth0_controller.rb
|
|
221
|
+
- app/controllers/aven/oauth/base_controller.rb
|
|
222
|
+
- app/controllers/aven/oauth/documentation/auth0.md
|
|
223
|
+
- app/controllers/aven/oauth/documentation/entra_id.md
|
|
224
|
+
- app/controllers/aven/oauth/documentation/github.md
|
|
225
|
+
- app/controllers/aven/oauth/documentation/google.md
|
|
226
|
+
- app/controllers/aven/oauth/entra_id_controller.rb
|
|
227
|
+
- app/controllers/aven/oauth/github_controller.rb
|
|
228
|
+
- app/controllers/aven/oauth/google_controller.rb
|
|
260
229
|
- app/controllers/aven/static_controller.rb
|
|
230
|
+
- app/controllers/aven/workspaces_controller.rb
|
|
231
|
+
- app/controllers/concerns/aven/authentication.rb
|
|
232
|
+
- app/controllers/concerns/aven/controller_helpers.rb
|
|
261
233
|
- app/helpers/aven/application_helper.rb
|
|
262
234
|
- app/javascript/sqema/application.js
|
|
263
235
|
- app/javascript/sqema/controllers/application.js
|
|
@@ -277,22 +249,23 @@ files:
|
|
|
277
249
|
- app/views/layouts/aven/admin.html.erb
|
|
278
250
|
- app/views/layouts/aven/application.html.erb
|
|
279
251
|
- config/importmap.rb
|
|
280
|
-
- config/initializers/devise.rb
|
|
281
252
|
- config/routes.rb
|
|
282
|
-
- db/migrate/
|
|
283
|
-
- db/migrate/
|
|
284
|
-
- db/migrate/
|
|
285
|
-
- db/migrate/
|
|
286
|
-
- db/migrate/
|
|
287
|
-
- db/migrate/
|
|
288
|
-
- db/migrate/
|
|
289
|
-
- db/migrate/
|
|
253
|
+
- db/migrate/20200101000001_create_aven_users.rb
|
|
254
|
+
- db/migrate/20200101000002_create_aven_workspaces.rb
|
|
255
|
+
- db/migrate/20200101000003_create_aven_workspace_users.rb
|
|
256
|
+
- db/migrate/20200101000004_create_aven_workspace_roles.rb
|
|
257
|
+
- db/migrate/20200101000005_create_aven_workspace_user_roles.rb
|
|
258
|
+
- db/migrate/20200101000006_create_aven_logs.rb
|
|
259
|
+
- db/migrate/20200101000007_create_aven_app_record_schemas.rb
|
|
260
|
+
- db/migrate/20200101000008_create_aven_app_records.rb
|
|
290
261
|
- lib/aven.rb
|
|
291
262
|
- lib/aven/configuration.rb
|
|
292
263
|
- lib/aven/engine.rb
|
|
264
|
+
- lib/aven/model.rb
|
|
265
|
+
- lib/aven/model/tenant_model.rb
|
|
293
266
|
- lib/aven/version.rb
|
|
294
267
|
- lib/tasks/annotate_rb.rake
|
|
295
|
-
- lib/tasks/
|
|
268
|
+
- lib/tasks/aven_tasks.rake
|
|
296
269
|
homepage: https://github.com/getnvoi/aven
|
|
297
270
|
licenses:
|
|
298
271
|
- MIT
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
Devise.setup do |config|
|
|
4
|
-
# The secret key used by Devise will be taken from Rails credentials
|
|
5
|
-
# config.secret_key = Rails.application.credentials.secret_key_base
|
|
6
|
-
|
|
7
|
-
# ==> Mailer Configuration
|
|
8
|
-
config.mailer_sender = "noreply@nvoi.io"
|
|
9
|
-
|
|
10
|
-
# ==> ORM configuration
|
|
11
|
-
require "devise/orm/active_record"
|
|
12
|
-
|
|
13
|
-
# ==> Configuration for any authentication mechanism
|
|
14
|
-
# Configure which keys are used when authenticating a user
|
|
15
|
-
config.authentication_keys = [:email]
|
|
16
|
-
|
|
17
|
-
# ==> OAuth configuration
|
|
18
|
-
# GitHub OAuth will be configured with credentials from the host app
|
|
19
|
-
# The engine will receive credentials via configuration
|
|
20
|
-
|
|
21
|
-
# Configure sign out to use GET request (required for some OAuth providers)
|
|
22
|
-
config.sign_out_via = :get
|
|
23
|
-
|
|
24
|
-
# ==> Scopes configuration
|
|
25
|
-
config.scoped_views = true
|
|
26
|
-
|
|
27
|
-
# ==> Navigation configuration
|
|
28
|
-
config.navigational_formats = ['*/*', :html, :turbo_stream]
|
|
29
|
-
|
|
30
|
-
# The default HTTP method used to sign out a resource. Default is :delete.
|
|
31
|
-
config.sign_out_via = %i[delete get]
|
|
32
|
-
|
|
33
|
-
# ==> Mountable engine configuration
|
|
34
|
-
# Set parent controller for the engine
|
|
35
|
-
config.parent_controller = 'Aven::ApplicationController'
|
|
36
|
-
|
|
37
|
-
# ==> OmniAuth
|
|
38
|
-
# OmniAuth providers are configured dynamically via Aven.configuration
|
|
39
|
-
# in the engine initializer (lib/aven/engine.rb)
|
|
40
|
-
|
|
41
|
-
# Configure OmniAuth to work with the engine's mounted path
|
|
42
|
-
# config.omniauth_path_prefix = '/aven/users/auth'
|
|
43
|
-
end
|
|
File without changes
|
|
File without changes
|