consent 0.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +21 -0
- data/.travis.yml +6 -1
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/consent.gemspec +8 -4
- data/lib/consent.rb +48 -6
- data/lib/consent/ability.rb +5 -2
- data/lib/consent/action.rb +3 -1
- data/lib/consent/dsl.rb +5 -3
- data/lib/consent/permission.rb +7 -1
- data/lib/consent/permissions.rb +5 -1
- data/lib/consent/railtie.rb +16 -9
- data/lib/consent/reloader.rb +30 -0
- data/lib/consent/rspec.rb +62 -12
- data/lib/consent/subject.rb +3 -1
- data/lib/consent/version.rb +3 -1
- data/lib/consent/view.rb +5 -1
- data/lib/generators/consent/permissions_generator.rb +13 -6
- metadata +34 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f54a2338cba28ba0e887ec44e7e43f9aae2209d4b1017638eaf4334564eae2c
|
4
|
+
data.tar.gz: 2dc433ca07b4615fc56a344d32c3b6adfc5267420419d6d1fd201040ee9bdb31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1ddfc63c31df91ccac74ada8806408353e81f2626d0592dcb954f34c3ffd03aacde585c0f625d9534cd749b2999deebb05860cd2cc3be34ba9b40c2a8645ac4
|
7
|
+
data.tar.gz: 5389891aeef0e65d3752ada1c647c9e0dc1c60debb67fc22019f067dbeb4a4b0c5ac07ab14d0fb760680818c38beab6e4fb4c225f5d07639945b9377cf2dd0bd
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-11-20 02:06:29 -0300 using RuboCop version 0.65.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 5
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
# ExcludedMethods: refine
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Exclude:
|
14
|
+
- 'spec/**/*'
|
15
|
+
- 'lib/consent/rspec.rb'
|
16
|
+
|
17
|
+
# Offense count: 9
|
18
|
+
Style/Documentation:
|
19
|
+
Exclude:
|
20
|
+
- 'spec/**/*'
|
21
|
+
- 'test/**/*'
|
data/.travis.yml
CHANGED
@@ -2,7 +2,11 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
4
|
- 2.2.2
|
5
|
-
|
5
|
+
- 2.5.0
|
6
|
+
before_install: gem install bundler -v 1.17.3
|
7
|
+
script:
|
8
|
+
- bundle exec rubocop
|
9
|
+
- bundle exec rspec
|
6
10
|
deploy:
|
7
11
|
provider: rubygems
|
8
12
|
api_key:
|
@@ -11,3 +15,4 @@ deploy:
|
|
11
15
|
on:
|
12
16
|
tags: true
|
13
17
|
repo: powerhome/consent
|
18
|
+
ruby: 2.5.0
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright Power Home Remodeling Group, LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'consent'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "consent"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/consent.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'consent/version'
|
5
6
|
|
@@ -12,14 +13,17 @@ Gem::Specification.new do |spec|
|
|
12
13
|
spec.summary = 'Consent'
|
13
14
|
spec.description = 'Consent'
|
14
15
|
|
16
|
+
spec.licenses = ['MIT']
|
17
|
+
|
15
18
|
spec.files = `git ls-files`.split.reject do |file|
|
16
19
|
file =~ /^(test|spec|features)/
|
17
20
|
end
|
18
21
|
spec.require_paths = ['lib']
|
19
22
|
|
20
|
-
spec.add_development_dependency 'activesupport', '
|
23
|
+
spec.add_development_dependency 'activesupport', '>= 4.1.11'
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.17.3'
|
21
25
|
spec.add_development_dependency 'cancancan', '~> 1.15.0'
|
22
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
23
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.65.0'
|
25
29
|
end
|
data/lib/consent.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'consent/version'
|
2
4
|
require 'consent/subject'
|
3
5
|
require 'consent/view'
|
@@ -8,23 +10,42 @@ require 'consent/permissions'
|
|
8
10
|
require 'consent/ability' if defined?(CanCan)
|
9
11
|
require 'consent/railtie' if defined?(Rails)
|
10
12
|
|
13
|
+
# Consent makes defining permissions easier by providing a clean,
|
14
|
+
# concise DSL for authorization so that all abilities do not have
|
15
|
+
# to be in your `Ability` class.
|
11
16
|
module Consent
|
12
|
-
FULL_ACCESS = %w
|
17
|
+
FULL_ACCESS = %w[1 true].freeze
|
13
18
|
|
19
|
+
# Default views available to every permission
|
20
|
+
#
|
21
|
+
# i.e.:
|
22
|
+
# Defining a view with no conditions:
|
23
|
+
# Consent.default_views[:all] = Consent::View.new(:all, "All")
|
24
|
+
#
|
25
|
+
# @return [Hash<Symbol,Consent::View>]
|
14
26
|
def self.default_views
|
15
27
|
@default_views ||= {}
|
16
28
|
end
|
17
29
|
|
30
|
+
# Subjects defined in Consent
|
31
|
+
#
|
32
|
+
# @return [Array<Consent::Subject>]
|
18
33
|
def self.subjects
|
19
34
|
@subjects ||= []
|
20
35
|
end
|
21
36
|
|
37
|
+
# Finds all subjects defined with the given key
|
38
|
+
#
|
39
|
+
# @return [Array<Consent::Subject>]
|
22
40
|
def self.find_subjects(subject_key)
|
23
|
-
@subjects.
|
41
|
+
@subjects.find_all do |subject|
|
24
42
|
subject.key.eql?(subject_key)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
46
|
+
# Finds an action within a subject context
|
47
|
+
#
|
48
|
+
# @return [Consent::Action,nil]
|
28
49
|
def self.find_action(subject_key, action_key)
|
29
50
|
Consent.find_subjects(subject_key)
|
30
51
|
.map(&:actions).flatten
|
@@ -33,18 +54,36 @@ module Consent
|
|
33
54
|
end
|
34
55
|
end
|
35
56
|
|
57
|
+
# Finds a view within a subject context
|
58
|
+
#
|
59
|
+
# @return [Consent::View,nil]
|
36
60
|
def self.find_view(subject_key, view_key)
|
37
61
|
views = Consent.find_subjects(subject_key)
|
38
|
-
.map
|
62
|
+
.map(&:views)
|
39
63
|
.reduce({}, &:merge)
|
40
64
|
views[view_key]
|
41
65
|
end
|
42
66
|
|
43
|
-
|
44
|
-
|
45
|
-
|
67
|
+
# Loads all permission (ruby) files from the given directory
|
68
|
+
# and using the given mechanism (default: :require)
|
69
|
+
#
|
70
|
+
# @param paths [Array<String,#to_s>] paths where the ruby files are located
|
71
|
+
# @param mechanism [:require,:load] mechanism to load the files
|
72
|
+
def self.load_subjects!(paths, mechanism = :require)
|
73
|
+
permission_files = paths.map { |dir| File.join(dir, '*.rb') }
|
74
|
+
Dir[*permission_files].each(&Kernel.method(mechanism))
|
46
75
|
end
|
47
76
|
|
77
|
+
# Defines a subject with the given key, label and options
|
78
|
+
#
|
79
|
+
# i.e:
|
80
|
+
# Consent.define :users, "User management" do
|
81
|
+
# view :department, "Same department only" do |user|
|
82
|
+
# { department_id: user.department_id }
|
83
|
+
# end
|
84
|
+
# action :read, "Can view users"
|
85
|
+
# action :update, "Can edit existing user", views: :department
|
86
|
+
# end
|
48
87
|
def self.define(key, label, options = {}, &block)
|
49
88
|
defaults = options.fetch(:defaults, {})
|
50
89
|
subjects << Subject.new(key, label).tap do |subject|
|
@@ -52,6 +91,9 @@ module Consent
|
|
52
91
|
end
|
53
92
|
end
|
54
93
|
|
94
|
+
# Maps a permissions hash to a Consent::Permissions
|
95
|
+
#
|
96
|
+
# @return [Consent::Permissions]
|
55
97
|
def self.permissions(permissions)
|
56
98
|
Permissions.new(permissions)
|
57
99
|
end
|
data/lib/consent/ability.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
4
|
+
# Defines a CanCan(Can)::Ability class based on a permissions hash
|
2
5
|
class Ability
|
3
6
|
include CanCan::Ability
|
4
7
|
|
5
8
|
def initialize(permissions, *args)
|
6
9
|
Consent.permissions(permissions).each do |permission|
|
7
10
|
conditions = permission.conditions(*args)
|
8
|
-
|
9
|
-
can permission.action_key, permission.subject_key, conditions, &
|
11
|
+
ocond = permission.object_conditions(*args)
|
12
|
+
can permission.action_key, permission.subject_key, conditions, &ocond
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
data/lib/consent/action.rb
CHANGED
data/lib/consent/dsl.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
2
|
-
class DSL
|
4
|
+
class DSL # :nodoc:
|
3
5
|
attr_reader :subject
|
4
6
|
|
5
7
|
def initialize(subject, defaults)
|
@@ -11,13 +13,13 @@ module Consent
|
|
11
13
|
DSL.build(@subject, @defaults.merge(new_defaults), &block)
|
12
14
|
end
|
13
15
|
|
14
|
-
# rubocop:disable
|
16
|
+
# rubocop:disable Lint/UnusedBlockArgument, Security/Eval
|
15
17
|
def eval_view(key, label, collection_conditions)
|
16
18
|
view key, label do |user|
|
17
19
|
eval(collection_conditions)
|
18
20
|
end
|
19
21
|
end
|
20
|
-
# rubocop:enable
|
22
|
+
# rubocop:enable Lint/UnusedBlockArgument, Security/Eval
|
21
23
|
|
22
24
|
def view(key, label, instance = nil, collection = nil, &block)
|
23
25
|
collection ||= block
|
data/lib/consent/permission.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
2
|
-
class Permission
|
4
|
+
class Permission # :nodoc:
|
3
5
|
def initialize(subject, action, view = nil)
|
4
6
|
@subject = subject
|
5
7
|
@action = action
|
@@ -14,6 +16,9 @@ module Consent
|
|
14
16
|
@action.key
|
15
17
|
end
|
16
18
|
|
19
|
+
# Disables Sytle/SafeNavigation to keep this code
|
20
|
+
# compatible with ruby < 2.3
|
21
|
+
# rubocop:disable Style/SafeNavigation
|
17
22
|
def view_key
|
18
23
|
@view && @view.key
|
19
24
|
end
|
@@ -25,5 +30,6 @@ module Consent
|
|
25
30
|
def object_conditions(*args)
|
26
31
|
@view && @view.object_conditions(*args)
|
27
32
|
end
|
33
|
+
# rubocop:enable Style/SafeNavigation
|
28
34
|
end
|
29
35
|
end
|
data/lib/consent/permissions.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
2
|
-
class Permissions
|
4
|
+
class Permissions # :nodoc:
|
3
5
|
include Enumerable
|
4
6
|
|
5
7
|
def initialize(permissions)
|
@@ -25,12 +27,14 @@ module Consent
|
|
25
27
|
|
26
28
|
def full(subject, action, view_key)
|
27
29
|
return unless Consent::FULL_ACCESS.include?(view_key.to_s.strip)
|
30
|
+
|
28
31
|
Permission.new(subject, action)
|
29
32
|
end
|
30
33
|
|
31
34
|
def partial(subject, action, view_key)
|
32
35
|
view = subject.view_for(action, view_key.to_s.to_sym)
|
33
36
|
return if view.nil?
|
37
|
+
|
34
38
|
Permission.new(subject, action, view)
|
35
39
|
end
|
36
40
|
end
|
data/lib/consent/railtie.rb
CHANGED
@@ -1,19 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'consent/reloader'
|
4
|
+
|
1
5
|
module Consent
|
2
6
|
# Plugs consent permission load to the Rails class loading cycle
|
3
7
|
class Railtie < Rails::Railtie
|
4
|
-
config.before_configuration do
|
5
|
-
default_path =
|
6
|
-
config.consent =
|
8
|
+
config.before_configuration do |app|
|
9
|
+
default_path = app.root.join('app', 'permissions')
|
10
|
+
config.consent = Consent::Reloader.new(
|
11
|
+
default_path,
|
12
|
+
ActiveSupport::Dependencies.mechanism
|
13
|
+
)
|
7
14
|
end
|
8
15
|
|
9
|
-
config.
|
10
|
-
|
11
|
-
Consent.load_subjects! Rails.application.config.consent.paths
|
16
|
+
config.after_initialize do |app|
|
17
|
+
app.config.consent.execute
|
12
18
|
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
ActiveSupport::Dependencies.autoload_paths -=
|
20
|
+
initializer 'initialize consent permissions reloading' do |app|
|
21
|
+
app.reloaders << config.consent
|
22
|
+
ActiveSupport::Dependencies.autoload_paths -= config.consent.paths
|
23
|
+
config.to_prepare { app.config.consent.execute }
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Consent
|
4
|
+
# Rails file reloader to detect permission changes and apply them to consent
|
5
|
+
class Reloader
|
6
|
+
attr_reader :paths
|
7
|
+
delegate :updated?, :execute, :execute_if_updated, to: :updater
|
8
|
+
|
9
|
+
def initialize(default_path, mechanism)
|
10
|
+
@paths = [default_path]
|
11
|
+
@mechanism = mechanism
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def reload!
|
17
|
+
Consent.subjects.clear
|
18
|
+
Consent.load_subjects! paths, @mechanism
|
19
|
+
end
|
20
|
+
|
21
|
+
def updater
|
22
|
+
@updater ||= ActiveSupport::FileUpdateChecker.new([], globs) { reload! }
|
23
|
+
end
|
24
|
+
|
25
|
+
def globs
|
26
|
+
pairs = paths.map { |path| [path.to_s, %w[rb]] }
|
27
|
+
Hash[pairs]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/consent/rspec.rb
CHANGED
@@ -1,6 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'consent'
|
2
4
|
|
3
5
|
module Consent
|
6
|
+
# RSpec helpers for consent. Given permissions are loaded,
|
7
|
+
# gives you the ability of defining permission specs like
|
8
|
+
#
|
9
|
+
# Given "users" permissions
|
10
|
+
# Consent.define :users, "User management" do
|
11
|
+
# view :department, "Same department only" do |user|
|
12
|
+
# { department_id: user.department_id }
|
13
|
+
# end
|
14
|
+
# action :read, "Can view users"
|
15
|
+
# action :update, "Can edit existing user", views: :department
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# RSpec.describe "User permissions" do
|
19
|
+
# include Consent::Rspec
|
20
|
+
# let(:user) { double(department_id: 15) }
|
21
|
+
#
|
22
|
+
# it do
|
23
|
+
# is_expected.to consent_view(:department, department_id: 15).to(user)
|
24
|
+
# end
|
25
|
+
# it { is_expected.to consent_action(:read) }
|
26
|
+
# it { is_expected.to consent_action(:update).with_views(:department) }
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Find more examples at:
|
30
|
+
# https://github.com/powerhome/consent
|
4
31
|
module Rspec
|
5
32
|
extend RSpec::Matchers::DSL
|
6
33
|
|
@@ -11,17 +38,25 @@ module Consent
|
|
11
38
|
|
12
39
|
match do |subject_key|
|
13
40
|
action = Consent.find_action(subject_key, action_key)
|
14
|
-
action && @views
|
41
|
+
if action && @views
|
42
|
+
values_match?(action.view_keys.sort, @views.sort)
|
43
|
+
else
|
44
|
+
!action.nil?
|
45
|
+
end
|
15
46
|
end
|
16
47
|
|
17
48
|
failure_message do |subject_key|
|
18
49
|
action = Consent.find_action(subject_key, action_key)
|
19
|
-
message =
|
20
|
-
|
21
|
-
|
50
|
+
message = format(
|
51
|
+
'expected %<skey>s (%<sclass>s) to provide action %<action>s',
|
52
|
+
skey: subject_key.to_s, sclass: subject.class, action: action_key
|
53
|
+
)
|
22
54
|
|
23
55
|
if action && @views
|
24
|
-
|
56
|
+
format(
|
57
|
+
'%<message>s with views %<views>s, but actual views are %<keys>p',
|
58
|
+
message: message, views: @views, keys: action.view_keys
|
59
|
+
)
|
25
60
|
else
|
26
61
|
message
|
27
62
|
end
|
@@ -35,21 +70,36 @@ module Consent
|
|
35
70
|
|
36
71
|
match do |subject_key|
|
37
72
|
view = Consent.find_view(subject_key, view_key)
|
38
|
-
|
73
|
+
if conditions
|
74
|
+
view&.conditions(*@context).eql?(conditions)
|
75
|
+
else
|
76
|
+
!view.nil?
|
77
|
+
end
|
39
78
|
end
|
40
79
|
|
41
80
|
failure_message do |subject_key|
|
42
81
|
view = Consent.find_view(subject_key, view_key)
|
43
|
-
message =
|
44
|
-
|
45
|
-
|
82
|
+
message = format(
|
83
|
+
'expected %<skey>s (%<sclass>s) to provide view %<view>s with` \
|
84
|
+
`%<conditions>p, but',
|
85
|
+
skey: subject_key.to_s, sclass: subject.class,
|
86
|
+
view: view_key, conditions: conditions
|
87
|
+
)
|
46
88
|
|
47
89
|
if view && conditions
|
48
90
|
actual_conditions = view.conditions(*@context)
|
49
|
-
|
91
|
+
format(
|
92
|
+
'%<message>s conditions are %<conditions>p',
|
93
|
+
message: message, conditions: actual_conditions
|
94
|
+
)
|
50
95
|
else
|
51
|
-
actual_views = Consent.find_subjects(subject_key)
|
52
|
-
|
96
|
+
actual_views = Consent.find_subjects(subject_key)
|
97
|
+
.map(&:views)
|
98
|
+
.map(&:keys).flatten
|
99
|
+
format(
|
100
|
+
'%<message>s available views are %<views>p',
|
101
|
+
message: message, views: actual_views
|
102
|
+
)
|
53
103
|
end
|
54
104
|
end
|
55
105
|
end
|
data/lib/consent/subject.rb
CHANGED
data/lib/consent/version.rb
CHANGED
data/lib/consent/view.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
2
|
-
class View
|
4
|
+
class View # :nodoc:
|
3
5
|
attr_reader :key, :label
|
4
6
|
|
5
7
|
def initialize(key, label, instance = nil, collection = nil)
|
@@ -11,11 +13,13 @@ module Consent
|
|
11
13
|
|
12
14
|
def conditions(*args)
|
13
15
|
return @collection unless @collection.respond_to?(:call)
|
16
|
+
|
14
17
|
@collection.call(*args)
|
15
18
|
end
|
16
19
|
|
17
20
|
def object_conditions(*args)
|
18
21
|
return @instance unless @instance.respond_to?(:curry)
|
22
|
+
|
19
23
|
@instance.curry[*args]
|
20
24
|
end
|
21
25
|
end
|
@@ -1,14 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Consent
|
2
|
-
class PermissionsGenerator < Rails::Generators::NamedBase
|
3
|
-
source_root File.expand_path('
|
4
|
+
class PermissionsGenerator < Rails::Generators::NamedBase # :nodoc:
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
4
6
|
argument :description, type: :string, required: false
|
5
7
|
|
6
8
|
def create_permissions
|
7
|
-
template
|
8
|
-
|
9
|
-
|
9
|
+
template(
|
10
|
+
'permissions.rb.erb',
|
11
|
+
"app/permissions/#{file_path}.rb",
|
12
|
+
assigns: { description: description }
|
13
|
+
)
|
10
14
|
|
11
|
-
template
|
15
|
+
template(
|
16
|
+
'permissions_spec.rb.erb',
|
17
|
+
"spec/permissions/#{file_path}_spec.rb"
|
18
|
+
)
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Palhares
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.1.11
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.1.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.17.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.17.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: cancancan
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.15.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.15.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.65.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.65.0
|
83
97
|
description: Consent
|
84
98
|
email:
|
85
99
|
- chjunior@gmail.com
|
@@ -89,9 +103,12 @@ extra_rdoc_files: []
|
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
91
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".rubocop_todo.yml"
|
92
108
|
- ".ruby-version"
|
93
109
|
- ".travis.yml"
|
94
110
|
- Gemfile
|
111
|
+
- LICENSE
|
95
112
|
- README.md
|
96
113
|
- Rakefile
|
97
114
|
- TODO.md
|
@@ -105,6 +122,7 @@ files:
|
|
105
122
|
- lib/consent/permission.rb
|
106
123
|
- lib/consent/permissions.rb
|
107
124
|
- lib/consent/railtie.rb
|
125
|
+
- lib/consent/reloader.rb
|
108
126
|
- lib/consent/rspec.rb
|
109
127
|
- lib/consent/subject.rb
|
110
128
|
- lib/consent/version.rb
|
@@ -113,7 +131,8 @@ files:
|
|
113
131
|
- lib/generators/consent/templates/permissions.rb.erb
|
114
132
|
- lib/generators/consent/templates/permissions_spec.rb.erb
|
115
133
|
homepage:
|
116
|
-
licenses:
|
134
|
+
licenses:
|
135
|
+
- MIT
|
117
136
|
metadata: {}
|
118
137
|
post_install_message:
|
119
138
|
rdoc_options: []
|