eucalypt 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +4 -4
- data/Rakefile +1 -6
- data/lib/eucalypt/app.rb +7 -0
- data/lib/eucalypt/core/cli/console.rb +24 -3
- data/lib/eucalypt/core/helpers/default_index.rb +1 -1
- data/lib/eucalypt/core/templates/Gemfile.tt +1 -5
- data/lib/eucalypt/core/templates/eucalypt/.travis.yml +1 -1
- data/lib/eucalypt/core/templates/eucalypt/Rakefile +1 -6
- data/lib/eucalypt/core/templates/eucalypt/config/logging.rb +2 -1
- data/lib/eucalypt/generate/namespaces/generate-controller/templates/controller/policy_rest_controller.tt +22 -4
- data/lib/eucalypt/generate/namespaces/generate/cli/generate-scaffold.rb +1 -1
- data/lib/eucalypt/security/permissions.rb +11 -3
- data/lib/eucalypt/version.rb +2 -2
- 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: 771a431c14d309ed211df539c99b3e25ab84e915ca74701daea4e14fcf5adf47
|
4
|
+
data.tar.gz: 333f258faf7446501ed5700009f34300cb7226160dda5722ebde2bb12b164767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c1a78bcaf7f2804dc6a3557930e3c74f9bc4aafa4be272ecd0c224a7d9b6f4b610d27cdfa5c2897e19f88e9bdda088b88bff93caaf63fa15604317b55d370dc
|
7
|
+
data.tar.gz: 054f855e42dd04196f5d3fbb9fc4e1400f98479bb72d44202a358690a5fa67a280f1e785d27ef34b21fcb841fc453183d0076ff25edda5fc136b5e079d0194c3
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
<p align="center"><img width="75px" src="
|
1
|
+
<p align="center"><img width="75px" src="https://i.ibb.co/BKb7SxT/eucalypt.png"></p>
|
2
2
|
|
3
3
|
[![Ruby Version](https://img.shields.io/badge/ruby-~%3E%202.5-red.svg)](https://github.com/eucalypt-framework/eucalypt/blob/0c509a4e22fd97ec52b6f638af21de783f3aafc8/eucalypt.gemspec#L19)
|
4
4
|
[![Gem](https://img.shields.io/gem/v/eucalypt.svg)](https://rubygems.org/gems/eucalypt)
|
5
|
-
[![Build Status](https://travis-ci.
|
5
|
+
[![Build Status](https://travis-ci.com/eucalypt-framework/eucalypt.svg?branch=master)](https://travis-ci.com/eucalypt-framework/eucalypt)
|
6
6
|
[![License](https://img.shields.io/github/license/eucalypt-framework/eucalypt.svg)](https://github.com/eucalypt-framework/eucalypt/blob/master/LICENSE)
|
7
7
|
[![Documentation](https://img.shields.io/badge/docs-gitbook-blue.svg)](https://eucalypt.gitbook.io/eucalypt)
|
8
8
|
|
@@ -22,7 +22,7 @@ $ gem install eucalypt
|
|
22
22
|
|
23
23
|
Running the top-level `eucalypt` command displays information about initializing a new application:
|
24
24
|
|
25
|
-
<p align="center"><img width="70%" src="
|
25
|
+
<p align="center"><img width="70%" src="https://i.ibb.co/4ZkqjS5/cli-1.png"></p>
|
26
26
|
|
27
27
|
Initialize a new application with:
|
28
28
|
|
@@ -36,7 +36,7 @@ $ eucalypt init my-new-app
|
|
36
36
|
|
37
37
|
Move into your new application's directory and run the top-level `eucalypt` command to display a list of all available commands:
|
38
38
|
|
39
|
-
<p align="center"><img width="70%" src="
|
39
|
+
<p align="center"><img width="70%" src="https://i.ibb.co/JsQkH8j/cli-2.png"></p>
|
40
40
|
|
41
41
|
## Documentation
|
42
42
|
|
data/Rakefile
CHANGED
data/lib/eucalypt/app.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Eucalypt
|
2
2
|
APP_FILE = 'Gumfile'.freeze
|
3
|
+
|
3
4
|
def self.app?(directory)
|
4
5
|
File.exist? File.join(directory, APP_FILE)
|
5
6
|
end
|
7
|
+
|
8
|
+
# @note Does not check for boolean variables.
|
9
|
+
# Instead checks for presence.
|
10
|
+
def self.console?
|
11
|
+
!!ENV['CONSOLE']
|
12
|
+
end
|
6
13
|
end
|
@@ -2,14 +2,35 @@ require_relative '__base__'
|
|
2
2
|
module Eucalypt
|
3
3
|
class CLI < Thor
|
4
4
|
using Colorize
|
5
|
-
desc "console", "Interactive console with all files loaded".colorize(:grey)
|
6
|
-
def console
|
5
|
+
desc "console [ENV]", "Interactive console with all files loaded".colorize(:grey)
|
6
|
+
def console(env = ENV['APP_ENV']||'development')
|
7
7
|
directory = File.expand_path('.')
|
8
8
|
if Eucalypt.app? directory
|
9
|
-
|
9
|
+
unless %w[p production d development t test].include? env
|
10
|
+
Out.error "Invalid Rack environment #{env.colorize(:bold)}"
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
env = map_env env
|
15
|
+
cmd = "CONSOLE=true bundle exec irb -r ./app.rb"
|
16
|
+
|
17
|
+
puts "Running command: #{cmd.colorize(:bold)}"
|
18
|
+
puts "Rack environment: #{env.colorize(:bold)}"
|
19
|
+
exec "env APP_ENV=#{env} #{cmd}"
|
10
20
|
else
|
11
21
|
Eucalypt::Error.wrong_directory
|
12
22
|
end
|
13
23
|
end
|
24
|
+
|
25
|
+
no_tasks do
|
26
|
+
def map_env(env)
|
27
|
+
case env
|
28
|
+
when ?p then 'production'
|
29
|
+
when ?d then 'development'
|
30
|
+
when ?t then 'test'
|
31
|
+
else env
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
14
35
|
end
|
15
36
|
end
|
@@ -47,7 +47,7 @@ class MainController < ApplicationController
|
|
47
47
|
</head>
|
48
48
|
<body>
|
49
49
|
<div id="container">
|
50
|
-
<img src="https://
|
50
|
+
<img src="https://i.ibb.co/BKb7SxT/eucalypt.png">
|
51
51
|
<div id="text">
|
52
52
|
<h1>It's running!</h1>
|
53
53
|
<p><b>Eucalypt version</b> : <span>#{Eucalypt::VERSION}</span></p>
|
@@ -1,15 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'irb', require: false
|
3
4
|
gem 'sinatra', '~> 2.0', '>= 2.0.4', require: 'sinatra/base'
|
4
5
|
gem 'eucalypt', '<%= config[:version] %>'
|
5
6
|
gem 'rake', '~> 12.3'
|
6
7
|
gem 'thin', '~> 1.7'
|
7
8
|
|
8
|
-
# IRB is not bundled in Ruby >= 2.6
|
9
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
|
10
|
-
gem 'irb', require: false
|
11
|
-
end
|
12
|
-
|
13
9
|
# Test environment
|
14
10
|
group :test do
|
15
11
|
gem 'rack-test', '~> 1.0', require: 'rack/test'
|
@@ -11,7 +11,8 @@ class ApplicationController < Sinatra::Base
|
|
11
11
|
|
12
12
|
configure :production do
|
13
13
|
enable :logging
|
14
|
-
|
14
|
+
# Output to log file except when running console
|
15
|
+
set :log_file, !Eucalypt.console?
|
15
16
|
end
|
16
17
|
|
17
18
|
set :log_directory_format, "%Y-%m-%d_%H-%M-%S"
|
@@ -10,35 +10,53 @@ class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:rout
|
|
10
10
|
# - e.g. Showing a form for editing <%= config[:resources] %>
|
11
11
|
<% if config[:headless] %>
|
12
12
|
# Authorization helpers are used in the following way (if using headless policies):
|
13
|
+
# - `authorized?(:<%= config[:resource] %>, :read?)`
|
13
14
|
# - `authorized?(:<%= config[:resource] %>, :add?)`
|
14
15
|
# - `authorized?(:<%= config[:resource] %>, :edit?)`
|
15
16
|
# - `authorized?(:<%= config[:resource] %>, :delete?)`
|
16
17
|
<% else %>
|
17
18
|
# Authorization helpers are used in the following way:
|
19
|
+
# - `authorized?(<%= config[:constant] %>, :read?)`
|
18
20
|
# - `authorized?(<%= config[:constant] %>, :add?)`
|
19
21
|
# - `authorized?(<%= config[:constant] %>, :edit?)`
|
20
22
|
# - `authorized?(<%= config[:constant] %>, :delete?)`
|
21
23
|
<% end %>
|
22
24
|
# GET - Browse
|
23
25
|
get '/' do
|
26
|
+
# NOTE: To skip browse permission checks, comment out the `authenticate` and `authorize` lines.
|
27
|
+
authenticate
|
28
|
+
authorize <%= config[:constant] %>, :read?
|
24
29
|
@<%= config[:resources] %> = <%= config[:constant] %>.all
|
25
|
-
# Render
|
30
|
+
# Render the <%= config[:resources] %> as JSON, or create a view
|
31
|
+
content_type :json
|
32
|
+
@<%= config[:resources] %>.to_json
|
33
|
+
rescue Pundit::NotAuthorizedError
|
34
|
+
status 401 # Unauthorized
|
35
|
+
redirect '/'
|
26
36
|
end
|
27
37
|
|
28
38
|
# GET - Read
|
29
39
|
get '/:id' do |id|
|
40
|
+
# NOTE: To skip read permission checks, comment out the `authenticate` and `authorize` lines.
|
41
|
+
authenticate
|
30
42
|
@<%= config[:resource] %> = <%= config[:constant] %>.find id
|
31
|
-
|
43
|
+
authorize @<%= config[:resource] %>, :read?
|
44
|
+
# Render the <%= config[:resource] %> as JSON, or create a view
|
45
|
+
content_type :json
|
46
|
+
@<%= config[:resource] %>.to_json
|
32
47
|
rescue ActiveRecord::RecordNotFound
|
33
48
|
status 404 # Resource not found
|
34
49
|
redirect to '/'
|
50
|
+
rescue Pundit::NotAuthorizedError
|
51
|
+
status 401 # Unauthorized
|
52
|
+
redirect to '/'
|
35
53
|
end
|
36
54
|
|
37
55
|
# POST - Edit
|
38
56
|
post '/:id/edit' do |id|
|
39
57
|
authenticate
|
40
58
|
<%= config[:resource] %> = <%= config[:constant] %>.find id
|
41
|
-
authorize <%= config[:resource]%>, :edit?
|
59
|
+
authorize <%= config[:resource] %>, :edit?
|
42
60
|
<%= config[:resource] %>.update! params['<%= config[:resource] %>']
|
43
61
|
redirect to "/#{id}"
|
44
62
|
rescue ActiveRecord::RecordNotFound
|
@@ -65,7 +83,7 @@ class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:rout
|
|
65
83
|
post '/:id/delete' do |id|
|
66
84
|
authenticate
|
67
85
|
<%= config[:resource] %> = <%= config[:constant] %>.find id
|
68
|
-
authorize <%= config[:resource]%>, :delete?
|
86
|
+
authorize <%= config[:resource] %>, :delete?
|
69
87
|
<%= config[:resource] %>.destroy!
|
70
88
|
redirect to '/'
|
71
89
|
rescue ActiveRecord::RecordNotFound
|
@@ -54,7 +54,7 @@ module Eucalypt
|
|
54
54
|
if options[:policy]
|
55
55
|
args = ['security', 'policy', 'generate', name]
|
56
56
|
args << '--headless' if options[:headless]
|
57
|
-
args << %w[-p add edit delete] if options[:rest]
|
57
|
+
args << %w[-p read add edit delete] if options[:rest]
|
58
58
|
args.flatten!
|
59
59
|
Eucalypt::CLI.start(args)
|
60
60
|
end
|
@@ -10,10 +10,18 @@ Eucalypt.glob('app', '{policies}', '*.rb') do |file|
|
|
10
10
|
role_constant = role_constant_name.constantize
|
11
11
|
|
12
12
|
if ActiveRecord::Base.connection.table_exists? roles_name
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
level = ActiveRecord::Base.logger.level
|
14
|
+
begin
|
15
|
+
ActiveRecord::Base.logger.level = :unknown
|
16
|
+
role_constant.pluck(:permission).each do |permission|
|
17
|
+
policy_constant.define_method "#{permission}?" do
|
18
|
+
role_constant.find_by(permission: permission).send(user.role.send resource_name)
|
19
|
+
end
|
16
20
|
end
|
21
|
+
rescue => exception
|
22
|
+
throw exception
|
23
|
+
ensure
|
24
|
+
ActiveRecord::Base.logger.level = level
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
data/lib/eucalypt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eucalypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Onuonga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|