diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a9854f99..8fe708d97 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -148,7 +148,6 @@ class ApplicationController < ActionController::Base end def default_stream_action(stream_klass) - puts "yah" authenticate_user! save_sort_order @stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d0ee9370d..cb36b646c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -7,6 +7,7 @@ require File.join(Rails.root, 'lib', 'stream', 'public_stream') class PostsController < ApplicationController before_filter :authenticate_user!, :except => :show before_filter :set_format_if_malformed_from_status_net, :only => :show + before_filter :redirect_unless_admin, :only => :index respond_to :html, :mobile, diff --git a/app/helpers/publisher_helper.rb b/app/helpers/publisher_helper.rb index 516a20b28..235fafbdb 100644 --- a/app/helpers/publisher_helper.rb +++ b/app/helpers/publisher_helper.rb @@ -4,7 +4,7 @@ module PublisherHelper def public_value - params[:controller] == "tags" + params[:controller] == "tags" || params[:controller] == "posts" end def remote? diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index e7999fa46..5665e1cea 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -841,6 +841,7 @@ en: contacts_title: "People who dig these tags" public: title: "Public Activity" + contacts_title: "Recent Posters" users: logged_out: diff --git a/lib/base_stream.rb b/lib/base_stream.rb index e615acc02..e07077fe8 100644 --- a/lib/base_stream.rb +++ b/lib/base_stream.rb @@ -9,16 +9,16 @@ class BaseStream end def random_featured_user - Person.find_by_diaspora_handle(featured_diaspora_id) + @random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id) end def has_featured_users? - featured_diaspora_id.present? + random_featured_user.present? end #requied to implement said stream def link(opts={}) - Rails.application.routes.url_helpers.mentions_path(opts) + 'change me in lib/base_stream.rb!' end def can_comment?(post) @@ -26,15 +26,17 @@ class BaseStream end def title - 'a title' + 'change me in lib/base_stream.rb!' end def posts [] end + # @return [ActiveRecord::Association] AR association of people within stream's given aspects def people - [] + people_ids = posts.map{|x| x.author_id} + Person.where(:id => people_ids).includes(:profile) end def contacts_link_title @@ -42,11 +44,11 @@ class BaseStream end def contacts_title - "title for a stream" + 'change me in lib/base_stream.rb!' end def contacts_link - '#' + 'change me in lib/base_stream.rb!' end #helpers diff --git a/lib/stream/mention_stream.rb b/lib/stream/mention_stream.rb index fbf954ebb..069bad02d 100644 --- a/lib/stream/mention_stream.rb +++ b/lib/stream/mention_stream.rb @@ -17,11 +17,6 @@ class MentionStream< BaseStream @posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order) end - # @return [ActiveRecord::Association] AR association of people within stream's given aspects - def people - @people ||= posts.map{|p| p.author}.uniq - end - def contacts_title I18n.translate('streams.mentions.contacts_title') end diff --git a/lib/stream/public_stream.rb b/lib/stream/public_stream.rb index 59bc1d0d6..dbb813aa2 100644 --- a/lib/stream/public_stream.rb +++ b/lib/stream/public_stream.rb @@ -3,7 +3,6 @@ # the COPYRIGHT file. class PublicStream < BaseStream - def link(opts={}) Rails.application.routes.url_helpers.public_stream_path(opts) end @@ -12,19 +11,14 @@ class PublicStream < BaseStream I18n.translate("streams.public.title") end - # @return [ActiveRecord::Association] AR association of posts def posts @posts ||= Post.all_public.for_a_stream(max_time, order) end - # @return [ActiveRecord::Association] AR association of people within stream's given aspects - def people - @people ||= posts.map{|p| p.author}.uniq - end def contacts_title - "The last 15 people in this stream" + I18n.translate("streams.public.contacts_title") end def can_comment?(post) diff --git a/lib/stream/tag_stream.rb b/lib/stream/tag_stream.rb index fcec4e473..47ccc5ec4 100644 --- a/lib/stream/tag_stream.rb +++ b/lib/stream/tag_stream.rb @@ -20,10 +20,6 @@ class TagStream < BaseStream for_a_stream(@max_time, @order) end - def people - @people ||= posts.map{|p| p.author}.uniq - end - def contacts_title I18n.translate('streams.tags.contacts_title') end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 6e0da0ab4..df4ac9a0a 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -146,4 +146,23 @@ describe PostsController do StatusMessage.exists?(message.id).should be_true end end + + describe '#index' do + before do + sign_in alice + end + + it 'will succeed if admin' do + AppConfig[:admins] = [alice.username] + get :index + response.should be_success + end + + it 'will redirect if not' do + AppConfig[:admins] = [] + get :index + response.should be_redirect + end + + end end diff --git a/spec/lib/stream/public_stream_spec.rb b/spec/lib/stream/public_stream_spec.rb new file mode 100644 index 000000000..3d272ed09 --- /dev/null +++ b/spec/lib/stream/public_stream_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') +describe PublicStream do + before do + @stream = PublicStream.new(stub) + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end