citygate 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/README.rdoc +13 -3
  2. data/app/assets/javascripts/citygate/home.js.coffee.erb +6 -5
  3. data/app/controllers/citygate/application_controller.rb +1 -0
  4. data/app/controllers/citygate/users_controller.rb +2 -0
  5. data/app/models/citygate/role.rb +4 -0
  6. data/app/models/citygate/user.rb +24 -1
  7. data/config/locales/views/admin/actions/en.yml +4 -0
  8. data/db/seeds.rb +0 -14
  9. data/lib/ability/USAGE +8 -0
  10. data/lib/ability/ability_generator.rb +3 -0
  11. data/lib/ability/templates/ability.rb +25 -0
  12. data/lib/citygate/engine.rb +8 -1
  13. data/lib/citygate/version.rb +1 -1
  14. data/lib/generators/ability/USAGE +8 -0
  15. data/lib/generators/ability/ability_generator.rb +7 -0
  16. data/lib/generators/ability/templates/ability.rb +25 -0
  17. data/spec/dummy/config/application.rb +3 -1
  18. data/spec/dummy/db/development.sqlite3 +0 -0
  19. data/spec/dummy/db/migrate/{20120706095546_devise_create_users.citygate.rb → 20121010234716_devise_create_users.citygate.rb} +0 -0
  20. data/spec/dummy/db/migrate/{20120706095547_add_name_to_users.citygate.rb → 20121010234717_add_name_to_users.citygate.rb} +0 -0
  21. data/spec/dummy/db/migrate/{20120706095548_add_confirmable_to_users.citygate.rb → 20121010234718_add_confirmable_to_users.citygate.rb} +0 -0
  22. data/spec/dummy/db/migrate/{20120706095549_devise_invitable_add_to_users.citygate.rb → 20121010234719_devise_invitable_add_to_users.citygate.rb} +0 -0
  23. data/spec/dummy/db/migrate/{20120706095550_add_omniauth_to_devise.citygate.rb → 20121010234720_add_omniauth_to_devise.citygate.rb} +0 -0
  24. data/spec/dummy/db/migrate/{20120706095551_create_roles.citygate.rb → 20121010234721_create_roles.citygate.rb} +0 -0
  25. data/spec/dummy/db/schema.rb +1 -11
  26. data/spec/dummy/db/test.sqlite3 +0 -0
  27. data/spec/dummy/features/step_definitions/user_steps.rb +7 -0
  28. data/spec/dummy/features/support/paths.rb +3 -0
  29. data/spec/dummy/features/users/user_edit.feature +2 -0
  30. data/spec/dummy/features/users/users_admin.feature +1 -1
  31. data/spec/dummy/lib/ability.rb +25 -0
  32. data/spec/dummy/log/development.log +2692 -0
  33. data/spec/dummy/log/test.log +23012 -0
  34. data/spec/dummy/spec/models/role_spec.rb +13 -0
  35. data/spec/dummy/spec/models/user_spec.rb +47 -0
  36. data/spec/dummy/tmp/cache/assets/C72/B10/sprockets%2F21a4b8118f1f4254bf815e306027b951 +0 -0
  37. data/spec/dummy/tmp/cache/assets/C7A/CE0/sprockets%2F9124c83a02e7332a90b2883b69f81d04 +0 -0
  38. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  39. data/spec/dummy/tmp/cache/assets/CE3/150/sprockets%2F7d7a09e1df5c7510266a8d752683c4b3 +0 -0
  40. data/spec/dummy/tmp/cache/assets/D0D/DE0/sprockets%2Fa35442f02b0b2479f22d83d639d8c4fd +0 -0
  41. data/spec/dummy/tmp/cache/assets/D11/620/sprockets%2Ff9ea58224378018a71daac5437676adc +0 -0
  42. data/spec/dummy/tmp/cache/assets/D14/F80/sprockets%2F88a8b65bba21cb666758df2ff9300272 +0 -0
  43. data/spec/dummy/tmp/cache/assets/D1C/110/sprockets%2Ff7118b71a9f4d6d8bf76e874be631322 +0 -0
  44. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  45. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  46. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  47. data/spec/dummy/tmp/cache/assets/D8F/400/sprockets%2F1aeaa1227411ad4c4ee0a489f5dbc668 +0 -0
  48. data/spec/dummy/tmp/cache/assets/D99/BF0/sprockets%2F2fd8d582e234f8d0a741c1b4cafb716e +0 -0
  49. data/spec/dummy/tmp/cache/assets/D9E/F10/sprockets%2F9ab223df888d724dcad09eb1163cc5f4 +0 -0
  50. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  51. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  52. metadata +312 -198
  53. data/app/assets/javascripts/citygate/admin_users.coffee +0 -2
  54. data/app/assets/javascripts/citygate/jquery.pjax.js +0 -690
  55. data/app/models/citygate/permission.rb +0 -24
  56. data/db/migrate/20120727143920_create_permissions_table.rb +0 -12
  57. data/db/migrate/20120916221334_add_conditions_to_permissions.rb +0 -5
  58. data/lib/ability.rb +0 -73
  59. data/spec/dummy/db/migrate/20120727145840_create_permissions_table.citygate.rb +0 -13
  60. data/spec/dummy/db/migrate/20120916223209_add_conditions_to_permissions.citygate.rb +0 -6
  61. data/spec/dummy/spec/lib/ability_spec.rb +0 -10
  62. data/spec/dummy/spec/models/permission_spec.rb +0 -13
