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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b9cdc6ec4c9b2140900fd3fc555b87d02a0b29a
4
- data.tar.gz: 8c3db4cf6a57b8d8f6b03abeca622fb826f474c9
3
+ metadata.gz: ebd1454fa916b0e537765f88c05da50da6b30e2a
4
+ data.tar.gz: 205499cee654ab67ecef3388825a3a14cb212ac2
5
5
  SHA512:
6
- metadata.gz: 88f44f9f528329fc2a8a615decf58f5ee672a5787bf95d78c97e05f7d37ebc4b92816e9620e7ac1805e5f67e45c87b1e9dd2693205705e487b857e8d9664de10
7
- data.tar.gz: 0dc24fc1b0dd11859ccae8de077341b878a67dc161c5623eb77597930b55cb79da80b9d127ee1cdd950a8cf13bdd167b981969a1e7716c6698af6dcefaee1144
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
- <%= f.fields_for :permissions do |p|%>
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
@@ -1,3 +1,3 @@
1
1
  module CheckPermission
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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?
@@ -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
- def permission_model_exists?
17
- File.exists?(File.join(destination_root, permission_model_path))
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 permission_model_path
35
- @permission_model_path ||= File.join("app", "models", "permission.rb")
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.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
Binary file