forest_admin_rails 1.0.0.pre.beta.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +5 -0
- data/app/controllers/forest_admin_rails/forest_controller.rb +51 -0
- data/app/helpers/forest_admin_rails/application_helper.rb +4 -0
- data/config/routes.rb +5 -0
- data/lib/forest_admin_rails/engine.rb +55 -0
- data/lib/forest_admin_rails/version.rb +3 -0
- data/lib/forest_admin_rails.rb +32 -0
- data/lib/generators/forest_admin_rails/install_generator.rb +16 -0
- data/lib/generators/forest_admin_rails/templates/create_agent.rb +16 -0
- data/lib/generators/forest_admin_rails/templates/initializers/config.rb +4 -0
- data/lib/tasks/forest_admin_rails_tasks.rake +4 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1299315823fb267116811e6ae29fb9985a66b9d1cd1711cb1cce87c5066f4ad1
|
4
|
+
data.tar.gz: 93b595e413b2da5cd6eaf5ab0ffa14255af02698964db6d9eeda40e916056933
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c92087cb113959bac21c93d319419a0b991499b9b08ca77adda74b7ec9deb9c573d4bc79bdcba067c2201f4a652b6b72a0a26500b743f4c4c56801af6badc820
|
7
|
+
data.tar.gz: db33af05dbf38c3987dc2ab42c4a04abe5c2b9675c8ccee4694484529253bed68eae2865afc741bfc43ef0885ac9c5de9cb545875e9366b8778c00a621003164
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2023 FORESTADMIN
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# ForestAdmin
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "forest_admin"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install forest_admin
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module ForestAdminRails
|
2
|
+
class ForestController < ActionController::Base
|
3
|
+
skip_forgery_protection
|
4
|
+
|
5
|
+
def index
|
6
|
+
if ForestAdminAgent::Http::Router.routes.key? params['route_alias']
|
7
|
+
route = ForestAdminAgent::Http::Router.routes[params['route_alias']]
|
8
|
+
|
9
|
+
begin
|
10
|
+
forest_response route[:closure].call({ params: params.to_unsafe_h, headers: request.headers.to_h })
|
11
|
+
rescue StandardError => e
|
12
|
+
exception_handler e
|
13
|
+
end
|
14
|
+
else
|
15
|
+
render json: { error: 'Route not found' }, status: 404
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def forest_response(data = {})
|
20
|
+
render json: data[:content], status: data[:status] || 200
|
21
|
+
end
|
22
|
+
|
23
|
+
def exception_handler(exception)
|
24
|
+
if exception.is_a? ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient
|
25
|
+
data = {
|
26
|
+
error: exception.error,
|
27
|
+
error_description: exception.error_description,
|
28
|
+
state: exception.state
|
29
|
+
}
|
30
|
+
else
|
31
|
+
data = {
|
32
|
+
errors: [
|
33
|
+
{
|
34
|
+
name: exception.name,
|
35
|
+
detail: exception.message,
|
36
|
+
status: exception.status
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
|
41
|
+
data[:errors][0][:data] = exception.data if exception.defined? :data
|
42
|
+
|
43
|
+
# TODO: IMPLEMENT LOGGING
|
44
|
+
# if Facades::Container.cache(:is_production)
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
|
48
|
+
render json: data, status: exception.status
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'forest_admin_agent'
|
2
|
+
require 'rack/cors'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class Cors
|
6
|
+
class Resource
|
7
|
+
def to_preflight_headers(env)
|
8
|
+
h = to_headers(env)
|
9
|
+
if env['HTTP_ACCESS_CONTROL_REQUEST_PRIVATE_NETWORK'] == 'true'
|
10
|
+
h['Access-Control-Allow-Private-Network'] = 'true'
|
11
|
+
end
|
12
|
+
if env[HTTP_ACCESS_CONTROL_REQUEST_HEADERS]
|
13
|
+
h['Access-Control-Allow-Headers'] = env[HTTP_ACCESS_CONTROL_REQUEST_HEADERS]
|
14
|
+
end
|
15
|
+
h
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ForestAdminRails
|
22
|
+
class Engine < ::Rails::Engine
|
23
|
+
isolate_namespace ForestAdminRails
|
24
|
+
|
25
|
+
config.after_initialize do
|
26
|
+
agent_factory = ForestAdminAgent::Builder::AgentFactory.instance
|
27
|
+
agent_factory.setup(ForestAdminRails.config)
|
28
|
+
load_configuration
|
29
|
+
load_cors
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_configuration
|
33
|
+
return unless File.exist?(Rails.root.join('lib', 'forest_admin_rails', 'create_agent.rb'))
|
34
|
+
|
35
|
+
# force eager loading models
|
36
|
+
Rails.application.eager_load!
|
37
|
+
|
38
|
+
# setup agent
|
39
|
+
require Rails.root.join('lib', 'forest_admin_rails', 'create_agent.rb')
|
40
|
+
ForestAdminRails::CreateAgent.setup!
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_cors
|
44
|
+
config.middleware.insert_before 0, Rack::Cors do
|
45
|
+
allow do
|
46
|
+
hostnames = [/\A.*\.forestadmin\.com\z/]
|
47
|
+
hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']
|
48
|
+
|
49
|
+
origins hostnames
|
50
|
+
resource '*', headers: :any, methods: :any, credentials: true, max_age: 86_400
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'dry-configurable'
|
2
|
+
require 'forest_admin_rails/version'
|
3
|
+
require 'forest_admin_rails/engine'
|
4
|
+
require 'zeitwerk'
|
5
|
+
require 'rails/railtie'
|
6
|
+
require 'forest_admin_agent'
|
7
|
+
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
9
|
+
loader.ignore("#{__dir__}/generators")
|
10
|
+
loader.setup
|
11
|
+
|
12
|
+
module ForestAdminRails
|
13
|
+
extend Dry::Configurable
|
14
|
+
|
15
|
+
setting :debug, default: true
|
16
|
+
setting :auth_secret
|
17
|
+
setting :env_secret
|
18
|
+
setting :forest_server_url, default: 'https://api.forestadmin.com'
|
19
|
+
setting :is_production, default: Rails.env.production?
|
20
|
+
setting :prefix, default: 'forest'
|
21
|
+
setting :permission_expiration, default: 300
|
22
|
+
setting :cache_dir, default: :'tmp/cache/forest_admin'
|
23
|
+
setting :schema_path, default: File.join(Dir.pwd, '.forestadmin-schema.json')
|
24
|
+
setting :project_dir, default: Dir.pwd
|
25
|
+
setting :loggerLevel, default: 'info'
|
26
|
+
setting :logger, default: nil
|
27
|
+
|
28
|
+
if defined?(Rails::Railtie)
|
29
|
+
# logic for cors middleware,... here // or it might be into Engine
|
30
|
+
//
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ForestAdminRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
argument :env_secret, type: :string, required: true, desc: 'required', banner: 'env_secret'
|
6
|
+
|
7
|
+
def install
|
8
|
+
@auth_secret = SecureRandom.hex(20)
|
9
|
+
@env_secret = env_secret
|
10
|
+
template 'initializers/config.rb', 'config/initializers/forest_admin_rails.rb'
|
11
|
+
template 'create_agent.rb', 'lib/forest_admin_rails/create_agent.rb'
|
12
|
+
route "mount ForestAdminRails::Engine => '/#{ForestAdminRails.config[:prefix]}'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ForestAdminRails
|
2
|
+
class CreateAgent
|
3
|
+
def self.setup!
|
4
|
+
database_configuration = Rails.configuration.database_configuration
|
5
|
+
datasource = ForestAdminDatasourceActiveRecord::Datasource.new(database_configuration[Rails.env])
|
6
|
+
|
7
|
+
@create_agent = ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
|
8
|
+
customize
|
9
|
+
@create_agent.build
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.customize
|
13
|
+
# @create_agent.add_datasource....
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: forest_admin_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.beta.21
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthieu
|
8
|
+
- Nicolas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-11-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dry-configurable
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '6.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: zeitwerk
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.3'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.3'
|
56
|
+
description: |-
|
57
|
+
Forest is a modern admin interface that works on all major web frameworks. This gem makes Forest
|
58
|
+
admin work on any Rails application (Rails >= 6.1).
|
59
|
+
email:
|
60
|
+
- matthv@gmail.com
|
61
|
+
- nicolasalexandre9@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- app/controllers/forest_admin_rails/forest_controller.rb
|
70
|
+
- app/helpers/forest_admin_rails/application_helper.rb
|
71
|
+
- config/routes.rb
|
72
|
+
- lib/forest_admin_rails.rb
|
73
|
+
- lib/forest_admin_rails/engine.rb
|
74
|
+
- lib/forest_admin_rails/version.rb
|
75
|
+
- lib/generators/forest_admin_rails/install_generator.rb
|
76
|
+
- lib/generators/forest_admin_rails/templates/create_agent.rb
|
77
|
+
- lib/generators/forest_admin_rails/templates/initializers/config.rb
|
78
|
+
- lib/tasks/forest_admin_rails_tasks.rake
|
79
|
+
homepage: https://www.forestadmin.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata:
|
83
|
+
homepage_uri: https://www.forestadmin.com
|
84
|
+
source_code_uri: https://github.com/ForestAdmin/rails-forest_admin
|
85
|
+
changelog_uri: https://github.com/ForestAdmin/rails-forest_admin/CHANGELOG.md
|
86
|
+
rubygems_mfa_required: 'false'
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 3.0.0
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.3.1
|
101
|
+
requirements: []
|
102
|
+
rubygems_version: 3.3.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Official Rails Agent for Forest Admin.
|
106
|
+
test_files: []
|