@@ -1,24 +0,0 @@
1
- module Citygate
2
- # @author Zamith
3
- class Permission < ActiveRecord::Base
4
- attr_accessible :action, :subject_class, :subject_id, :role_id, :conditions
5
- belongs_to :role
6
-
7
- # Load all the permissions for all the roles
8
- # DB intensive, should run only once!
9
- def self.load_all
10
- permissions = {}
11
-
12
- # Get guest permissions
13
- permissions[:guest] = Citygate::Permission.find_all_by_role_id(nil)
14
-
15
- # Get everyother role permissions
16
- roles = Citygate::Role.select [:id, :name]
17
- roles.each do |role|
18
- permissions[role.name.underscore.to_sym] = Citygate::Permission.find_all_by_role_id(role.id)
19
- end
20
-
21
- return permissions
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- class CreatePermissionsTable < ActiveRecord::Migration
2
- def change
3
- create_table :citygate_permissions do |t|
4
- t.string :action, :null => false
5
- t.string :subject_class, :null => false
6
- t.string :subject_id
7
- t.integer :role_id
8
- end
9
-
10
- add_index :citygate_permissions, :role_id
11
- end
12
- end
@@ -1,5 +0,0 @@
1
- class AddConditionsToPermissions < ActiveRecord::Migration
2
- def change
3
- add_column :citygate_permissions, :conditions, :string
4
- end
5
- end
@@ -1,73 +0,0 @@
1
- # @author Zamith
2
- class Ability
3
- include CanCan::Ability
4
-
5
- # Defines the permissions for a user wich is not logged in or if it is,
6
- # calls the corresponding method to its role
7
- # @param [Citygate::User] user the current user
8
- def initialize(user)
9
- # This runs only once
10
- @@permissions ||= Citygate::Permission.load_all
11
-
12
- @user = user || Citygate::User.new # guest user (not logged in)
13
-
14
- @@permissions[:guest].each do |permission|
15
- handle_permission permission
16
- end
17
-
18
- if @user.role
19
- send(@user.role.name.downcase)
20
- end
21
- end
22
-
23
- # Defines the permissions on a user with the role of member
24
- def member
25
- @@permissions[:member].each do |permission|
26
- handle_permission permission
27
- end
28
- end
29
-
30
- # Defines the permissions on a user with the role of admin
31
- # As this is a super admin that can do anything, it does not need
32
- # to inherit from member
33
- def admin
34
- #member
35
- @@permissions[:admin].each do |permission|
36
- handle_permission permission
37
- end
38
- end
39
-
40
- protected
41
-
42
- def handle_permission(permission)
43
- if permission.subject_id.nil?
44
- begin
45
- can permission.action.to_sym, permission.subject_class.constantize, generate_conditions_hash(permission)
46
- rescue
47
- can permission.action.to_sym, permission.subject_class.to_sym, generate_conditions_hash(permission)
48
- end
49
- else
50
- begin
51
- can permission.action.to_sym, permission.subject_class.constantize, generate_conditions_hash(permission)
52
- rescue
53
- can permission.action.to_sym, permission.subject_class.to_sym, generate_conditions_hash(permission)
54
- end
55
- end
56
- end
57
-
58
- def generate_conditions_hash(permission)
59
- user = @user
60
- conditions_hash = {}
61
- if permission.conditions
62
- permission.conditions.split(",").each do |condition|
63
- key,value = condition.split("#")
64
- conditions_hash[key.to_sym] = instance_eval value
65
- end
66
-
67
- conditions_hash.merge({id: permission.subject_id}) if permission.subject_id
68
- end
69
-
70
- return conditions_hash
71
- end
72
-
73
- end
@@ -1,13 +0,0 @@
1
- # This migration comes from citygate (originally 20120727143920)
2
- class CreatePermissionsTable < ActiveRecord::Migration
3
- def change
4
- create_table :citygate_permissions do |t|
5
- t.string :action, :null => false
6
- t.string :subject_class, :null => false
7
- t.string :subject_id
8
- t.integer :role_id
9
- end
10
-
11
- add_index :citygate_permissions, :role_id
12
- end
13
- end
@@ -1,6 +0,0 @@
1
- # This migration comes from citygate (originally 20120916221334)
2
- class AddConditionsToPermissions < ActiveRecord::Migration
3
- def change
4
- add_column :citygate_permissions, :conditions, :string
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ability do
4
- context "initialization" do
5
- it "should cache the permissions loaded" do
6
- Ability.new Citygate::User.new
7
- Ability.class_variable_get(:@@permissions).should_not be_nil
8
- end
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Citygate::Permission do
4
- context "load all permissions" do
5
- it "should load the guest permissions" do
6
- Citygate::Permission.load_all.should have_key :guest
7
- end
8
-
9
- it "should load permissions for all the roles" do
10
- Citygate::Permission.load_all.size.should eq 3
11
- end
12
- end
13
- end