aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/public_body.rb8
-rw-r--r--app/models/user.rb14
2 files changed, 17 insertions, 5 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 9c4956b68..546de2c40 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -21,7 +21,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body.rb,v 1.22 2008-02-27 12:04:10 francis Exp $
+# $Id: public_body.rb,v 1.23 2008-02-27 12:18:28 francis Exp $
class PublicBody < ActiveRecord::Base
validates_presence_of :name
@@ -50,14 +50,14 @@ class PublicBody < ActiveRecord::Base
# When name or short name is changed, also change the url name
def short_name=(short_name)
write_attribute(:short_name, short_name)
- update_url_name
+ self.update_url_name
end
def name=(name)
write_attribute(:name, name)
- update_url_name
+ self.update_url_name
end
def update_url_name
- url_name = MySociety::Format.simplify_url_part(short_or_long_name)
+ url_name = MySociety::Format.simplify_url_part(self.short_or_long_name)
write_attribute(:url_name, url_name)
end
# Return the short name if present, or else long name
diff --git a/app/models/user.rb b/app/models/user.rb
index ab680dc1e..79f26464d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -19,7 +19,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user.rb,v 1.29 2008-02-26 15:13:51 francis Exp $
+# $Id: user.rb,v 1.30 2008-02-27 12:18:28 francis Exp $
require 'digest/sha1'
@@ -28,6 +28,8 @@ class User < ActiveRecord::Base
validates_uniqueness_of :email, :case_sensitive => false, :message => "^There is already an account with that email address. You can sign in to it on the left."
validates_presence_of :name, :message => "^Please enter your name"
+ validates_presence_of :url_name
+
validates_presence_of :hashed_password, :message => "^Please enter a password"
has_many :info_requests
@@ -73,6 +75,16 @@ class User < ActiveRecord::Base
return self.find(:first, :conditions => [ 'email ilike ?', email ] ) # using ilike for case insensitive
end
+ # When name is changed, also change the url name
+ def name=(name)
+ write_attribute(:name, name)
+ self.update_url_name
+ end
+ def update_url_name
+ url_name = MySociety::Format.simplify_url_part(self.name)
+ write_attribute(:url_name, url_name)
+ end
+
# Virtual password attribute, which stores the hashed password, rather than plain text.
def password
@password