scaffold_plus 1.10.1 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 892354dc67fc130674d405fa1cf7d48a0d20fcca
|
4
|
+
data.tar.gz: 6505cce490b378beb556bfa5a42a1663a047bc3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b2fd31da58d798575a5709defb2943e3e8ec56df75d54638bb5714443a39f2ec8b68c549e1e312faa0765a49c7d05c661047eb54f24528c1caeac691832f9cb
|
7
|
+
data.tar.gz: f44bac767b7c586a07af26c615e8dd12d0454f64256e19e24650b00d7429951a328b19a04a86840cc3a63100a7ff3d3efa5cc82d4b69d4a4fe187f7990641d2f
|
@@ -8,6 +8,8 @@ module ScaffoldPlus
|
|
8
8
|
desc: 'The object that will be protected'
|
9
9
|
class_option :authorizer, type: :string,
|
10
10
|
desc: 'authorizer (full name) instead of <class name>Authorizer'
|
11
|
+
class_option :controller, type: :boolean, default: false,
|
12
|
+
desc: 'add standard authorization to controller'
|
11
13
|
class_option :before, type: :boolean, default: false,
|
12
14
|
desc: 'Add a line before generated text in model'
|
13
15
|
class_option :after, type: :boolean, default: false,
|
@@ -32,6 +34,23 @@ module ScaffoldPlus
|
|
32
34
|
return if options.authorizer.present?
|
33
35
|
template "authorizer.rb", "app/authorizers/#{name}_authorizer.rb"
|
34
36
|
end
|
37
|
+
|
38
|
+
def update_controller
|
39
|
+
return unless options.controller?
|
40
|
+
file = "app/controllers/#{table_name}_controller.rb"
|
41
|
+
inject_into_file file, after: /before_action :set_#{name}.*$/ do
|
42
|
+
"\n authorize_actions_for #{class_name}, only: [:index, :new, :create]"
|
43
|
+
end
|
44
|
+
inject_into_file file, after: /private$/ do
|
45
|
+
"\n def authority_forbidden(error)" +
|
46
|
+
"\n Authority.logger.warn(error.message)" +
|
47
|
+
"\n redirect_to breeders_path, alert: 'Forbidden'" +
|
48
|
+
"\n end\n"
|
49
|
+
end
|
50
|
+
inject_into_file file, after: /@#{name} = #{class_name}.find.*$/ do
|
51
|
+
"\n authorize_action_for(@#{name})"
|
52
|
+
end
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
37
56
|
end
|