citygate 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -3
- data/app/assets/javascripts/citygate/home.js.coffee.erb +6 -5
- data/app/controllers/citygate/application_controller.rb +1 -0
- data/app/controllers/citygate/users_controller.rb +2 -0
- data/app/models/citygate/role.rb +4 -0
- data/app/models/citygate/user.rb +24 -1
- data/config/locales/views/admin/actions/en.yml +4 -0
- data/db/seeds.rb +0 -14
- data/lib/ability/USAGE +8 -0
- data/lib/ability/ability_generator.rb +3 -0
- data/lib/ability/templates/ability.rb +25 -0
- data/lib/citygate/engine.rb +8 -1
- data/lib/citygate/version.rb +1 -1
- data/lib/generators/ability/USAGE +8 -0
- data/lib/generators/ability/ability_generator.rb +7 -0
- data/lib/generators/ability/templates/ability.rb +25 -0
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20120706095546_devise_create_users.citygate.rb → 20121010234716_devise_create_users.citygate.rb} +0 -0
- data/spec/dummy/db/migrate/{20120706095547_add_name_to_users.citygate.rb → 20121010234717_add_name_to_users.citygate.rb} +0 -0
- data/spec/dummy/db/migrate/{20120706095548_add_confirmable_to_users.citygate.rb → 20121010234718_add_confirmable_to_users.citygate.rb} +0 -0
- data/spec/dummy/db/migrate/{20120706095549_devise_invitable_add_to_users.citygate.rb → 20121010234719_devise_invitable_add_to_users.citygate.rb} +0 -0
- data/spec/dummy/db/migrate/{20120706095550_add_omniauth_to_devise.citygate.rb → 20121010234720_add_omniauth_to_devise.citygate.rb} +0 -0
- data/spec/dummy/db/migrate/{20120706095551_create_roles.citygate.rb → 20121010234721_create_roles.citygate.rb} +0 -0
- data/spec/dummy/db/schema.rb +1 -11
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/features/step_definitions/user_steps.rb +7 -0
- data/spec/dummy/features/support/paths.rb +3 -0
- data/spec/dummy/features/users/user_edit.feature +2 -0
- data/spec/dummy/features/users/users_admin.feature +1 -1
- data/spec/dummy/lib/ability.rb +25 -0
- data/spec/dummy/log/development.log +2692 -0
- data/spec/dummy/log/test.log +23012 -0
- data/spec/dummy/spec/models/role_spec.rb +13 -0
- data/spec/dummy/spec/models/user_spec.rb +47 -0
- data/spec/dummy/tmp/cache/assets/C72/B10/sprockets%2F21a4b8118f1f4254bf815e306027b951 +0 -0
- data/spec/dummy/tmp/cache/assets/C7A/CE0/sprockets%2F9124c83a02e7332a90b2883b69f81d04 +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CE3/150/sprockets%2F7d7a09e1df5c7510266a8d752683c4b3 +0 -0
- data/spec/dummy/tmp/cache/assets/D0D/DE0/sprockets%2Fa35442f02b0b2479f22d83d639d8c4fd +0 -0
- data/spec/dummy/tmp/cache/assets/D11/620/sprockets%2Ff9ea58224378018a71daac5437676adc +0 -0
- data/spec/dummy/tmp/cache/assets/D14/F80/sprockets%2F88a8b65bba21cb666758df2ff9300272 +0 -0
- data/spec/dummy/tmp/cache/assets/D1C/110/sprockets%2Ff7118b71a9f4d6d8bf76e874be631322 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D8F/400/sprockets%2F1aeaa1227411ad4c4ee0a489f5dbc668 +0 -0
- data/spec/dummy/tmp/cache/assets/D99/BF0/sprockets%2F2fd8d582e234f8d0a741c1b4cafb716e +0 -0
- data/spec/dummy/tmp/cache/assets/D9E/F10/sprockets%2F9ab223df888d724dcad09eb1163cc5f4 +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- metadata +312 -198
- data/app/assets/javascripts/citygate/admin_users.coffee +0 -2
- data/app/assets/javascripts/citygate/jquery.pjax.js +0 -690
- data/app/models/citygate/permission.rb +0 -24
- data/db/migrate/20120727143920_create_permissions_table.rb +0 -12
- data/db/migrate/20120916221334_add_conditions_to_permissions.rb +0 -5
- data/lib/ability.rb +0 -73
- data/spec/dummy/db/migrate/20120727145840_create_permissions_table.citygate.rb +0 -13
- data/spec/dummy/db/migrate/20120916223209_add_conditions_to_permissions.citygate.rb +0 -6
- data/spec/dummy/spec/lib/ability_spec.rb +0 -10
- 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
|
data/lib/ability.rb
DELETED
@@ -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,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
|