rails-acu 1.2.1
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 +7 -0
- data/.gitignore +8 -0
- data/.project +18 -0
- data/.rspec +3 -0
- data/.travis.yml +30 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +169 -0
- data/MIT-LICENSE +20 -0
- data/README.md +221 -0
- data/Rakefile +26 -0
- data/bin/rails +13 -0
- data/lib/acu/configs.rb +30 -0
- data/lib/acu/engine.rb +9 -0
- data/lib/acu/errors.rb +37 -0
- data/lib/acu/helpers/helpers.rb +9 -0
- data/lib/acu/injectors.rb +15 -0
- data/lib/acu/listeners.rb +18 -0
- data/lib/acu/monitor.rb +201 -0
- data/lib/acu/rules.rb +134 -0
- data/lib/acu/utilities.rb +14 -0
- data/lib/acu/version.rb +3 -0
- data/lib/generators/acu/install_generator.rb +20 -0
- data/lib/generators/templates/rules.rb +34 -0
- data/lib/generators/templates/setup.rb +30 -0
- data/lib/rails-acu.rb +26 -0
- data/rails-acu-1.2.0.gem +0 -0
- data/rails-acu.gemspec +23 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/admin/manage.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/books.js +2 -0
- data/spec/dummy/app/assets/javascripts/cable.js +12 -0
- data/spec/dummy/app/assets/javascripts/comments.js +2 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/stylesheets/admin/manage.css +4 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/books.css +4 -0
- data/spec/dummy/app/assets/stylesheets/comments.css +4 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +84 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/admin/manage_controller.rb +19 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/home_controller.rb +7 -0
- data/spec/dummy/app/helpers/admin/manage_helper.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/user.rb +8 -0
- data/spec/dummy/app/models/user_type.rb +3 -0
- data/spec/dummy/app/views/admin/manage/add.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/delete.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/index.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/list.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/prove.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/show.html.erb +2 -0
- data/spec/dummy/app/views/home/contact.html.erb +2 -0
- data/spec/dummy/app/views/home/index.html.erb +21 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/acu_rules.rb +31 -0
- data/spec/dummy/config/initializers/acu_setup.rb +14 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/devise.rb +277 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +64 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +19 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/db/migrate/20170329111257_create_books.rb +9 -0
- data/spec/dummy/db/migrate/20170329111323_create_comments.rb +10 -0
- data/spec/dummy/db/migrate/20170329114943_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20170329120950_create_admin_user_types.rb +15 -0
- data/spec/dummy/db/migrate/20170329121612_add_user_type_id_to_users.rb +5 -0
- data/spec/dummy/db/schema.rb +59 -0
- data/spec/dummy/db/seeds.rb +39 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +72 -0
- data/spec/dummy/spec/controllers/application_controller_spec.rb +14 -0
- data/spec/dummy/spec/controllers/home_controller_spec.rb +560 -0
- data/spec/rails_helper.rb +59 -0
- data/spec/spec_helper.rb +104 -0
- metadata +268 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
module Acu
|
2
|
+
module Utilities
|
3
|
+
protected
|
4
|
+
def helper_initialize
|
5
|
+
instance_variable_set("@_params", {}) if not instance_variable_defined?("@_params")
|
6
|
+
end
|
7
|
+
def pass args = {}
|
8
|
+
helper_initialize
|
9
|
+
args.each { |k, v| @_params[k] = v }
|
10
|
+
yield
|
11
|
+
args.each { |k, _| @_params.delete k }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/acu/version.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Acu
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates an Acu initializer and copy locale files to your application."
|
9
|
+
|
10
|
+
def copy_setup
|
11
|
+
template 'setup.rb', "config/initializers/acu_setup.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_rule
|
15
|
+
template 'rules.rb', "config/initializers/acu_rules.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This is an examble, modify it as well
|
2
|
+
Acu::Rules.define do
|
3
|
+
# anyone make a request could be count as everyone!
|
4
|
+
whois :everyone { true }
|
5
|
+
|
6
|
+
# whois :admin, args: [:user] { |c| c and c.user_type.symbol == :ADMIN.to_s }
|
7
|
+
# whois :client, args: [:user] { |c| c and c.user_type.symbol == :PUBLIC.to_s }
|
8
|
+
|
9
|
+
# assume anyone can access
|
10
|
+
# this has security leak of overrideing the `allow_by_default` config
|
11
|
+
# allow :everyone
|
12
|
+
|
13
|
+
# the default namespace
|
14
|
+
# namespace do
|
15
|
+
# controller :home do
|
16
|
+
# allow [:admin, :client], on: [:some_secret_action]
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
# the admin namespace
|
21
|
+
# namespace :admin do
|
22
|
+
# allow :admin
|
23
|
+
|
24
|
+
# controller :contact, only: [:send_message] do
|
25
|
+
# allow :everyone
|
26
|
+
# end
|
27
|
+
|
28
|
+
# controller :contact do
|
29
|
+
# action :support {
|
30
|
+
# allow :client
|
31
|
+
# }
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Acu.setup do |config|
|
2
|
+
# name it to the Base Application Controller that your project
|
3
|
+
# is going to use as a base of all of your controllers.
|
4
|
+
config.base_controller = :ApplicationController
|
5
|
+
|
6
|
+
# to tighten the security this is enabled by default
|
7
|
+
# i.e if it checked to be true, then if a request didn't match to any of rules, it will get passed through
|
8
|
+
# otherwise the requests which don't fit into any of rules, the request is denied by default
|
9
|
+
config.allow_by_default = false
|
10
|
+
|
11
|
+
# the audit log file, to log how the requests handles, good for production
|
12
|
+
# leave it black for nil to disable the logging
|
13
|
+
config.audit_log_file = ""
|
14
|
+
|
15
|
+
# cache the rules to make rule matching much faster
|
16
|
+
# it's not recommended to use it in developement/test evn.
|
17
|
+
config.use_cache = false
|
18
|
+
|
19
|
+
# the caching namespace
|
20
|
+
config.cache_namespace = 'acu'
|
21
|
+
|
22
|
+
# define the expiration of cached entries
|
23
|
+
config.cache_expires_in = nil
|
24
|
+
|
25
|
+
# the race condition ttl
|
26
|
+
config.cache_race_condition_ttl = nil
|
27
|
+
|
28
|
+
# more details about cache options:
|
29
|
+
# http://guides.rubyonrails.org/caching_with_rails.html
|
30
|
+
end
|
data/lib/rails-acu.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
module Acu
|
5
|
+
|
6
|
+
def self.register *files, under: 'acu/', global: false
|
7
|
+
command = 'autoload'
|
8
|
+
command = "Acu.#{command}" if not global
|
9
|
+
files.each { |f| eval "#{command} :#{f.humanize.to_sym}, '#{under}#{f}'" }
|
10
|
+
end
|
11
|
+
|
12
|
+
register 'engine', 'rules', 'monitor', 'listeners', 'injectors', 'configs', 'errors'
|
13
|
+
|
14
|
+
# Default way to set up Acu. Run rails generate devise_install to create
|
15
|
+
# a fresh initializer with all configuration values.
|
16
|
+
def self.setup
|
17
|
+
yield Acu::Configs
|
18
|
+
end
|
19
|
+
|
20
|
+
# include the error utilities
|
21
|
+
include Errors
|
22
|
+
# include listeners
|
23
|
+
include Listeners
|
24
|
+
# include Injector operations
|
25
|
+
include Injectors
|
26
|
+
end
|
data/rails-acu-1.2.0.gem
ADDED
Binary file
|
data/rails-acu.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "acu/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rails-acu"
|
9
|
+
s.version = Acu::VERSION
|
10
|
+
s.authors = ["Dariush Hasanpour"]
|
11
|
+
s.email = ["b.g.dariush@gmail.com"]
|
12
|
+
s.homepage = "https://github.com/noise2/rails-acu"
|
13
|
+
s.summary = "Access Control Unit"
|
14
|
+
s.description = "Access control unit for controller-action sets"
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
|
+
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "rails", "~> 5.0.0", '>= 5.0.0'
|
23
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
|
+
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
3
|
+
//
|
4
|
+
//= require action_cable
|
5
|
+
//= require_self
|
6
|
+
|
7
|
+
(function() {
|
8
|
+
this.App || (this.App = {});
|
9
|
+
|
10
|
+
App.cable = ActionCable.createConsumer();
|
11
|
+
|
12
|
+
}).call(this);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,84 @@
|
|
1
|
+
body {
|
2
|
+
background-color: #fff;
|
3
|
+
color: #333;
|
4
|
+
}
|
5
|
+
|
6
|
+
body, p, ol, ul, td {
|
7
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
8
|
+
font-size: 13px;
|
9
|
+
line-height: 18px;
|
10
|
+
margin: 33px;
|
11
|
+
}
|
12
|
+
|
13
|
+
pre {
|
14
|
+
background-color: #eee;
|
15
|
+
padding: 10px;
|
16
|
+
font-size: 11px;
|
17
|
+
}
|
18
|
+
|
19
|
+
a {
|
20
|
+
color: #000;
|
21
|
+
}
|
22
|
+
|
23
|
+
a:visited {
|
24
|
+
color: #666;
|
25
|
+
}
|
26
|
+
|
27
|
+
a:hover {
|
28
|
+
color: #fff;
|
29
|
+
background-color: #000;
|
30
|
+
}
|
31
|
+
|
32
|
+
th {
|
33
|
+
padding-bottom: 5px;
|
34
|
+
}
|
35
|
+
|
36
|
+
td {
|
37
|
+
padding-bottom: 7px;
|
38
|
+
padding-left: 5px;
|
39
|
+
padding-right: 5px;
|
40
|
+
}
|
41
|
+
|
42
|
+
div.field,
|
43
|
+
div.actions {
|
44
|
+
margin-bottom: 10px;
|
45
|
+
}
|
46
|
+
|
47
|
+
#notice {
|
48
|
+
color: green;
|
49
|
+
}
|
50
|
+
|
51
|
+
.field_with_errors {
|
52
|
+
padding: 2px;
|
53
|
+
background-color: red;
|
54
|
+
display: table;
|
55
|
+
}
|
56
|
+
|
57
|
+
#error_explanation {
|
58
|
+
width: 450px;
|
59
|
+
border: 2px solid red;
|
60
|
+
padding: 7px;
|
61
|
+
padding-bottom: 0;
|
62
|
+
margin-bottom: 20px;
|
63
|
+
background-color: #f0f0f0;
|
64
|
+
}
|
65
|
+
|
66
|
+
#error_explanation h2 {
|
67
|
+
text-align: left;
|
68
|
+
font-weight: bold;
|
69
|
+
padding: 5px 5px 5px 15px;
|
70
|
+
font-size: 12px;
|
71
|
+
margin: -7px;
|
72
|
+
margin-bottom: 0;
|
73
|
+
background-color: #c00;
|
74
|
+
color: #fff;
|
75
|
+
}
|
76
|
+
|
77
|
+
#error_explanation ul li {
|
78
|
+
font-size: 12px;
|
79
|
+
list-style: square;
|
80
|
+
}
|
81
|
+
|
82
|
+
label {
|
83
|
+
display: block;
|
84
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class User < ApplicationRecord
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
4
|
+
devise :database_authenticatable, :registerable,
|
5
|
+
:recoverable, :rememberable, :trackable, :validatable
|
6
|
+
|
7
|
+
belongs_to :user_type
|
8
|
+
end
|