diff options
-rw-r--r-- | app/controllers/track_controller.rb | 11 | ||||
-rw-r--r-- | app/controllers/user_controller.rb | 58 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 2 | ||||
-rw-r--r-- | app/models/track_thing.rb | 66 | ||||
-rw-r--r-- | app/views/layouts/default.rhtml | 1 | ||||
-rw-r--r-- | app/views/public_body/show.rhtml | 2 | ||||
-rw-r--r-- | app/views/request/_sidebar.rhtml | 2 | ||||
-rw-r--r-- | app/views/request/_wall_listing.rhtml | 30 | ||||
-rw-r--r-- | app/views/track/_tracking_links.rhtml | 19 | ||||
-rw-r--r-- | app/views/user/_change_receive_email.rhtml | 16 | ||||
-rw-r--r-- | app/views/user/show.rhtml | 7 | ||||
-rw-r--r-- | app/views/user/wall.rhtml | 16 | ||||
-rw-r--r-- | config/routes.rb | 3 | ||||
-rw-r--r-- | db/migrate/112_add_receive_email_alerts_to_user.rb | 11 | ||||
-rw-r--r-- | public/stylesheets/main.css | 36 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 5 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 9 |
19 files changed, 278 insertions, 53 deletions
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 312cedc6c..07e807451 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -123,7 +123,7 @@ class TrackController < ApplicationController if @user @existing_track = TrackThing.find_by_existing_track(@user, @track_thing) if @existing_track - flash[:notice] = _("You are already being emailed updates about ") + @track_thing.params[:list_description] + flash[:notice] = _("You are already following updates about {{track_description}}", :track_description => @track_thing.params[:list_description]) return true end end @@ -135,8 +135,11 @@ class TrackController < ApplicationController @track_thing.track_medium = 'email_daily' @track_thing.tracking_user_id = @user.id @track_thing.save! - - flash[:notice] = _("You will now be emailed updates about ") + @track_thing.params[:list_description] + if @user.receive_email_alerts + flash[:notice] = _('You will now be emailed updates about {{track_description}}. <a href="{{change_email_alerts_url}}">Prefer not to receive emails?</a>', :track_description => @track_thing.params[:list_description], :change_email_alerts_url => url_for(:controller => "user", :action => "wall", :url_name => @user.url_name)) + else + flash[:notice] = _('You are now <a href="{{wall_url_user}}">following</a> updates about {{track_description}}', :track_description => @track_thing.params[:list_description], :wall_url_user => url_for(:controller => "user", :action => "wall", :url_name => @user.url_name)) + end return true end @@ -179,7 +182,7 @@ class TrackController < ApplicationController new_medium = params[:track_medium] if new_medium == 'delete' track_thing.destroy - flash[:notice] = _("You will no longer be emailed updates about ") + track_thing.params[:list_description] + flash[:notice] = _("You are no longer following {{track_description}}", :track_description => track_thing.params[:list_description]) redirect_to params[:r] # Reuse code like this if we let medium change again. #elsif new_medium == 'email_daily' diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 76c56c442..e56c4dd33 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -6,6 +6,8 @@ # # $Id: user_controller.rb,v 1.71 2009-09-17 07:51:47 francis Exp $ +require 'set' + class UserController < ApplicationController layout :select_layout @@ -89,6 +91,50 @@ class UserController < ApplicationController end + # Show the user's wall + def wall + long_cache + @display_user = User.find(:first, :conditions => [ "url_name = ? and email_confirmed = ?", params[:url_name], true ]) + if not @display_user + raise ActiveRecord::RecordNotFound.new("user not found, url_name=" + params[:url_name]) + end + @is_you = !@user.nil? && @user.id == @display_user.id + feed_results = Set.new + # Use search query for this so can collapse and paginate easily + # XXX really should just use SQL query here rather than Xapian. + begin + requests_query = 'requested_by:' + @display_user.url_name + comments_query = 'commented_by:' + @display_user.url_name + # XXX combine these as OR query + @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse') + @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil) + rescue + @xapian_requests = nil + @xapian_comments = nil + end + + feed_results += @xapian_requests.results.map {|x| x[:model]} if !@xapian_requests.nil? + feed_results += @xapian_comments.results.map {|x| x[:model]} if !@xapian_comments.nil? + + # All tracks for the user + if @is_you + @track_things = TrackThing.find(:all, :conditions => ["tracking_user_id = ? and track_medium = ?", @display_user.id, 'email_daily'], :order => 'created_at desc') + for track_thing in @track_things + # XXX factor out of track_mailer.rb + xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 20, 1) + feed_results += xapian_object.results.map {|x| x[:model]} + end + end + + @feed_results = Array(feed_results).sort {|x,y| y.created_at <=> x.created_at}.first(20) + + respond_to do |format| + format.html { @has_json = true } + format.json { render :json => @display_user.json_for_api } + end + + end + # Login form def signin work_out_post_redirect @@ -533,6 +579,18 @@ class UserController < ApplicationController end end + # Change about me text on your profile page + def set_receive_email_alerts + if authenticated_user.nil? + flash[:error] = _("You need to be logged in to edit your profile.") + redirect_to frontpage_url + return + end + @user.receive_email_alerts = params[:receive_email_alerts] + @user.save! + redirect_to params[:came_from] + end + private def is_modal_dialog diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index f618fba49..92da7c376 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -47,7 +47,7 @@ class TrackMailer < ApplicationMailer return done_something end for user in users - next if !user.should_be_emailed? + next if !user.should_be_emailed? || !user.receive_email_alerts email_about_things = [] track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ? and track_medium = ?", user.id, 'email_daily' ]) diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index f6a58189f..7f6bc9a7e 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -195,16 +195,16 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track this request by email"), - :verb_on_page_already => _("You are already tracking this request by email"), + :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :verb_on_page => _("Follow this request"), + :verb_on_page_already => _("You are already following this request"), # Email :title_in_email => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), :title_in_rss => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), # Authentication - :web => _("To follow updates to the request '{{request_title}}'", :request_title => CGI.escapeHTML(self.info_request.title)), - :email => _("Then you will be emailed whenever the request '{{request_title}}' is updated.", :request_title => CGI.escapeHTML(self.info_request.title)), - :email_subject => _("Confirm you want to follow updates to the request '{{request_title}}'", :request_title => self.info_request.title), + :web => _("To follow the request '{{request_title}}'", :request_title => CGI.escapeHTML(self.info_request.title)), + :email => _("Then you will be updated whenever the request '{{request_title}}' is updated.", :request_title => CGI.escapeHTML(self.info_request.title)), + :email_subject => _("Confirm you want to follow the request '{{request_title}}'", :request_title => self.info_request.title), # RSS sorting :feed_sortby => 'newest' } @@ -212,15 +212,15 @@ class TrackThing < ActiveRecord::Base @params = { # Website :list_description => _("any <a href=\"/list\">new requests</a>"), - :verb_on_page => _("Email me when there are new requests"), - :verb_on_page_already => _("You are being emailed when there are new requests"), + :verb_on_page => _("Follow all new requests"), + :verb_on_page_already => _("You are already following new requests"), # Email :title_in_email => _("New Freedom of Information requests"), :title_in_rss => _("New Freedom of Information requests"), # Authentication - :web => _("To be emailed about any new requests"), - :email => _("Then you will be emailed whenever anyone makes a new FOI request."), - :email_subject => _("Confirm you want to be emailed about new requests"), + :web => _("To be follow new requests"), + :email => _("Then you will be following all new FOI request."), + :email_subject => _("Confirm you want to follow new requests"), # RSS sorting :feed_sortby => 'newest' } @@ -228,15 +228,15 @@ class TrackThing < ActiveRecord::Base @params = { # Website :list_description => _("any <a href=\"/list/successful\">successful requests</a>"), - :verb_on_page => _("Email me new successful responses "), - :verb_on_page_already => _("You are being emailed about any new successful responses"), + :verb_on_page => _("Follow new successful responses"), + :verb_on_page_already => _("You are following all new successful responses"), # Email :title_in_email => _("Successful Freedom of Information requests"), :title_in_rss => _("Successful Freedom of Information requests"), # Authentication - :web => _("To be emailed about any successful requests"), - :email => _("Then you will be emailed whenever an FOI request succeeds."), - :email_subject => _("Confirm you want to be emailed when an FOI request succeeds"), + :web => _("To follow all successful requests"), + :email => _("Then you will be notified whenever an FOI request succeeds."), + :email_subject => _("Confirm you want to follow all successful FOI requests"), # RSS sorting - used described date, as newest would give a # date for responses possibly days before description, so # wouldn't appear at top of list when description (known @@ -246,48 +246,48 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'public_body_updates' @params = { # Website - :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track requests to {{public_body_name}} by email",:public_body_name=>CGI.escapeHTML(self.public_body.name)), - :verb_on_page_already => _("You are already tracking requests to {{public_body_name}} by email", :public_body_name=>CGI.escapeHTML(self.public_body.name)), + :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :verb_on_page => _("Follow requests to {{public_body_name}}",:public_body_name=>CGI.escapeHTML(self.public_body.name)), + :verb_on_page_already => _("You are already following requests to {{public_body_name}}", :public_body_name=>CGI.escapeHTML(self.public_body.name)), # Email :title_in_email => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'", :title_in_rss => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'", # Authentication - :web => _("To be emailed about requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>MySociety::Config.get('SITE_NAME', 'Alaveteli'), :public_body_name=>CGI.escapeHTML(self.public_body.name)), - :email => _("Then you will be emailed whenever someone requests something or gets a response from '{{public_body_name}}'.", :public_body_name=>CGI.escapeHTML(self.public_body.name)), - :email_subject => _("Confirm you want to be emailed about requests to '{{public_body_name}}'", :public_body_name=>self.public_body.name), + :web => _("To follow requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>MySociety::Config.get('SITE_NAME', 'Alaveteli'), :public_body_name=>CGI.escapeHTML(self.public_body.name)), + :email => _("Then you will be notified whenever someone requests something or gets a response from '{{public_body_name}}'.", :public_body_name=>CGI.escapeHTML(self.public_body.name)), + :email_subject => _("Confirm you want to follow requests to '{{public_body_name}}'", :public_body_name=>self.public_body.name), # RSS sorting :feed_sortby => 'newest' } elsif self.track_type == 'user_updates' @params = { # Website - :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track this person by email"), - :verb_on_page_already => _("You are already tracking this person by email"), + :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :verb_on_page => _("Follow this person"), + :verb_on_page_already => _("You are already following this person"), # Email :title_in_email => _("FOI requests by '{{user_name}}'", :user_name=>self.tracked_user.name), :title_in_rss => _("FOI requests by '{{user_name}}'", :user_name=>self.tracked_user.name), # Authentication - :web => _("To be emailed about requests by '{{user_name}}'", :user_name=>CGI.escapeHTML(self.tracked_user.name)), - :email => _("Then you will be emailed whenever '{{user_name}}' requests something or gets a response.", :user_name=>CGI.escapeHTML(self.tracked_user.name)), - :email_subject => _("Confirm you want to be emailed about requests by '{{user_name}}'", :user_name=>self.tracked_user.name), + :web => _("To follow requests by '{{user_name}}'", :user_name=>CGI.escapeHTML(self.tracked_user.name)), + :email => _("Then you will be notified whenever '{{user_name}}' requests something or gets a response.", :user_name=>CGI.escapeHTML(self.tracked_user.name)), + :email_subject => _("Confirm you want to follow requests by '{{user_name}}'", :user_name=>self.tracked_user.name), # RSS sorting :feed_sortby => 'newest' } elsif self.track_type == 'search_query' @params = { # Website - :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track things matching this search by email"), - :verb_on_page_already => _("You are already tracking things matching this search by email"), + :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :verb_on_page => _("Follow things matching this search"), + :verb_on_page_already => _("You are already following things matching this search"), # Email :title_in_email => _("Requests or responses matching your saved search"), :title_in_rss => _("Requests or responses matching your saved search"), # Authentication :web => _("To follow requests and responses matching your search"), - :email => _("Then you will be emailed whenever a new request or response matches your search."), - :email_subject => _("Confirm you want to be emailed about new requests or responses matching your search"), + :email => _("Then you will be notified whenever a new request or response matches your search."), + :email_subject => _("Confirm you want to follow new requests or responses matching your search"), # RSS sorting - XXX hmmm, we don't really know which to use # here for sorting. Might be a query term (e.g. 'cctv'), in # which case newest is good, or might be something like diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index e60e7bef2..bc9dfb02d 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -104,6 +104,7 @@ <% if @user %> <%=link_to _("My requests"), show_user_requests_path(:url_name => @user.url_name) %> <%=link_to _("My profile"), show_user_profile_path(:url_name => @user.url_name) %> + <%=link_to _("My wall"), show_user_wall_path(:url_name => @user.url_name) %> <% end %> diff --git a/app/views/public_body/show.rhtml b/app/views/public_body/show.rhtml index 5f20a9717..63bd5f7fc 100644 --- a/app/views/public_body/show.rhtml +++ b/app/views/public_body/show.rhtml @@ -4,7 +4,7 @@ <h2><%= _('Follow this authority')%></h2> <% follower_count = TrackThing.count(:all, :conditions => ["public_body_id = ?", @public_body.id]) %> - <p><%= n_("There is %d person following this authority", "There are %d people following this authority", follower_count) % follower_count %></p> + <p><%= n_("<span id='follow_count'>%d</span> person is following this authority", "<span id='follow_count'>%d</span> people are following this authority", follower_count) % follower_count %></p> <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'sidebar' } %> <h2><%= _('More about this authority')%></h2> diff --git a/app/views/request/_sidebar.rhtml b/app/views/request/_sidebar.rhtml index c0708a36a..bca142fa9 100644 --- a/app/views/request/_sidebar.rhtml +++ b/app/views/request/_sidebar.rhtml @@ -1,9 +1,11 @@ <div id="right_column"> + <div id="follow_box"> <h2><%= _('Follow this request') %></h2> <% follower_count = TrackThing.count(:all, :conditions => ["info_request_id = ?", @info_request.id]) + 1 %> <p><%= n_("There is %d person following this request", "There are %d people following this request", follower_count) % follower_count %></p> <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => @info_request.user == @user, :location => 'sidebar' } %> + </div> <% if @info_request.described_state != "attention_requested" %> <h2><%= _('Offensive? Unsuitable?') %></h2> <% if @info_request.attention_requested %> diff --git a/app/views/request/_wall_listing.rhtml b/app/views/request/_wall_listing.rhtml new file mode 100644 index 000000000..9cde234c0 --- /dev/null +++ b/app/views/request/_wall_listing.rhtml @@ -0,0 +1,30 @@ +<% if @highlight_words.nil? + @highlight_words = [] +end %> + +<div class="request_listing"> + <div class="request_left"> + <div class="requester"> + <% if event.event_type == 'sent' %> + <%= _('A new request, <em><a href="{{request_url}}">{{request_title}}</a></em>, was sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>user_link_absolute(info_request.user),:date=>simple_date(event.created_at),:request_url=>request_url(info_request),:request_title=>info_request.title) %> + <% elsif event.event_type == 'followup_sent' %> + <%= _('A <a href="{{request_url}}">follow up</a> to <em>{{request_title}}</em> was sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>user_link_absolute(info_request.user),:date=>simple_date(event.created_at),:request_url=>outgoing_message_url(event.outgoing_message),:request_title=>info_request.title) %> + <% elsif event.event_type == 'response' %> + <%= _('A <a href="{{request_url}}">response</a> to <em>{{request_title}}</em> was sent by {{public_body_name}} to {{info_request_user}} on {{date}}. The request status is: {{request_status}}',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>user_link_absolute(info_request.user),:date=>simple_date(event.created_at),:request_url=>incoming_message_url(event.incoming_message_selective_columns("incoming_messages.id")),:request_title=>info_request.title,:request_status=>info_request.display_status) %> + <% elsif event.event_type == 'comment' %> + <%= _('An <a href="{{request_url}}">annotation</a> to <em>{{request_title}}</em> was made by {{event_comment_user}} on {{date}}',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>user_link_absolute(info_request.user),:event_comment_user=>user_link_absolute(event.comment.user),:date=>simple_date(event.created_at),:request_url=>comment_url(event.comment),:request_title=>info_request.title) %> + <% else %> + <%# Events of other types will not be indexed: see InfoRequestEvent#indexed_by_search? + However, it can happen that we see other types of event transiently here in the period + between a change being made and the update-xapian-index job being run. %> + <!-- Event of type '<%= event.event_type %>', id=<%= event.id %> --> + <% end %> + </div> + </div> + <div class="request_right"> + <span class="desc"> + <%= highlight_and_excerpt(event.search_text_main(true), @highlight_words, 150) %> + </span> + </div> +</div> + diff --git a/app/views/track/_tracking_links.rhtml b/app/views/track/_tracking_links.rhtml index f50a8bbbf..39f346eff 100644 --- a/app/views/track/_tracking_links.rhtml +++ b/app/views/track/_tracking_links.rhtml @@ -7,18 +7,17 @@ <% if own_request %> <p><%= _('This is your own request, so you will be automatically emailed when new responses arrive.')%></p> <% elsif existing_track %> - <% form_tag({:controller => 'track', :action => 'update', :track_id => existing_track.id}, :class => "feed_form feed_form_" + location) do %> - <p> - <%= track_thing.params[:verb_on_page_already] %> - <%= hidden_field_tag 'track_medium', "delete" %> - <%= hidden_field_tag 'r', request.request_uri %> - <%= submit_tag "unsubscribe" %> - </p> - <% end %> + <p><%= track_thing.params[:verb_on_page_already] %></p> + <div class="feed_link feed_link_<%=location%>"> + <%= link_to "Unsubscribe", {:controller => 'track', :action => 'update', :track_id => existing_track.id, :track_medium => "delete", :r => request.request_uri}, :class => "link_button_green" %> + </div> <% elsif track_thing %> <div class="feed_link feed_link_<%=location%>"> - <%= link_to '<img src="/images/email-16.png" alt="">', do_track_url(track_thing) %> - <%= link_to _("Follow by email"), do_track_url(track_thing) %> + <% if defined? follower_count && follower_count > 0 %> + <%= link_to _("I like this request"), do_track_url(track_thing), :class => "link_button_green" %> + <% else %> + <%= link_to _("Follow"), do_track_url(track_thing), :class => "link_button_green" %> + <% end %> </div> <div class="feed_link feed_link_<%=location%>"> diff --git a/app/views/user/_change_receive_email.rhtml b/app/views/user/_change_receive_email.rhtml new file mode 100644 index 000000000..83e5d8601 --- /dev/null +++ b/app/views/user/_change_receive_email.rhtml @@ -0,0 +1,16 @@ +<% form_tag(:controller=>"user", :action=>"set_receive_email_alerts") do %> + <div> + <% if @user.receive_email_alerts %> + <%= _('You are currently receiving notification of new activity on your wall by email.', :wall_url => show_user_wall_path) %><br><br> + <%= hidden_field_tag 'receive_email_alerts', 'false' %> + <%= hidden_field_tag 'came_from', request.url %> + <%= submit_tag _("Turn off email alerts") %> + <% else %> + <%= _('Items matching the following conditions are currently displayed on your wall.') %><br><br> + <%= hidden_field_tag 'receive_email_alerts', 'true' %> + <%= hidden_field_tag 'came_from', request.url %> + <%= submit_tag _("Also send me alerts by email") %> + <% end %> + </div> +<% end %> + diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml index f8b820f03..d723196d3 100644 --- a/app/views/user/show.rhtml +++ b/app/views/user/show.rhtml @@ -192,11 +192,12 @@ </div> <% end %> <% if @show_profile && @is_you %> + <h2 id="email_subscriptions"> <%= _("Things you're following")%></h2> + <%= render :partial => 'change_receive_email' %> + <br> <% if @track_things.empty? %> - <h2 id="email_subscriptions"> <%= _('Your email subscriptions')%></h2> - <p><%= _('None made.')%></p> + <p><%= _("You're not following anything.")%></p> <% else %> - <h2 id="email_subscriptions"> Your <%=pluralize(@track_things.size, _('email subscription')) %> </h2> <% if @track_things_grouped.size == 1 %> <% form_tag({:controller => 'track', :action => 'delete_all_type'}, :class => "feed_form") do %> <h3> diff --git a/app/views/user/wall.rhtml b/app/views/user/wall.rhtml new file mode 100644 index 000000000..190cc0a6d --- /dev/null +++ b/app/views/user/wall.rhtml @@ -0,0 +1,16 @@ +<% @title = h(@display_user.name) + _(" - wall") %> +<% if @is_you %> +<div class="medium_column"> + <p><%= _('You can change the requests and users you are following on <a href="{{profile_url}}">your profile page</a>.', :profile_url => show_user_profile_path) %> + <%= render :partial => 'change_receive_email' %> +</div> +<% end %> +<div id="user_profile_search"> + <% if !@feed_results.nil? %> + <% for result in @feed_results %> + <%= render :partial => 'request/wall_listing', :locals => { :event => result, :info_request => result.info_request } %> + <% end %> + <% end %> + + +</div> diff --git a/config/routes.rb b/config/routes.rb index ca032c7df..0ba8139c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,6 +82,7 @@ ActionController::Routing::Routes.draw do |map| user.show_user '/user/:url_name.:format', :action => 'show' user.show_user_profile '/user/:url_name/profile.:format', :action => 'show', :view => 'profile' user.show_user_requests '/user/:url_name/requests.:format', :action => 'show', :view => 'requests' + user.show_user_wall '/user/:url_name/wall.:format', :action => 'wall' user.contact_user '/user/contact/:id', :action => 'contact' user.signchangepassword '/profile/change_password', :action => 'signchangepassword' @@ -92,7 +93,7 @@ ActionController::Routing::Routes.draw do |map| user.get_profile_photo '/user/:url_name/photo.png', :action => 'get_profile_photo' user.get_draft_profile_photo '/profile/draft_photo/:id.png', :action => 'get_draft_profile_photo' user.set_profile_about_me '/profile/set_about_me', :action => 'set_profile_about_me' - + user.set_receive_email_alerts '/profile/set_receive_alerts', :action => 'set_receive_email_alerts' user.river '/profile/river', :action => 'river' end diff --git a/db/migrate/112_add_receive_email_alerts_to_user.rb b/db/migrate/112_add_receive_email_alerts_to_user.rb new file mode 100644 index 000000000..7e06dd275 --- /dev/null +++ b/db/migrate/112_add_receive_email_alerts_to_user.rb @@ -0,0 +1,11 @@ +class AddReceiveEmailAlertsToUser < ActiveRecord::Migration + def self.up + add_column :users, :receive_email_alerts, :boolean, :default => true, :null => false + end + def self.down + remove_column :users, :receive_email_alerts + end +end + + + diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 0c2239409..31a8ba63c 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -882,6 +882,34 @@ vertical-align:middle; text-decoration:none; } +#follow_box { + + padding: 4px; +} + +#follow_box .feed_link { + text-align: center; +} + +#follow_count { + color: #93278F; + font-family: 'DeliciousBold', Arial, sans-serif; + font-weight: 700; + font-size: 60px; + line-height: 60px; + text-align: right; + float: left; + margin-top: -15px; + margin-right: 5px; +} +.follow_count { + clear:both; +} + +#follow_box h2 { + margin: 0; +} + h2,dt { font-size:1.8em; } @@ -1255,6 +1283,9 @@ cursor:pointer; padding:5px 6px; } +.feed_link a.link_button_green { + color:white; +} a.link_button_green_large { background:url(/images/button-gradient-large.png); font-size:2em; @@ -1639,6 +1670,11 @@ width:575px; padding-right:50px; float:left; } +.medium_column { +width:575px; +padding-right:50px; +} + #authority_preview .request_left, #authority_preview #header_left { width: 100%; diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index bc7cfce64..1d38b3055 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -16,6 +16,8 @@ describe TrackController, "when making a new track on a request" do @user = mock_model(User) User.stub!(:find).and_return(@user) @user.stub!(:locale).and_return("en") + @user.stub!(:receive_email_alerts).and_return(true) + @user.stub!(:url_name).and_return("bob") end it "should require login when making new track" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 0d7b19e1e..7a6c9ac0d 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -630,6 +630,41 @@ describe UserController, "when showing JSON version for API" do end +describe UserController, "when viewing the wall" do + integrate_views + + before(:each) do + rebuild_xapian_index + end + it "should show users stuff on their wall, most recent first" do + user = users(:silly_name_user) + ire = info_request_events(:useless_incoming_message_event) + ire.created_at = DateTime.new(2001,1,1) + session[:user_id] = user.id + get :wall, :url_name => user.url_name + assigns[:feed_results][0].should_not == ire + ire.created_at = Time.now + ire.save! + get :wall, :url_name => user.url_name + assigns[:feed_results][0].should == ire + end + it "should show other users' activities on their walls" do + user = users(:silly_name_user) + ire = info_request_events(:useless_incoming_message_event) + get :wall, :url_name => user.url_name + assigns[:feed_results][0].should_not == ire + end + + it "should allow users to turn their own email alerts on and off" do + user = users(:silly_name_user) + session[:user_id] = user.id + user.receive_email_alerts.should == true + get :set_receive_email_alerts, :receive_email_alerts => 'false', :came_from => "/" + user.reload + user.receive_email_alerts.should_not == true + end + +end diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index 8620fb3de..d6391c5e8 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -12,6 +12,7 @@ bob_smith_user: ban_text: '' locale: 'en' about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.' + receive_email_alerts: true silly_name_user: id: "2" name: "Silly <em>Name</em>" @@ -26,6 +27,7 @@ silly_name_user: ban_text: '' locale: 'en' about_me: '' + receive_email_alerts: true admin_user: id: "3" name: Joe Admin @@ -40,6 +42,7 @@ admin_user: ban_text: '' locale: '' about_me: '' + receive_email_alerts: true unconfirmed_user: id: "4" name: "Unconfirmed" @@ -53,6 +56,7 @@ unconfirmed_user: admin_level: 'none' ban_text: '' about_me: '' + receive_email_alerts: true robin_user: id: 5 name: Robin Houston @@ -66,3 +70,4 @@ robin_user: admin_level: 'none' ban_text: '' about_me: 'I am the best' + receive_email_alerts: true diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 4f5499a90..1bf77dab5 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -25,6 +25,7 @@ describe TrackMailer do :get_locale => 'en', :should_be_emailed? => true) User.stub!(:find).and_return([@user]) + @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end @@ -122,6 +123,7 @@ describe TrackMailer do :url_name => 'test-name', :should_be_emailed? => false) User.stub!(:find).and_return([@user]) + @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end @@ -131,6 +133,13 @@ describe TrackMailer do TrackMailer.alert_tracks end + it 'should not ask for any daily track things for the user if they have receive_email_alerts off but could otherwise be emailed' do + @user.stub(:should_be_emailed?).and_return(true) + @user.stub(:receive_email_alerts).and_return(false) + expected_conditions = [ "tracking_user_id = ? and track_medium = ?", @user.id, 'email_daily' ] + TrackThing.should_not_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + TrackMailer.alert_tracks + end it 'should not set the no_xapian_reindex flag on the user' do @user.should_not_receive(:no_xapian_reindex=).with(true) |