check_permission 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +4 -14
- data/lib/check_permission/version.rb +1 -1
- data/lib/generators/active_record/check_permission_generator.rb +17 -3
- data/lib/generators/active_record/templates/{existing_migration.rb → migration_existing.rb} +0 -0
- data/lib/generators/check_permission/check_permission_generator.rb +2 -4
- data/lib/generators/check_permission/orm_helpers.rb +35 -5
- metadata +2 -3
- data/check_permission-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebd1454fa916b0e537765f88c05da50da6b30e2a
|
4
|
+
data.tar.gz: 205499cee654ab67ecef3388825a3a14cb212ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6b863119afba4266957f7a1c4c15acdc71a73482ee634ed124dcc0e9d0c38f7b4879219548983fefa37ea64f0eeba71c1c47c9b4d4c52a39cbb21e47adb4ac
|
7
|
+
data.tar.gz: 952f489c228611989f4e57c5246f3e2ec87ef38f59b43a4c9a4715a1282eb0b0337701ca2b8f27040022d3ba460304c0d8e2aa8d85e41b37229cd7708952e43d
|
data/README.md
CHANGED
@@ -31,9 +31,9 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
It will create the migrations for the user and permission and it will create the models for the same.
|
33
33
|
|
34
|
-
Create form for assinging the permissions.
|
34
|
+
Create form for assinging the permissions.
|
35
35
|
in UsersController
|
36
|
-
|
36
|
+
|
37
37
|
def new
|
38
38
|
@user = User.new
|
39
39
|
Permission_for.each do |model|
|
@@ -45,21 +45,11 @@ Or install it yourself as:
|
|
45
45
|
|
46
46
|
<%= form_for @user do |f|%
|
47
47
|
-- stuff --
|
48
|
-
<%=
|
49
|
-
<tr>
|
50
|
-
<%=p.hidden_field :resource_name%>
|
51
|
-
<td><%=p.object.resource_name%></td>
|
52
|
-
<td><%=p.check_box :is_read%></td>
|
53
|
-
<td><%=p.check_box :is_create%></td>
|
54
|
-
<td><%=p.check_box :is_update%></td>
|
55
|
-
<td><%=p.check_box :is_destroy%></td>
|
56
|
-
|
57
|
-
</tr>
|
58
|
-
<% end %>
|
48
|
+
<%= render 'permissions/permissions', f: f%>
|
59
49
|
<%end%
|
60
50
|
|
61
51
|
Call in controller or view has_permission
|
62
|
-
|
52
|
+
include PermissionsHelper in application controller
|
63
53
|
def edit
|
64
54
|
-- do stuff --
|
65
55
|
end if has_permission
|
@@ -8,7 +8,7 @@ module ActiveRecord
|
|
8
8
|
source_root File.expand_path("../templates", __FILE__)
|
9
9
|
def copy_permission_migration
|
10
10
|
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
11
|
-
migration_template "migration_existing.rb", "db/migrate/add_permission_to_#{table_name}.rb"
|
11
|
+
# migration_template "migration_existing.rb", "db/migrate/add_permission_to_#{table_name}.rb"
|
12
12
|
else
|
13
13
|
migration_template "migration.rb", "db/migrate/permission_create_#{table_name}.rb"
|
14
14
|
end
|
@@ -17,13 +17,27 @@ module ActiveRecord
|
|
17
17
|
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
18
18
|
end
|
19
19
|
|
20
|
-
def generate_model_permission
|
21
|
-
puts "i am in permission model #{name}"
|
20
|
+
def generate_model_permission
|
22
21
|
permission = "Permission"
|
23
22
|
Rails::Generators.invoke("active_record:model", [permission,"is_read:boolean", "is_update:boolean",
|
24
23
|
"is_create:boolean", "is_destroy:boolean", "resource_name:string", "#{table_name.singularize}:references"], {migration: true, timestamps: true})
|
25
24
|
end
|
26
25
|
|
26
|
+
def generate_view
|
27
|
+
create_file Rails.root.join("app", "views", "permissions", "_permissions.html.rb"), "#{partial_content}" unless permission_view_exists?
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_helper
|
31
|
+
create_file Rails.root.join("app", "helpers", "permissions_helper.rb"), "
|
32
|
+
module PermissionsHelper
|
33
|
+
include CheckPermission
|
34
|
+
def has_permission
|
35
|
+
super(params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
" unless permissions_helper_exists?
|
39
|
+
end
|
40
|
+
|
27
41
|
def inject_permission_content
|
28
42
|
content = model_contents
|
29
43
|
class_path = if namespaced?
|
File without changes
|
@@ -2,15 +2,13 @@ require 'rails/generators/named_base'
|
|
2
2
|
module CheckPermission
|
3
3
|
module Generators
|
4
4
|
class CheckPermissionGenerator < Rails::Generators::NamedBase
|
5
|
-
include Rails::Generators::ResourceHelpers
|
6
|
-
puts "pemission base name estart"
|
5
|
+
include Rails::Generators::ResourceHelpers
|
7
6
|
namespace "check_permission"
|
8
7
|
source_root File.expand_path("../templates", __FILE__)
|
9
8
|
desc "Generates a model with the given NAME (if one does not exist) with permission " <<
|
10
9
|
"configuration plus a migration file."
|
11
10
|
hook_for :orm
|
12
|
-
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
13
|
-
puts "pemission base name end"
|
11
|
+
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -12,15 +12,41 @@ module CheckPermission
|
|
12
12
|
CONTENT
|
13
13
|
buffer
|
14
14
|
end
|
15
|
+
|
16
|
+
def partial_content
|
17
|
+
buffer = <<-CONTENT
|
18
|
+
<%= f.fields_for :permissions do |p|%>
|
19
|
+
<tr>
|
20
|
+
<%=p.hidden_field :resource_name%>
|
21
|
+
<td><label><%=p.object.resource_name%></label></td><br>
|
22
|
+
<td><label><%=p.check_box :is_read%> Is Read?</label></td>
|
23
|
+
<td><label><%=p.check_box :is_create%> Is Create</label></td>
|
24
|
+
<td><label><%=p.check_box :is_update%> Is Update</label></td>
|
25
|
+
<td><label><%=p.check_box :is_destroy%> Is Destroy</label></td>
|
26
|
+
|
27
|
+
</tr>
|
28
|
+
<% end %>
|
29
|
+
CONTENT
|
30
|
+
buffer
|
31
|
+
end
|
15
32
|
private
|
16
|
-
|
17
|
-
|
33
|
+
|
34
|
+
def permission_view_exists?
|
35
|
+
File.exists?(File.join(destination_root, permission_view_path))
|
36
|
+
end
|
37
|
+
|
38
|
+
def permissions_helper_exists?
|
39
|
+
File.exists?(File.join(destination_root, permission_helper_path))
|
18
40
|
end
|
19
41
|
|
20
42
|
def model_exists?
|
21
43
|
File.exists?(File.join(destination_root, model_path))
|
22
44
|
end
|
23
45
|
|
46
|
+
# def model_exists?
|
47
|
+
# File.exists?(File.join(destination_root, model_path))
|
48
|
+
# end
|
49
|
+
|
24
50
|
def migration_exists?(table_name)
|
25
51
|
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_#{table_name}.rb$/).first
|
26
52
|
end
|
@@ -31,9 +57,13 @@ module CheckPermission
|
|
31
57
|
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
32
58
|
end
|
33
59
|
|
34
|
-
def
|
35
|
-
@
|
36
|
-
end
|
60
|
+
def permission_helper_path
|
61
|
+
@permission_helper_path ||= File.join("app", "helpers", "permissions_helper.rb")
|
62
|
+
end
|
63
|
+
|
64
|
+
def permission_view_path
|
65
|
+
@permission_view_path ||= File.join("app", "views", "permissions" "permissions_helper.rb")
|
66
|
+
end
|
37
67
|
end
|
38
68
|
end
|
39
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_permission
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sunil
|
@@ -68,13 +68,12 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
|
-
- check_permission-0.1.0.gem
|
72
71
|
- check_permission.gemspec
|
73
72
|
- lib/check_permission.rb
|
74
73
|
- lib/check_permission/version.rb
|
75
74
|
- lib/generators/active_record/check_permission_generator.rb
|
76
|
-
- lib/generators/active_record/templates/existing_migration.rb
|
77
75
|
- lib/generators/active_record/templates/migration.rb
|
76
|
+
- lib/generators/active_record/templates/migration_existing.rb
|
78
77
|
- lib/generators/check_permission/check_permission_generator.rb
|
79
78
|
- lib/generators/check_permission/install_generator.rb
|
80
79
|
- lib/generators/check_permission/orm_helpers.rb
|
data/check_permission-0.1.0.gem
DELETED
Binary file
|