diff options
-rw-r--r-- | app/controllers/admin_user_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/user_controller.rb | 28 | ||||
-rw-r--r-- | app/models/about_me_validator.rb | 20 | ||||
-rw-r--r-- | app/models/user.rb | 12 | ||||
-rw-r--r-- | app/views/admin_user/_form.rhtml | 4 | ||||
-rw-r--r-- | app/views/user/set_profile_about_me.rhtml | 37 | ||||
-rw-r--r-- | app/views/user/show.rhtml | 13 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | db/migrate/087_add_about_me.rb | 11 | ||||
-rw-r--r-- | db/schema.rb | 3 |
10 files changed, 125 insertions, 5 deletions
diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index f55c04e90..857457cc6 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -40,6 +40,7 @@ class AdminUserController < AdminController @admin_user.email = params[:admin_user][:email] @admin_user.admin_level = params[:admin_user][:admin_level] @admin_user.ban_text = params[:admin_user][:ban_text] + @admin_user.about_me = params[:admin_user][:about_me] if @admin_user.valid? @admin_user.save! diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 85d09abc7..fd9eb9fbf 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -419,6 +419,34 @@ class UserController < ApplicationController render_for_text(@display_user.profile_photo.data) end + # Change about me text on your profile page + def set_profile_about_me + if authenticated_user.nil? + flash[:error] = "You need to be logged in to change the text about you on your profile." + redirect_to frontpage_url + return + end + + if !params[:submitted_about_me] + params[:about_me] = {} + params[:about_me][:about_me] = @user.about_me + @about_me = AboutMeValidator.new(params[:about_me]) + render :action => 'set_profile_about_me' + return + end + + @about_me = AboutMeValidator.new(params[:about_me]) + if !@about_me.valid? + render :action => 'set_profile_about_me' + return + end + + @user.about_me = @about_me.about_me + @user.save! + flash[:notice] = "You have now changed the text about you on your profile." + redirect_to user_url(@user) + end + private # Decide where we are going to redirect back to after signin/signup, and record that diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb new file mode 100644 index 000000000..70778d911 --- /dev/null +++ b/app/models/about_me_validator.rb @@ -0,0 +1,20 @@ +# models/about_me_validator.rb: +# Validates editing about me text on user profile pages. +# +# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $ + +class AboutMeValidator < ActiveRecord::BaseWithoutTable + strip_attributes! + + column :about_me, :text, "I...", false + + def validate + if !self.about_me.blank? && self.about_me.size > 500 + errors.add(:about_me, "^Please keep it shorter than 500 characters") + end + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index dcc92d5e3..8b99cb61e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -109,6 +109,8 @@ class User < ActiveRecord::Base end # Don't display any leading/trailing spaces + # XXX we have strip_attributes! now, so perhaps this can be removed (might + # be still needed for existing cases) def name name = read_attribute(:name) if not name.nil? @@ -308,6 +310,16 @@ class User < ActiveRecord::Base nil # so doesn't print all users on console end + # Return about me text for display as HTML + def get_about_me_for_html_display + text = self.about_me.strip + text = CGI.escapeHTML(text) + text = MySociety::Format.make_clickable(text, :contract => 1) + text = text.gsub(/\n/, '<br>') + return text + end + + private def User.encrypted_password(password, salt) diff --git a/app/views/admin_user/_form.rhtml b/app/views/admin_user/_form.rhtml index 229b74d90..14945cf85 100644 --- a/app/views/admin_user/_form.rhtml +++ b/app/views/admin_user/_form.rhtml @@ -14,3 +14,7 @@ <p><label for="ban_text">Ban text</label> <small>(if not blank will stop the user from filing new requests, making annotations or messaging other users; the text is used in the user/banned.rhtml template, e.g. put "Unfortunately, you have repeatedly broken our moderation policy."</small>)<br/> <%= text_area 'admin_user', 'ban_text', :cols => 60, :rows => 3 %></p> +<p><label for="about_me">About me</label> (user's own text on their profile, format like comments):<br/> +<%= text_area 'admin_user', 'about_me', :cols => 60, :rows => 3 %></p> + + diff --git a/app/views/user/set_profile_about_me.rhtml b/app/views/user/set_profile_about_me.rhtml new file mode 100644 index 000000000..38d3b654c --- /dev/null +++ b/app/views/user/set_profile_about_me.rhtml @@ -0,0 +1,37 @@ +<% @title = "Change the text about you on your profile at WhatDoTheyKnow.com" %> + +<% raise "internal error" if not @user %> + +<%= foi_error_messages_for :about_me %> + +<% form_for :about_me do |f| %> + <div class="form_note"> + <h1>Edit text about you</h1> + <p> + What you are investigating using Freedom of Information? + </p> + <p> + This will appear on your WhatDoTheyKnow profile, to make it + easier for others to get involved with what you're doing. + </p> + </div> + + <p> + <label class="form_label" for="set_profile_about_me">About you:</label> + <%= f.text_area :about_me, :rows => 5, :cols => 55 %> + </p> + + <div class="form_note"> + <p> + Include relevant links, such as to a campaign page, your blog or a + twitter account. They will be made clickable. + e.g. + <a href="http://www.twitter.com/whatdotheyknow">http://www.twitter.com/whatdotheyknow</a> + </p> + </div> + + <div class="form_button"> + <%= hidden_field_tag 'submitted_about_me', 1 %> + <%= submit_tag "Save" %> + </div> +<% end %> diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml index 4d5a08720..ede1cc768 100644 --- a/app/views/user/show.rhtml +++ b/app/views/user/show.rhtml @@ -66,10 +66,15 @@ <% end %> </p> - <!--<div class="user_about_me"> - <img class="comment_quote" src="/images/quote.png" alt="">I like to make requests about bees. I'm obsessed with - them! Check out all the ace bees at http://www.britishbee.org.uk/ - </div>--> + <% if !@display_user.get_about_me_for_html_display.empty? || @is_you %> + <div class="user_about_me"> + <img class="comment_quote" src="/images/quote.png" alt=""> + <%= @display_user.get_about_me_for_html_display %> + <% if @is_you %> + (<%= link_to "edit text about you", set_profile_about_me_url() %>) + <% end %> + </div> + <% end %> <% if @is_you %> <p id="user_change_password_email"> diff --git a/config/routes.rb b/config/routes.rb index 14c8cfcfd..1b9f01eb4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ ActionController::Routing::Routes.draw do |map| user.set_profile_photo '/set_profile_photo', :action => 'set_profile_photo' user.get_profile_photo '/user/:url_name/photo.png', :action => 'get_profile_photo' user.get_draft_profile_photo '/draft_profile_photo/:id.png', :action => 'get_draft_profile_photo' + user.set_profile_about_me '/set_profile_about_me', :action => 'set_profile_about_me' end map.with_options :controller => 'public_body' do |body| diff --git a/db/migrate/087_add_about_me.rb b/db/migrate/087_add_about_me.rb new file mode 100644 index 000000000..9916454f3 --- /dev/null +++ b/db/migrate/087_add_about_me.rb @@ -0,0 +1,11 @@ +class AddAboutMe < ActiveRecord::Migration + def self.up + add_column :users, :about_me, :text, :null => false, :default => "" + end + + def self.down + raise "No reverse migration" + #remove_column :users, :about_me + end +end + diff --git a/db/schema.rb b/db/schema.rb index a6d5e8f55..e172a6e7e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 85) do +ActiveRecord::Schema.define(:version => 87) do create_table "acts_as_xapian_jobs", :force => true do |t| t.string "model", :null => false @@ -245,6 +245,7 @@ ActiveRecord::Schema.define(:version => 85) do t.datetime "last_daily_track_email", :default => '2000-01-01 00:00:00' t.string "admin_level", :default => "none", :null => false t.text "ban_text", :default => "", :null => false + t.text "about_me", :default => "", :null => false end add_index "users", ["url_name"], :name => "index_users_on_url_name", :unique => true |