auth-assistant 0.4.0
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.
- data/.DS_Store +0 -0
- data/.document +5 -0
- data/.gitignore +39 -0
- data/Changelog.txt +30 -0
- data/LICENSE +20 -0
- data/README.markdown +308 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/auth_assist/menu/_admin_login_items.html.erb +11 -0
- data/app/views/auth_assist/menu/_login_items.html.erb +11 -0
- data/app/views/auth_assist/menu/_registration_items.html.erb +10 -0
- data/auth-assistant.gemspec +115 -0
- data/config/locales/en.yml +14 -0
- data/init.rb +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/auth-assistant.rb +24 -0
- data/lib/auth_assistant/configure.rb +16 -0
- data/lib/auth_assistant/helpers/admin_role.rb +59 -0
- data/lib/auth_assistant/helpers/all.rb +4 -0
- data/lib/auth_assistant/helpers/localhost.rb +22 -0
- data/lib/auth_assistant/helpers/roles.rb +52 -0
- data/lib/auth_assistant/helpers/user_role.rb +47 -0
- data/lib/auth_assistant/model/user_config.rb +42 -0
- data/lib/auth_assistant/role_strategies/admin_field.rb +37 -0
- data/lib/auth_assistant/role_strategies/all.rb +7 -0
- data/lib/auth_assistant/role_strategies/multi_role_assignment.rb +34 -0
- data/lib/auth_assistant/role_strategies/role_assignment.rb +41 -0
- data/lib/auth_assistant/role_strategies/role_field.rb +32 -0
- data/lib/auth_assistant/role_strategies/roles_field.rb +31 -0
- data/lib/auth_assistant/role_strategies/roles_mask.rb +35 -0
- data/lib/auth_assistant/role_strategies/shared.rb +25 -0
- data/lib/auth_assistant/translate/authlabels.rb +23 -0
- data/lib/auth_assistant/view/all.rb +4 -0
- data/lib/auth_assistant/view/auth_menu_item.rb +27 -0
- data/lib/auth_assistant/view/registration_link.rb +30 -0
- data/lib/auth_assistant/view/rest_link.rb +70 -0
- data/lib/auth_assistant/view/session_link.rb +31 -0
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/auth_assist/.DS_Store +0 -0
- data/lib/generators/auth_assist/clear/clear_generator.rb +30 -0
- data/lib/generators/auth_assist/config/.DS_Store +0 -0
- data/lib/generators/auth_assist/config/config_generator.rb +72 -0
- data/lib/generators/auth_assist/templates/ability.rb +22 -0
- data/lib/generators/auth_assist/templates/auth_assistant.rb +6 -0
- data/lib/generators/auth_assist/templates/permits.rb +91 -0
- data/lib/generators/auth_assist/templates/remove_multi_role_assignments_migration.rb +24 -0
- data/lib/generators/auth_assist/templates/remove_role_assignments_migration.rb +17 -0
- data/lib/generators/auth_assist/templates/role_assignments_migration.rb +14 -0
- data/lib/generators/auth_assist/templates/roles_migration.rb +13 -0
- data/lib/generators/auth_assist/test.rb +40 -0
- data/lib/generators/auth_assist/views/views_generator.rb +66 -0
- data/lib/generators/auth_code_refactor.rb +71 -0
- data/lib/generators/migration_helper.rb +81 -0
- data/lib/generators/reverse_migrations.rb +48 -0
- data/lib/generators/role_migrations.rb +167 -0
- data/lib/permits.rb +92 -0
- data/spec/auth-assistant_spec.rb +7 -0
- data/spec/generators/ability_gen_spec.rb +9 -0
- data/spec/sandbox.rb +9 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +167 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{auth-assistant}
|
8
|
+
s.version = "0.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-05-18}
|
13
|
+
s.description = %q{Provides assistance for setting up an auth solution using devise and cancan auth frameworks}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".DS_Store",
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"Changelog.txt",
|
24
|
+
"LICENSE",
|
25
|
+
"README.markdown",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"app/.DS_Store",
|
29
|
+
"app/views/.DS_Store",
|
30
|
+
"app/views/auth_assist/menu/_admin_login_items.html.erb",
|
31
|
+
"app/views/auth_assist/menu/_login_items.html.erb",
|
32
|
+
"app/views/auth_assist/menu/_registration_items.html.erb",
|
33
|
+
"auth-assistant.gemspec",
|
34
|
+
"config/locales/en.yml",
|
35
|
+
"init.rb",
|
36
|
+
"lib/.DS_Store",
|
37
|
+
"lib/auth-assistant.rb",
|
38
|
+
"lib/auth_assistant/configure.rb",
|
39
|
+
"lib/auth_assistant/helpers/admin_role.rb",
|
40
|
+
"lib/auth_assistant/helpers/all.rb",
|
41
|
+
"lib/auth_assistant/helpers/localhost.rb",
|
42
|
+
"lib/auth_assistant/helpers/roles.rb",
|
43
|
+
"lib/auth_assistant/helpers/user_role.rb",
|
44
|
+
"lib/auth_assistant/model/user_config.rb",
|
45
|
+
"lib/auth_assistant/role_strategies/admin_field.rb",
|
46
|
+
"lib/auth_assistant/role_strategies/all.rb",
|
47
|
+
"lib/auth_assistant/role_strategies/multi_role_assignment.rb",
|
48
|
+
"lib/auth_assistant/role_strategies/role_assignment.rb",
|
49
|
+
"lib/auth_assistant/role_strategies/role_field.rb",
|
50
|
+
"lib/auth_assistant/role_strategies/roles_field.rb",
|
51
|
+
"lib/auth_assistant/role_strategies/roles_mask.rb",
|
52
|
+
"lib/auth_assistant/role_strategies/shared.rb",
|
53
|
+
"lib/auth_assistant/translate/authlabels.rb",
|
54
|
+
"lib/auth_assistant/view/all.rb",
|
55
|
+
"lib/auth_assistant/view/auth_menu_item.rb",
|
56
|
+
"lib/auth_assistant/view/registration_link.rb",
|
57
|
+
"lib/auth_assistant/view/rest_link.rb",
|
58
|
+
"lib/auth_assistant/view/session_link.rb",
|
59
|
+
"lib/generators/.DS_Store",
|
60
|
+
"lib/generators/auth_assist/.DS_Store",
|
61
|
+
"lib/generators/auth_assist/clear/clear_generator.rb",
|
62
|
+
"lib/generators/auth_assist/config/.DS_Store",
|
63
|
+
"lib/generators/auth_assist/config/config_generator.rb",
|
64
|
+
"lib/generators/auth_assist/templates/ability.rb",
|
65
|
+
"lib/generators/auth_assist/templates/auth_assistant.rb",
|
66
|
+
"lib/generators/auth_assist/templates/permits.rb",
|
67
|
+
"lib/generators/auth_assist/templates/remove_multi_role_assignments_migration.rb",
|
68
|
+
"lib/generators/auth_assist/templates/remove_role_assignments_migration.rb",
|
69
|
+
"lib/generators/auth_assist/templates/role_assignments_migration.rb",
|
70
|
+
"lib/generators/auth_assist/templates/roles_migration.rb",
|
71
|
+
"lib/generators/auth_assist/test.rb",
|
72
|
+
"lib/generators/auth_assist/views/views_generator.rb",
|
73
|
+
"lib/generators/auth_code_refactor.rb",
|
74
|
+
"lib/generators/migration_helper.rb",
|
75
|
+
"lib/generators/reverse_migrations.rb",
|
76
|
+
"lib/generators/role_migrations.rb",
|
77
|
+
"lib/permits.rb",
|
78
|
+
"spec/auth-assistant_spec.rb",
|
79
|
+
"spec/generators/ability_gen_spec.rb",
|
80
|
+
"spec/sandbox.rb",
|
81
|
+
"spec/spec.opts",
|
82
|
+
"spec/spec_helper.rb"
|
83
|
+
]
|
84
|
+
s.homepage = %q{http://github.com/kristianmandrup/devise-assistant}
|
85
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
86
|
+
s.require_paths = ["lib"]
|
87
|
+
s.rubygems_version = %q{1.3.6}
|
88
|
+
s.summary = %q{Provides assistance for setting up an auth solution}
|
89
|
+
s.test_files = [
|
90
|
+
"spec/auth-assistant_spec.rb",
|
91
|
+
"spec/generators/ability_gen_spec.rb",
|
92
|
+
"spec/sandbox.rb",
|
93
|
+
"spec/spec_helper.rb"
|
94
|
+
]
|
95
|
+
|
96
|
+
if s.respond_to? :specification_version then
|
97
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
98
|
+
s.specification_version = 3
|
99
|
+
|
100
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
101
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
102
|
+
s.add_runtime_dependency(%q<devise>, [">= 1.0"])
|
103
|
+
s.add_runtime_dependency(%q<cancan>, [">= 1.0"])
|
104
|
+
else
|
105
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
106
|
+
s.add_dependency(%q<devise>, [">= 1.0"])
|
107
|
+
s.add_dependency(%q<cancan>, [">= 1.0"])
|
108
|
+
end
|
109
|
+
else
|
110
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
111
|
+
s.add_dependency(%q<devise>, [">= 1.0"])
|
112
|
+
s.add_dependency(%q<cancan>, [">= 1.0"])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'auth-assistant'
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'auth_assistant/configure'
|
2
|
+
|
3
|
+
module ApplicationHelper
|
4
|
+
def self.auth_assist_helpers
|
5
|
+
include AuthAssistant::ViewHelpers
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ApplicationController
|
10
|
+
private
|
11
|
+
def current_ability
|
12
|
+
@current_ability ||= Ability.new(current_user, request)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
module AuthAssistant
|
18
|
+
module ViewHelpers
|
19
|
+
include AuthAssistant::ViewHelpers::SessionLink
|
20
|
+
include AuthAssistant::ViewHelpers::RegistrationLink
|
21
|
+
include AuthAssistant::ViewHelpers::RestLink
|
22
|
+
include AuthAssistant::ViewHelpers::AuthMenuItem
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'auth_assistant/helpers/all'
|
2
|
+
require 'auth_assistant/model/user_config'
|
3
|
+
require 'auth_assistant/translate/authlabels'
|
4
|
+
require 'auth_assistant/view/all'
|
5
|
+
|
6
|
+
if defined? ActionController
|
7
|
+
ActionController::Base.class_eval do
|
8
|
+
include AuthAssistant::Helpers::AdminRole
|
9
|
+
include AuthAssistant::Helpers::UserRole
|
10
|
+
include AuthAssistant::Helpers::Roles
|
11
|
+
include AuthAssistant::Helpers::LocalHost
|
12
|
+
include AuthAssistant::Helpers::AuthLabel
|
13
|
+
end
|
14
|
+
else
|
15
|
+
puts "ActionController not defined"
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module AuthAssistant
|
2
|
+
module Helpers
|
3
|
+
module AdminRole
|
4
|
+
def admin_block(&block)
|
5
|
+
with_output_buffer(&block) if admin?
|
6
|
+
end
|
7
|
+
|
8
|
+
def not_admin_block(&block)
|
9
|
+
with_output_buffer(&block) if !admin?
|
10
|
+
end
|
11
|
+
|
12
|
+
def admin_or_owner_block(obj, &block)
|
13
|
+
if admin? || owner?(obj)
|
14
|
+
with_output_buffer(&block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def admin?
|
19
|
+
devise_admin?(on) || cancan_admin?(on)
|
20
|
+
end
|
21
|
+
|
22
|
+
def admin_area(&block)
|
23
|
+
admin_block do
|
24
|
+
do_admin_area(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def not_admin_area(&block)
|
29
|
+
not_admin_block do
|
30
|
+
do_admin_area(&block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.included(base)
|
35
|
+
base.helper_method :admin_block, :not_admin_block, :admin_area, :not_admin_area, :admin_or_owner_block, :admin?
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def do_admin_area(&block)
|
40
|
+
content = with_output_buffer(&block)
|
41
|
+
content_tag :div, content, :class => 'admin'
|
42
|
+
end
|
43
|
+
|
44
|
+
def owner?(obj)
|
45
|
+
current_user == obj.user if obj.repond_to? :user
|
46
|
+
current_user == obj.owner if obj.repond_to? :owner
|
47
|
+
end
|
48
|
+
|
49
|
+
def devise_admin?
|
50
|
+
admin_signed_in? if respond_to? :admin_signed_in?
|
51
|
+
end
|
52
|
+
|
53
|
+
def cancan_admin?
|
54
|
+
current_user.admin?
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AuthAssistant
|
2
|
+
module Helpers
|
3
|
+
module LocalHost
|
4
|
+
def localhost_block(&block)
|
5
|
+
with_output_buffer(&block) if localhost?
|
6
|
+
end
|
7
|
+
|
8
|
+
def not_localhost_block(&block)
|
9
|
+
with_output_buffer(&block) if !localhost?
|
10
|
+
end
|
11
|
+
|
12
|
+
def localhost?
|
13
|
+
['localhost', '127.0.0.1'].include?(request.host)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.helper_method :localhost_block, :not_localhost_block, :localhost?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module AuthAssistant
|
2
|
+
module Helpers
|
3
|
+
module Roles
|
4
|
+
def roles_area(*user_roles, options, &block)
|
5
|
+
options ||= {}
|
6
|
+
roles_block user_roles do
|
7
|
+
clazz = options[:class] || 'special'
|
8
|
+
do_roles_area(clazz, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def not_roles_area(*user_roles, options, &block)
|
13
|
+
options ||= {}
|
14
|
+
not_roles_block user_roles do
|
15
|
+
clazz = options[:class] || 'special'
|
16
|
+
do_roles_area(clazz, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def roles_block(*user_roles, &block)
|
21
|
+
with_output_buffer(&block) if role?(user_roles)
|
22
|
+
end
|
23
|
+
|
24
|
+
def not_roles_block(*user_roles, &block)
|
25
|
+
with_output_buffer(&block) if !role?(user_roles)
|
26
|
+
end
|
27
|
+
|
28
|
+
def role?(*user_roles)
|
29
|
+
devise_role?(user_roles) || cancan_role?(user_roles)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.helper_method :roles_block, :not_roles_block, :roles_area, :not_roles_area, :role?
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def do_roles_area(clazz, &block)
|
38
|
+
content = with_output_buffer(&block)
|
39
|
+
content_tag :div, content, :class => clazz
|
40
|
+
end
|
41
|
+
|
42
|
+
def devise_role?(user_roles)
|
43
|
+
user_roles.flatten.any?{|role| warden.authenticate?(:scope => role.to_sym)}
|
44
|
+
end
|
45
|
+
|
46
|
+
def cancan_role?(user_roles)
|
47
|
+
union = current_user.roles & user_roles
|
48
|
+
!union.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AuthAssistant
|
2
|
+
module Helpers
|
3
|
+
module UserRole
|
4
|
+
def user_area(&block)
|
5
|
+
user_block do
|
6
|
+
do_user_area(&block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def not_user_area(&block)
|
11
|
+
not_user_block do
|
12
|
+
do_user_area(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_block(&block)
|
17
|
+
with_output_buffer(&block) if user?
|
18
|
+
end
|
19
|
+
|
20
|
+
def not_user_block(&block)
|
21
|
+
with_output_buffer(&block) if !user?
|
22
|
+
end
|
23
|
+
|
24
|
+
def user?
|
25
|
+
devise_user? || cancan_user?
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.included(base)
|
29
|
+
base.helper_method :user_block, :not_user_block, :user_area, :not_user_area, :user?
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def do_user_area(&block)
|
34
|
+
content = with_output_buffer(&block)
|
35
|
+
content_tag :div, content, :class => 'user'
|
36
|
+
end
|
37
|
+
|
38
|
+
def devise_user?
|
39
|
+
user_signed_in? if respond_to? :user_signed_in?
|
40
|
+
end
|
41
|
+
|
42
|
+
def cancan_user?
|
43
|
+
!current_user.admin?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'auth_assistant/role_strategies/all'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module AuthAssistant
|
5
|
+
def self.configure(&block)
|
6
|
+
block.arity < 1 ? AuthAssistant::Configuration.instance.class_eval(&block) : block.call(AuthAssistant::Configuration.instance)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Configuration
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
attr_accessor :role_strategy
|
13
|
+
attr_accessor :available_roles
|
14
|
+
|
15
|
+
|
16
|
+
def available_strategies
|
17
|
+
[:admin_field, :role_field, :roles_field, :roles_mask, :role_assignment, :multi_role_assignment]
|
18
|
+
end
|
19
|
+
|
20
|
+
def strategy(name)
|
21
|
+
n = name.to_s
|
22
|
+
available_strategies.include?(n.to_sym) ? n.to_sym : :roles_field
|
23
|
+
end
|
24
|
+
|
25
|
+
def role_strategy=(strategy_name)
|
26
|
+
# puts "Applying role strategy: #{strategy_name}"
|
27
|
+
|
28
|
+
if !available_strategies.include? strategy_name.to_sym
|
29
|
+
raise UnknownStrategy, "unknown strategy: #{strategy_name.inspect}, must be one of: #{available_strategies.inspect}"
|
30
|
+
end
|
31
|
+
@role_strategy = strategy(strategy_name)
|
32
|
+
camel = @role_strategy.to_s.camelize
|
33
|
+
User.class_eval do
|
34
|
+
include AuthAssistant::RoleStrategy::Shared
|
35
|
+
include "AuthAssistant::RoleStrategy::#{camel}".constantize
|
36
|
+
set_scope if respond_to? :set_scope
|
37
|
+
set_relationships if respond_to? :set_relationships
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AuthAssistant
|
2
|
+
module RoleStrategy
|
3
|
+
module AdminField
|
4
|
+
|
5
|
+
def roles=(*roles)
|
6
|
+
new_role = roles.first.to_s
|
7
|
+
self.admin = new_role == 'admin'
|
8
|
+
end
|
9
|
+
|
10
|
+
def roles
|
11
|
+
[role]
|
12
|
+
end
|
13
|
+
|
14
|
+
def role=(role)
|
15
|
+
self.roles = [role]
|
16
|
+
end
|
17
|
+
|
18
|
+
def role
|
19
|
+
admin == true ? 'admin' : 'default'
|
20
|
+
end
|
21
|
+
|
22
|
+
def role?(_role)
|
23
|
+
role == _role.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def set_scope
|
28
|
+
scope :with_role, lambda { |role| {:conditions => ["role == ?", role]} }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.extend(ClassMethods)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|