wheels 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/pages_controller.rb +32 -34
- data/app/controllers/users_controller.rb +14 -4
- data/app/models/access_control_entry.rb +3 -3
- data/app/models/profile.rb +1 -2
- data/app/models/sitemap.rb +53 -51
- data/app/models/user.rb +2 -6
- data/app/views/users/change_password.html.haml +38 -0
- data/app/views/users/edit.html.haml +4 -13
- data/lib/wheels/routes.rb +3 -0
- data/wheels.gemspec +3 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.16
|
@@ -2,11 +2,8 @@ class PagesController < InheritedResources::Base
|
|
2
2
|
respond_to :js, :html
|
3
3
|
ajax_loading
|
4
4
|
before_filter :authenticate_user!, :except=>[:show]
|
5
|
-
before_filter :
|
6
|
-
|
7
|
-
before_filter :maybe_authenticate, :only=>[:show]
|
8
|
-
before_filter :set_collection_name
|
9
|
-
authorize_resource
|
5
|
+
before_filter :authorize_resource, :except=>[:index, :show]
|
6
|
+
|
10
7
|
has_scope :tagged_with, :as => :tag
|
11
8
|
|
12
9
|
has_scope :accessible_by, :type=>:boolean, :default=>true do |c,s|
|
@@ -14,10 +11,31 @@ class PagesController < InheritedResources::Base
|
|
14
11
|
end
|
15
12
|
|
16
13
|
def show
|
17
|
-
resource
|
18
14
|
@sidebar = true
|
19
|
-
|
20
|
-
|
15
|
+
if params[:id]
|
16
|
+
@sitemap ||= resource.sitemaps.sort{|t,u| t.url.size <=> u.url.size}[0]
|
17
|
+
@page = resource
|
18
|
+
else
|
19
|
+
@sitemap = Sitemap.from_request_params(params)
|
20
|
+
@page = @sitemap.try(:resource)
|
21
|
+
end
|
22
|
+
if @page
|
23
|
+
@child_pages = @sitemap.children.is_a?(Array) ? [] : @sitemap.children.accessible_by(current_ability)
|
24
|
+
|
25
|
+
if can_access_resources?
|
26
|
+
respond_with @page, @sitemap, @child_pages, @attachments
|
27
|
+
else
|
28
|
+
if user_signed_in?
|
29
|
+
flash[:notice] = "How did you find that page? Please contact your administrator if you believe you should have access to that resource."
|
30
|
+
redirect_to root_url
|
31
|
+
else
|
32
|
+
authenticate_user!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
flash[:notice] = "Sorry, we couldn't find the resource you were looking for!"
|
37
|
+
redirect_to root_url
|
38
|
+
end
|
21
39
|
end
|
22
40
|
|
23
41
|
def edit
|
@@ -42,39 +60,19 @@ class PagesController < InheritedResources::Base
|
|
42
60
|
end
|
43
61
|
end
|
44
62
|
|
45
|
-
def set_collection_name
|
46
|
-
if params[:page_id]
|
47
|
-
self.resources_configuration[:self][:collection_name] = :children
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_request_url
|
52
|
-
if params["level1"]
|
53
|
-
@sitemap = Sitemap.find_by_path(*[1,2,3,4].map{|i|params["level#{i}"]})
|
54
|
-
@page = @sitemap.resource
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
63
|
def resource
|
60
|
-
|
61
|
-
|
62
|
-
if page_id.is_numeric?
|
63
|
-
@page ||= Page.find(page_id)
|
64
|
-
else
|
65
|
-
@page ||= Page.where(["lower(pages.title) = ?", page_id.downcase.gsub(/[_]/, ' ')]).first
|
66
|
-
end
|
67
|
-
@attachments ||= @page.attachments
|
68
|
-
end
|
69
|
-
@sitemap ||= @page.sitemaps.sort{|t,u| t.url.size <=> u.url.size}[0]
|
70
|
-
@page
|
64
|
+
return @page ||= Page.find(params[:id])
|
65
|
+
@attachments = @page.attachments
|
71
66
|
end
|
72
67
|
|
73
68
|
def maybe_authenticate
|
74
69
|
unless user_signed_in?
|
75
|
-
authenticate_user! unless current_ability.can? :read,
|
70
|
+
authenticate_user! unless current_ability.can?(:read, resource) && current_ability.can?(:read, @sitemap)
|
76
71
|
end
|
77
72
|
end
|
78
73
|
|
74
|
+
def can_access_resources?
|
75
|
+
current_ability.can?(params[:action].to_sym, resource) && current_ability.can?(params[:action].to_sym, @sitemap)
|
76
|
+
end
|
79
77
|
end
|
80
78
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class UsersController < InheritedResources::Base
|
2
|
-
respond_to :html, :js, :only=>[:edit, :show, :update]
|
2
|
+
respond_to :html, :js, :only=>[:edit, :show, :update, :change_password]
|
3
3
|
respond_to :json, :only=>[:verify_password]
|
4
4
|
|
5
5
|
before_filter :authenticate_user!, :resource
|
@@ -9,12 +9,22 @@ class UsersController < InheritedResources::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def update
|
12
|
-
|
13
|
-
|
12
|
+
if params[:commit] == "Update Account"
|
13
|
+
@user = User.find(params[:id])
|
14
|
+
@user._validators.delete_if{|k,v| k.in?(:password, :password_confirmation)}
|
15
|
+
params[:user].delete_if{|k,v| k.in?("password", "password_confirmation")}
|
16
|
+
@user.class_eval do
|
17
|
+
attr_accessor :old_password
|
18
|
+
validates :email, :presence => true, :email => true
|
19
|
+
validates :old_password, :presence=>true, :password=>true
|
20
|
+
end
|
21
|
+
else
|
22
|
+
@user = resource
|
23
|
+
end
|
14
24
|
|
15
25
|
update! do |success, failure|
|
16
26
|
failure.html{redirect_to my_account_path}
|
17
|
-
success.html{flash[:notice] = "Your
|
27
|
+
success.html{flash[:notice] = "Your account has been updated."; redirect_to root_url}
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
@@ -19,10 +19,10 @@ class AccessControlEntry < ActiveRecord::Base
|
|
19
19
|
|
20
20
|
def resource=(res)
|
21
21
|
@res = res
|
22
|
-
if res.is_a? Class then resource_type = res.name
|
22
|
+
if res.is_a? Class then self.resource_type = res.name
|
23
23
|
else
|
24
|
-
resource_id = res.id
|
25
|
-
resource_type = res.class.name
|
24
|
+
self.resource_id = res.id
|
25
|
+
self.resource_type = res.class.name
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/app/models/profile.rb
CHANGED
@@ -2,12 +2,11 @@ class Profile < ActiveRecord::Base
|
|
2
2
|
acts_as_tagger
|
3
3
|
belongs_to :user
|
4
4
|
validates_uniqueness_of :alias
|
5
|
+
validates :phone, :phone=>true
|
5
6
|
has_attached_file :image,
|
6
7
|
:storage => :s3,
|
7
8
|
:s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
|
8
9
|
:path => "/:style/:filename",
|
9
10
|
:styles => { :medium => "300x300>", :thumb => "100x100>" }
|
10
|
-
|
11
|
-
|
12
11
|
end
|
13
12
|
|
data/app/models/sitemap.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
class Sitemap < ActiveRecord::Base
|
2
|
+
after_create :create_resource
|
3
|
+
after_save :reload_root
|
4
|
+
alias_attribute :name, :menu_text
|
5
|
+
before_destroy :on_before_destroy
|
6
|
+
belongs_to :parent, :class_name=>'Sitemap', :foreign_key=>'parent_id'
|
7
|
+
belongs_to :resource, :polymorphic => true
|
8
|
+
has_many :access_control_entries, :as => :resource
|
2
9
|
has_many :children, :class_name=>'Sitemap', :foreign_key=>'parent_id', :dependent => :destroy do
|
3
10
|
def sorted
|
4
11
|
sort{|t, u| if t.nil? || t.position.nil?; 1;
|
@@ -6,35 +13,9 @@ class Sitemap < ActiveRecord::Base
|
|
6
13
|
else t.position <=> u.position end}
|
7
14
|
end
|
8
15
|
end
|
9
|
-
|
10
|
-
has_many :access_control_entries, :as => :resource
|
11
|
-
|
12
|
-
alias_attribute :name, :menu_text
|
13
|
-
|
14
|
-
def self.new_main_menu_page(name)
|
15
|
-
Sitemap.create( :parent=>self.main_menu,
|
16
|
-
:menu_text=>name,
|
17
|
-
:resource=>Page.create(:title=>name),
|
18
|
-
:position=>Sitemap.main_menu.children.count)
|
19
|
-
end
|
20
|
-
|
21
|
-
belongs_to :parent, :class_name=>'Sitemap', :foreign_key=>'parent_id'
|
22
|
-
belongs_to :resource, :polymorphic => true
|
23
|
-
after_create :create_resource
|
24
|
-
before_destroy :on_before_destroy
|
25
|
-
after_save :reload_root
|
26
|
-
validates :resource, :presence=>true
|
27
16
|
accepts_nested_attributes_for :children
|
28
|
-
|
29
|
-
def reload_root
|
30
|
-
Sitemap.instance_variable_set('@_root', nil)
|
31
|
-
end
|
32
|
-
|
33
|
-
def on_before_destroy
|
34
|
-
resource.destroy if resource && resource.sitemaps.size==1
|
35
|
-
end
|
36
|
-
|
37
17
|
scope :orphans, where(:parent_id=>nil).where("menu_text <> 'root'")
|
18
|
+
validates :resource, :presence=>true
|
38
19
|
|
39
20
|
def as_json(*a)
|
40
21
|
{
|
@@ -54,7 +35,7 @@ class Sitemap < ActiveRecord::Base
|
|
54
35
|
:state=>treeview_state,
|
55
36
|
:children=> children.sorted
|
56
37
|
}.as_json(*a)
|
57
|
-
|
38
|
+
end
|
58
39
|
|
59
40
|
def resource_attributes=(attrib={})
|
60
41
|
raise "Cant build resource without resource_type" if resource_type.empty?
|
@@ -63,13 +44,6 @@ class Sitemap < ActiveRecord::Base
|
|
63
44
|
resource.save
|
64
45
|
end
|
65
46
|
|
66
|
-
def create_resource
|
67
|
-
if self.resource_type && !self.resource_id
|
68
|
-
self.resource = resource_type.constantize.new
|
69
|
-
self.save
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
47
|
def url
|
74
48
|
if self == Sitemap.main_menu
|
75
49
|
'/'
|
@@ -80,6 +54,21 @@ class Sitemap < ActiveRecord::Base
|
|
80
54
|
end
|
81
55
|
end
|
82
56
|
|
57
|
+
# Callbacks
|
58
|
+
def reload_root
|
59
|
+
Sitemap.instance_variable_set('@_root', nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_before_destroy
|
63
|
+
resource.destroy if resource && resource.sitemaps.size==1
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_resource
|
67
|
+
if self.resource_type && !self.resource_id
|
68
|
+
self.resource = resource_type.constantize.new
|
69
|
+
self.save
|
70
|
+
end
|
71
|
+
end
|
83
72
|
|
84
73
|
#########################################################################
|
85
74
|
#
|
@@ -87,8 +76,9 @@ class Sitemap < ActiveRecord::Base
|
|
87
76
|
#
|
88
77
|
#########################################################################
|
89
78
|
|
90
|
-
def self.
|
91
|
-
|
79
|
+
def self.from_request_params(params)
|
80
|
+
puts params.slice(:level1, :level2, :level3, :level4).values.inspect + "\n"*30
|
81
|
+
find_by_path params.slice(:level1, :level2, :level3, :level4).values
|
92
82
|
end
|
93
83
|
|
94
84
|
def self.lost_and_found
|
@@ -99,26 +89,38 @@ class Sitemap < ActiveRecord::Base
|
|
99
89
|
root.children.select{|t| t.menu_text=='Main Menu'}[0]
|
100
90
|
end
|
101
91
|
|
92
|
+
def self.root
|
93
|
+
@_root ||= Sitemap.find_by_menu_text_and_parent_id('root', nil)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.new_main_menu_page(name)
|
97
|
+
Sitemap.create( :parent=>self.main_menu,
|
98
|
+
:menu_text=>name,
|
99
|
+
:resource=>Page.create(:title=>name),
|
100
|
+
:position=>Sitemap.main_menu.children.count)
|
101
|
+
end
|
102
|
+
|
102
103
|
def self.settings
|
103
104
|
root.children.select{|t| t.menu_text=='Settings'}[0]
|
104
105
|
end
|
105
106
|
|
107
|
+
#########################################################################
|
108
|
+
#
|
109
|
+
# Private Methods
|
110
|
+
#
|
111
|
+
#########################################################################
|
106
112
|
def self.find_by_path(*path_args)
|
113
|
+
path_args.flatten!
|
107
114
|
path = path_args.reverse
|
108
115
|
path.delete(nil)
|
109
116
|
obj = Sitemap.main_menu
|
110
117
|
while (path_piece=path.pop)
|
111
118
|
obj = obj.children.select{|t| t.menu_text.downcase==path_piece.downcase.gsub(/_/, ' ')}[0]
|
112
|
-
|
119
|
+
break unless obj
|
113
120
|
end
|
114
121
|
return obj
|
115
122
|
end
|
116
123
|
|
117
|
-
#########################################################################
|
118
|
-
#
|
119
|
-
# Private Methods
|
120
|
-
#
|
121
|
-
#########################################################################
|
122
124
|
|
123
125
|
private
|
124
126
|
def build_resource(params={})
|
@@ -137,14 +139,6 @@ class Sitemap < ActiveRecord::Base
|
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
140
|
-
def new_model
|
141
|
-
resource_class.new(:sitemaps=>[self]) if resource_class
|
142
|
-
end
|
143
|
-
|
144
|
-
def resource_class
|
145
|
-
resource_type.camelize.constantize unless resource_type.empty?
|
146
|
-
end
|
147
|
-
|
148
142
|
def icon_name
|
149
143
|
case resource_type
|
150
144
|
when "Page"
|
@@ -156,6 +150,14 @@ class Sitemap < ActiveRecord::Base
|
|
156
150
|
end
|
157
151
|
end
|
158
152
|
|
153
|
+
def new_model
|
154
|
+
resource_class.new(:sitemaps=>[self]) if resource_class
|
155
|
+
end
|
156
|
+
|
157
|
+
def resource_class
|
158
|
+
resource_type.camelize.constantize unless resource_type.empty?
|
159
|
+
end
|
160
|
+
|
159
161
|
def treeview_state
|
160
162
|
if resource.is_a?(Menu)
|
161
163
|
"open"
|
data/app/models/user.rb
CHANGED
@@ -6,9 +6,6 @@ class User < ActiveRecord::Base
|
|
6
6
|
has_many :access_control_entries, :dependent=>:destroy
|
7
7
|
before_create :create_profile
|
8
8
|
|
9
|
-
form_attributes( {"Edit your profile" => :profile_attributes},
|
10
|
-
{"Change your password" => [:old_password, :new_password, {"Re-type password"=>:password_confirmation}]})
|
11
|
-
|
12
9
|
accepts_nested_attributes_for :profile
|
13
10
|
|
14
11
|
def initialize(*args)
|
@@ -58,18 +55,17 @@ class User < ActiveRecord::Base
|
|
58
55
|
save
|
59
56
|
end
|
60
57
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :lockable, :timeoutable
|
61
|
-
|
62
58
|
end
|
63
59
|
|
64
60
|
class FullyValidatedUser < User
|
65
61
|
def class
|
66
62
|
User
|
67
63
|
end
|
64
|
+
_validators[:password].delete_if{|t| t.is_a? ActiveModel::Validations::PresenceValidator}
|
68
65
|
attr_accessor :old_password
|
69
66
|
validates :email, :presence => true, :email => true
|
70
|
-
validates :old_password, :presence=>true
|
67
|
+
validates :old_password, :presence=>true, :password=>true
|
71
68
|
validates :password, :length=>{:minimum=>6}
|
72
69
|
validates :password_confirmation, :equal_to=>{:other=>:password}
|
73
|
-
validates :phone, :phone=>true
|
74
70
|
end
|
75
71
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
%h1 Change Password
|
2
|
+
|
3
|
+
.form
|
4
|
+
= form_for resource do |f|
|
5
|
+
-if resource.errors.any?
|
6
|
+
#errorExplanation
|
7
|
+
%h2= "#{pluralize(resource.errors.count, "error")} prohibited this change:"
|
8
|
+
%ul
|
9
|
+
- resource.errors.full_messages.each do |msg|
|
10
|
+
%li= msg
|
11
|
+
.field
|
12
|
+
.fieldName= label_tag "Please enter your old password for verification."
|
13
|
+
.fieldValue= f.password_field :old_password, :id=>"old_password"
|
14
|
+
.field
|
15
|
+
.fieldName= label_tag "New Password:"
|
16
|
+
.fieldValue= f.password_field :password, :id=>"password"
|
17
|
+
.field
|
18
|
+
.fieldName= label_tag "Confirm Password:"
|
19
|
+
.fieldalue= f.password_field :password_confirmation
|
20
|
+
.submit= f.submit "Change Password"
|
21
|
+
|
22
|
+
:css
|
23
|
+
.extra_form_data {
|
24
|
+
display: none;
|
25
|
+
}
|
26
|
+
|
27
|
+
= content_for :head do
|
28
|
+
= javascript_include_tag %w(jquery.validate jquery-validate/additional-methods.js)
|
29
|
+
|
30
|
+
|
31
|
+
:javascript
|
32
|
+
var checkingPassword = true;
|
33
|
+
$(function(){
|
34
|
+
|
35
|
+
$('form').validate({onkeyup: function(element) {}});
|
36
|
+
$('#old_password').rules("add", {verify_user : true, alphanumeric: true})
|
37
|
+
});
|
38
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
%h1
|
1
|
+
%h1 Update your personal info:
|
2
2
|
|
3
3
|
.form
|
4
4
|
= form_for resource do |f|
|
@@ -10,7 +10,6 @@
|
|
10
10
|
%li= msg
|
11
11
|
|
12
12
|
.fieldGroup
|
13
|
-
.fieldGroupTitle Edit your personal info
|
14
13
|
= f.fields_for :profile do |pf|
|
15
14
|
.field
|
16
15
|
.fieldName= pf.label :first_name
|
@@ -30,18 +29,10 @@
|
|
30
29
|
.field
|
31
30
|
.fieldName= pf.label :position
|
32
31
|
.fieldValue= pf.text_field :position
|
33
|
-
.fieldGroup
|
34
|
-
.fieldGroupTitle Change your password
|
35
32
|
.field
|
36
|
-
.fieldName= label_tag "
|
33
|
+
.fieldName= label_tag "Please enter your password for verification:"
|
37
34
|
.fieldValue= f.password_field :old_password, :id=>"old_password"
|
38
|
-
.
|
39
|
-
.fieldName= label_tag "New Password:"
|
40
|
-
.fieldValue= f.password_field :password, :id=>"password"
|
41
|
-
.field
|
42
|
-
.fieldName= label_tag "Confirm Password:"
|
43
|
-
.fieldalue= f.password_field :password_confirmation
|
44
|
-
.submit= f.submit "Change Password"
|
35
|
+
.submit= f.submit "Update Account"
|
45
36
|
|
46
37
|
:css
|
47
38
|
.extra_form_data {
|
@@ -49,7 +40,7 @@
|
|
49
40
|
}
|
50
41
|
|
51
42
|
= content_for :head do
|
52
|
-
= javascript_include_tag %w(jquery.validate jquery-validate/
|
43
|
+
= javascript_include_tag %w(jquery.validate jquery-validate/additional-methods.js)
|
53
44
|
|
54
45
|
|
55
46
|
:javascript
|
data/lib/wheels/routes.rb
CHANGED
@@ -50,7 +50,10 @@ module ActionDispatch::Routing
|
|
50
50
|
match '/css' => 'app_configs#css'
|
51
51
|
match '/admin' => "sitemaps#index"
|
52
52
|
match "my_account" => "users#edit"
|
53
|
+
match "change_password" => "users#change_password"
|
53
54
|
match "verify_password" => "users#verify", :format=>:json
|
55
|
+
match '/:level1(/:level2(/:level3(/:level4)))' =>'pages#show'
|
56
|
+
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
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.1.
|
8
|
+
s.version = "0.1.16"
|
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-09-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.description = %q{Call rails generate wheels.}
|
14
14
|
s.email = %q{tgannon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -216,6 +216,7 @@ Gem::Specification.new do |s|
|
|
216
216
|
"app/views/sitemaps/index.json.erb",
|
217
217
|
"app/views/sitemaps/new.html.haml",
|
218
218
|
"app/views/sitemaps/new.js.erb",
|
219
|
+
"app/views/users/change_password.html.haml",
|
219
220
|
"app/views/users/edit.html.haml",
|
220
221
|
"app/views/users/index.html.haml",
|
221
222
|
"config/amazon_s3.yml",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 16
|
9
|
+
version: 0.1.16
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tyler Gannon
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-17 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- app/views/sitemaps/index.json.erb
|
240
240
|
- app/views/sitemaps/new.html.haml
|
241
241
|
- app/views/sitemaps/new.js.erb
|
242
|
+
- app/views/users/change_password.html.haml
|
242
243
|
- app/views/users/edit.html.haml
|
243
244
|
- app/views/users/index.html.haml
|
244
245
|
- config/amazon_s3.yml
|