wheels 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/access_control_entries_controller.rb +15 -14
- data/app/controllers/pages_controller.rb +8 -1
- data/app/models/access_control_entry.rb +36 -27
- data/app/models/page.rb +1 -1
- data/app/models/role.rb +8 -0
- data/app/views/access_control_entries/_form.html.haml +20 -14
- data/app/views/access_control_entries/_index.html.haml +46 -0
- data/app/views/access_control_entries/_show.html.haml +12 -0
- data/app/views/access_control_entries/create.js.haml +3 -0
- data/app/views/access_control_entries/destroy.js.haml +3 -0
- data/app/views/access_control_entries/edit.js.haml +3 -0
- data/app/views/access_control_entries/index.html.haml +1 -28
- data/app/views/access_control_entries/index.js.haml +3 -0
- data/app/views/access_control_entries/new.js.haml +3 -0
- data/app/views/access_control_entries/show.html.haml +1 -21
- data/app/views/access_control_entries/show.js.haml +4 -0
- data/app/views/access_control_entries/update.js.haml +3 -0
- data/app/views/pages/_form.html.haml +4 -0
- data/app/views/pages/index.html.haml +9 -0
- data/app/views/pages/show.html.haml +2 -0
- data/public/stylesheets/sass/dreamy.sass +2 -0
- data/wheels.gemspec +11 -2
- metadata +13 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.22
|
@@ -1,19 +1,20 @@
|
|
1
1
|
class AccessControlEntriesController < InheritedResources::Base
|
2
|
-
|
3
|
-
|
2
|
+
ajax_loading
|
3
|
+
before_filter :authenticate_user!
|
4
|
+
belongs_to :user, :optional => true
|
5
|
+
has_scope :by_resource, :using => [:resource_class, :resource_id]
|
6
|
+
has_scope :by_role, :using=>[:role_id]
|
7
|
+
has_scope :by_class, :using=>[:class]
|
8
|
+
respond_to :html, :js
|
4
9
|
|
5
|
-
def
|
6
|
-
|
10
|
+
def new_ace
|
11
|
+
a = AccessControlEntry.new
|
12
|
+
a.user_id = params[:user_id]
|
13
|
+
a.role_id = params[:role_id]
|
14
|
+
a.resource_class_name = params[:resource_class]
|
15
|
+
a.options[:id] = params[:resource_id]
|
16
|
+
return a
|
7
17
|
end
|
8
|
-
|
9
|
-
private
|
10
|
-
def load_resource
|
11
|
-
if params[:id]
|
12
|
-
AccessControlEntry.find(params[:id])
|
13
|
-
else
|
14
|
-
raise "No resource id supplied" unless params[:class]
|
15
|
-
AccessControlEntry.find_by_resource_class_name_and_resource_id params[:class], params[:resource_id]
|
16
|
-
end
|
17
|
-
end
|
18
|
+
helper_method :new_ace
|
18
19
|
end
|
19
20
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
class PagesController < InheritedResources::Base
|
2
|
+
before_filter :resource, :only=>[:update, :show, :destroy, :edit]
|
3
|
+
authorize_resource
|
4
|
+
has_scope :tagged_with, :as => :tag
|
5
|
+
has_scope :accessible_by, :type=>:boolean, :default=>true do |c,s|
|
6
|
+
s.accessible_by(c.current_ability)
|
7
|
+
end
|
8
|
+
|
2
9
|
def resource
|
3
|
-
page_id = params[:id]
|
10
|
+
page_id = params[:id]
|
4
11
|
if page_id.is_numeric?
|
5
12
|
@page ||= Page.find(page_id)
|
6
13
|
else
|
@@ -6,52 +6,59 @@ class AccessControlEntry < ActiveRecord::Base
|
|
6
6
|
where(:resource_class_name=>resource_class_name).
|
7
7
|
where(:resource_id=>resource_id)
|
8
8
|
}
|
9
|
+
scope :by_role, lambda {|role_id|
|
10
|
+
where(:role_id=>role_id)
|
11
|
+
}
|
12
|
+
scope :by_class, lambda {|class_name|
|
13
|
+
where(:resource_class_name=>class_name)
|
14
|
+
}
|
9
15
|
|
10
16
|
def resource
|
11
|
-
@resource ||=
|
12
|
-
self.resource_class_name.constantize.find(self.resource_id))
|
17
|
+
@resource ||= self.resource_class_name.constantize
|
13
18
|
end
|
14
19
|
|
15
20
|
def resource=(res)
|
16
21
|
@resource = res
|
17
22
|
if res.type==Class
|
18
|
-
self.resource_id = nil
|
19
23
|
self.resource_class_name = res.name
|
20
24
|
else
|
21
|
-
self.
|
25
|
+
self.options[:id] = res.id
|
22
26
|
self.resource_class_name = res.class.name
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def options
|
27
|
-
@options ||= eval(self.serialized_options)
|
31
|
+
@options ||= (self.serialized_options ? eval(self.serialized_options) : {})
|
32
|
+
end
|
33
|
+
|
34
|
+
def options_str
|
35
|
+
options.map{|u,v| "#{u.inspect}=>#{v.is_numeric? ? v : v.inspect}"}.join(", ")
|
28
36
|
end
|
37
|
+
def options_str=(str)
|
38
|
+
opts = str.split(",").map(&:strip).map_hash{|keyval|
|
39
|
+
key, val = keyval.split("=>").map(&:strip)
|
40
|
+
val = val.to_i if val.is_numeric?
|
41
|
+
if key.index(":")
|
42
|
+
key = key.gsub(/\:/, "").to_sym
|
43
|
+
end
|
44
|
+
{key=>val}
|
45
|
+
}
|
29
46
|
|
30
|
-
def options=(opts)
|
31
|
-
raise "I only take hash" unless opts.class==Hash
|
32
|
-
klasses = %w(String Symbol)
|
33
|
-
opts.delete_if{|u,v| !klasses.include?(u.class.name) || !klasses.include?(v.class.name)}
|
34
47
|
@options = opts
|
35
48
|
self.serialized_options = opts.inspect
|
36
49
|
end
|
37
50
|
|
38
51
|
def configure(ability)
|
39
|
-
|
52
|
+
raise "I only like Ability" unless ability.class==Ability
|
53
|
+
ability.send method_name, verb.to_sym, resource, options
|
54
|
+
puts "ability.send #{method_name}, #{verb.to_sym.inspect}, #{resource.inspect}, #{options.inspect}"
|
40
55
|
end
|
41
56
|
|
42
57
|
def self.can(verb, resource, options={})
|
43
|
-
AccessControlEntry.new(true, verb, resource, options )
|
58
|
+
AccessControlEntry.new(:can=>true, :verb=> verb, :resource=>resource, :options=>options )
|
44
59
|
end
|
45
60
|
def self.cannot(verb, resource, options)
|
46
|
-
AccessControlEntry.new(false, verb, resource, options )
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(can, verb, resource, options={})
|
50
|
-
@options = options
|
51
|
-
self.can = can
|
52
|
-
self.verb = verb
|
53
|
-
self.resource = resource
|
54
|
-
self.options = options
|
61
|
+
AccessControlEntry.new(:can=>false, :verb=> verb, :resource=>resource, :options=>options )
|
55
62
|
end
|
56
63
|
|
57
64
|
def method_name
|
@@ -66,14 +73,16 @@ class AccessControlEntry < ActiveRecord::Base
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def role=(role)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
role = role.to_s.camelize
|
73
|
-
if role.is_numeric?
|
74
|
-
self.role_id= role
|
76
|
+
unless role.empty?
|
77
|
+
if role.kind_of? Role
|
78
|
+
self.role_id = role.id
|
75
79
|
else
|
76
|
-
|
80
|
+
role = role.to_s.camelize
|
81
|
+
if role.is_numeric?
|
82
|
+
self.role_id= role
|
83
|
+
else
|
84
|
+
self.role_id= Role.find_by_name(role).id
|
85
|
+
end
|
77
86
|
end
|
78
87
|
end
|
79
88
|
end
|
data/app/models/page.rb
CHANGED
data/app/models/role.rb
CHANGED
@@ -2,6 +2,14 @@ class Role < ActiveRecord::Base
|
|
2
2
|
has_many :users
|
3
3
|
has_many :access_control_entries
|
4
4
|
|
5
|
+
def self.collection_entries
|
6
|
+
roles = [["Not Set", nil]]
|
7
|
+
Role.all.map{|t| [t.name, t.id]}.each do |t|
|
8
|
+
roles << t
|
9
|
+
end
|
10
|
+
roles
|
11
|
+
end
|
12
|
+
|
5
13
|
SUPER = 1
|
6
14
|
ADMIN = 2
|
7
15
|
USER = 3
|
@@ -1,27 +1,33 @@
|
|
1
|
-
= form_for @access_control_entry do |f|
|
1
|
+
= form_for @access_control_entry, :remote=>true do |f|
|
2
2
|
-if @access_control_entry.errors.any?
|
3
3
|
#errorExplanation
|
4
4
|
%h2= "#{pluralize(@access_control_entry.errors.count, "error")} prohibited this access_control_entry from being saved:"
|
5
5
|
%ul
|
6
6
|
- @access_control_entry.errors.full_messages.each do |msg|
|
7
7
|
%li= msg
|
8
|
-
|
8
|
+
= hidden_field_tag :container, "ace_listing"
|
9
|
+
= hidden_field_tag :ajax_function, "append"
|
10
|
+
%ul.ace_form_fields
|
9
11
|
%li
|
10
|
-
|
11
|
-
= f.
|
12
|
-
= f.hidden_field :resource_id
|
12
|
+
.name Email
|
13
|
+
= f.text_field :user_email, :class=>"email"
|
13
14
|
%li
|
14
|
-
|
15
|
-
= f.
|
15
|
+
.name Role
|
16
|
+
= f.select :role, Role.collection_entries
|
16
17
|
%li
|
17
|
-
|
18
|
-
= f.select :role, ["Admin", "User", "Nobody"]
|
19
|
-
%li
|
20
|
-
= f.label :can
|
18
|
+
.name Can?
|
21
19
|
= f.check_box :can
|
22
20
|
%li
|
23
|
-
|
24
|
-
= f.text_field :verb
|
21
|
+
.name verb
|
22
|
+
= f.text_field :verb, :class=>"verb"
|
23
|
+
%li
|
24
|
+
.name Resource
|
25
|
+
= f.select :resource_class_name, [["Forum", "Forum"], ["Page", "Page"]]
|
26
|
+
= f.hidden_field :resource_id
|
27
|
+
%li
|
28
|
+
.name options
|
29
|
+
= f.text_field :options_str, :class=>"verb"
|
30
|
+
|
25
31
|
%li
|
26
|
-
= f.submit 'Save'
|
32
|
+
= f.submit 'Save', :disable_with=>"Saving..."
|
27
33
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
%h1 Listing Access Control Entries for
|
2
|
+
|
3
|
+
%ul.listing#ace_listing
|
4
|
+
- @access_control_entries.each do |ace|
|
5
|
+
%li
|
6
|
+
%ul.ace{:id=>ace.element_id}
|
7
|
+
%li= ace.user.email if ace.user
|
8
|
+
%li= ace.role.name if ace.role
|
9
|
+
%li= ace.can ? "Can" : "Cannot"
|
10
|
+
%li= ace.verb
|
11
|
+
%li= ace.resource_class_name
|
12
|
+
%li= ace.options_str if ace.options_str
|
13
|
+
- if can? :edit, ace
|
14
|
+
%li= link_to "Edit", edit_access_control_entry_path(ace), :remote=>true
|
15
|
+
- if can? :destroy, ace
|
16
|
+
%li= link_to "X", ace, :method=>:delete, :remote=>true, "data-confirm"=>"Are you sure?"
|
17
|
+
|
18
|
+
- if can? :create, AccessControlEntry
|
19
|
+
%h2 Enter a new Access Control Entry
|
20
|
+
= form_for new_ace, :remote=>true do |f|
|
21
|
+
= hidden_field_tag :container, "ace_listing"
|
22
|
+
= hidden_field_tag :ajax_function, "append"
|
23
|
+
%ul.ace_form_fields
|
24
|
+
%li
|
25
|
+
.name Email
|
26
|
+
= f.text_field :user_email, :class=>"email"
|
27
|
+
%li
|
28
|
+
.name Role
|
29
|
+
= f.select :role, Role.collection_entries
|
30
|
+
%li
|
31
|
+
.name Can?
|
32
|
+
= f.check_box :can
|
33
|
+
%li
|
34
|
+
.name verb
|
35
|
+
= f.text_field :verb, :class=>"verb"
|
36
|
+
%li
|
37
|
+
.name Resource
|
38
|
+
= f.select :resource_class_name, [["Forum", "Forum"], ["Page", "Page"]]
|
39
|
+
= f.hidden_field :resource_id
|
40
|
+
%li
|
41
|
+
.name options
|
42
|
+
= f.text_field :options_str, :class=>"verb"
|
43
|
+
|
44
|
+
%li
|
45
|
+
= f.submit 'Save', :disable_with=>"Saving..."
|
46
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%ul.ace{:id=>resource.element_id}
|
2
|
+
%li= resource.user.email if resource.user
|
3
|
+
%li= resource.role.name if resource.role
|
4
|
+
%li= resource.can ? "Can" : "Cannot"
|
5
|
+
%li= resource.verb
|
6
|
+
%li= resource.resource_class_name
|
7
|
+
%li= resource.options_str if resource.options_str
|
8
|
+
- if can? :edit, resource
|
9
|
+
%li= link_to "Edit", edit_access_control_entry_path(resource), :remote=>true
|
10
|
+
- if can? :destroy, resource
|
11
|
+
%li= link_to "X", resource, :method=>:delete, :remote=>true, "data-confirm"=>"Are you sure?"
|
12
|
+
|
@@ -1,29 +1,2 @@
|
|
1
|
-
|
1
|
+
= render :partial => "index"
|
2
2
|
|
3
|
-
%table
|
4
|
-
%tr
|
5
|
-
%th Resource class name
|
6
|
-
%th Resource
|
7
|
-
%th User
|
8
|
-
%th Role
|
9
|
-
%th Can
|
10
|
-
%th Verb
|
11
|
-
%th
|
12
|
-
%th
|
13
|
-
%th
|
14
|
-
|
15
|
-
- @access_control_entries.each do |access_control_entry|
|
16
|
-
%tr
|
17
|
-
%td= access_control_entry.resource_class_name
|
18
|
-
%td= access_control_entry.resource_id
|
19
|
-
%td= access_control_entry.user_id
|
20
|
-
%td= access_control_entry.role_id
|
21
|
-
%td= access_control_entry.can
|
22
|
-
%td= access_control_entry.verb
|
23
|
-
%td= link_to 'Show', access_control_entry
|
24
|
-
%td= link_to 'Edit', edit_access_control_entry_path(access_control_entry)
|
25
|
-
%td= link_to 'Destroy', access_control_entry, :confirm => 'Are you sure?', :method => :delete
|
26
|
-
|
27
|
-
%br
|
28
|
-
|
29
|
-
= link_to 'New access_control_entry', new_access_control_entry_path
|
@@ -1,22 +1,2 @@
|
|
1
|
-
|
2
|
-
%b Resource class name:
|
3
|
-
= @access_control_entry.resource_class_name
|
4
|
-
%p
|
5
|
-
%b Resource:
|
6
|
-
= @access_control_entry.resource_id
|
7
|
-
%p
|
8
|
-
%b User:
|
9
|
-
= @access_control_entry.user_id
|
10
|
-
%p
|
11
|
-
%b Role:
|
12
|
-
= @access_control_entry.role_id
|
13
|
-
%p
|
14
|
-
%b Can:
|
15
|
-
= @access_control_entry.can
|
16
|
-
%p
|
17
|
-
%b Verb:
|
18
|
-
= @access_control_entry.verb
|
1
|
+
= render :partial => "show"
|
19
2
|
|
20
|
-
= link_to 'Edit', edit_access_control_entry_path(@access_control_entry)
|
21
|
-
\|
|
22
|
-
= link_to 'Back', access_control_entries_path
|
@@ -1,5 +1,14 @@
|
|
1
1
|
= link_to 'New page', new_page_path if can? :create, Page
|
2
2
|
|
3
|
+
= content_for :links do
|
4
|
+
- @pages.each do |page|
|
5
|
+
%li
|
6
|
+
= link_to page.title, page
|
7
|
+
- if can? :edit, @page
|
8
|
+
= link_to '| Edit', edit_page_path(page)
|
9
|
+
- if can? :manage, @page
|
10
|
+
= link_to '| Access Ctrl', access_control_entries_path(:resource_class=>"Page", :resource_id=>page.id)
|
11
|
+
|
3
12
|
- @pages.each do |page|
|
4
13
|
%h1= link_to page.title, page
|
5
14
|
= link_to "Edit", edit_page_path(page) if can? :edit, page
|
data/wheels.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wheels}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.22"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tyler Gannon"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-17}
|
13
13
|
s.description = %q{Call rails generate wheels.}
|
14
14
|
s.email = %q{tgannon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -50,10 +50,19 @@ Gem::Specification.new do |s|
|
|
50
50
|
"app/models/tagging.rb",
|
51
51
|
"app/models/user.rb",
|
52
52
|
"app/views/access_control_entries/_form.html.haml",
|
53
|
+
"app/views/access_control_entries/_index.html.haml",
|
54
|
+
"app/views/access_control_entries/_show.html.haml",
|
55
|
+
"app/views/access_control_entries/create.js.haml",
|
56
|
+
"app/views/access_control_entries/destroy.js.haml",
|
53
57
|
"app/views/access_control_entries/edit.html.haml",
|
58
|
+
"app/views/access_control_entries/edit.js.haml",
|
54
59
|
"app/views/access_control_entries/index.html.haml",
|
60
|
+
"app/views/access_control_entries/index.js.haml",
|
55
61
|
"app/views/access_control_entries/new.html.haml",
|
62
|
+
"app/views/access_control_entries/new.js.haml",
|
56
63
|
"app/views/access_control_entries/show.html.haml",
|
64
|
+
"app/views/access_control_entries/show.js.haml",
|
65
|
+
"app/views/access_control_entries/update.js.haml",
|
57
66
|
"app/views/blogs/_form.html.haml",
|
58
67
|
"app/views/blogs/edit.html.haml",
|
59
68
|
"app/views/blogs/index.html.haml",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wheels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 22
|
10
|
+
version: 0.0.22
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyler Gannon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-17 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -75,10 +75,19 @@ files:
|
|
75
75
|
- app/models/tagging.rb
|
76
76
|
- app/models/user.rb
|
77
77
|
- app/views/access_control_entries/_form.html.haml
|
78
|
+
- app/views/access_control_entries/_index.html.haml
|
79
|
+
- app/views/access_control_entries/_show.html.haml
|
80
|
+
- app/views/access_control_entries/create.js.haml
|
81
|
+
- app/views/access_control_entries/destroy.js.haml
|
78
82
|
- app/views/access_control_entries/edit.html.haml
|
83
|
+
- app/views/access_control_entries/edit.js.haml
|
79
84
|
- app/views/access_control_entries/index.html.haml
|
85
|
+
- app/views/access_control_entries/index.js.haml
|
80
86
|
- app/views/access_control_entries/new.html.haml
|
87
|
+
- app/views/access_control_entries/new.js.haml
|
81
88
|
- app/views/access_control_entries/show.html.haml
|
89
|
+
- app/views/access_control_entries/show.js.haml
|
90
|
+
- app/views/access_control_entries/update.js.haml
|
82
91
|
- app/views/blogs/_form.html.haml
|
83
92
|
- app/views/blogs/edit.html.haml
|
84
93
|
- app/views/blogs/index.html.haml
|