can now hide posts
This commit is contained in:
parent
fb8b8ab7fc
commit
5a9ec82597
15 changed files with 113 additions and 31 deletions
|
|
@ -7,13 +7,19 @@ class PostVisibilitiesController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@vis = ConversationVisibility.where(:person_id => current_user.person.id,
|
#note :id is garbage
|
||||||
:conversation_id => params[:conversation_id]).first
|
|
||||||
|
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
|
||||||
|
@contact = current_user.contact_for( @post.author)
|
||||||
|
@vis = PostVisibility.where(:contact_id => @contact.id,
|
||||||
|
:post_id => params[:post_id]).first
|
||||||
if @vis
|
if @vis
|
||||||
if @vis.destroy
|
@vis.hidden = true
|
||||||
flash[:notice] = "Conversation successfully removed"
|
if @vis.save
|
||||||
|
render :nothing => true, :status => 200
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to conversations_path
|
render :nothing => true, :status => 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class PostVisibility < ActiveRecord::Base
|
class PostVisibility < ActiveRecord::Base
|
||||||
|
default_scope where(:hidden => false)
|
||||||
|
|
||||||
belongs_to :contact
|
belongs_to :contact
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
- unless reshare_aspects.empty?
|
- unless reshare_aspects.empty?
|
||||||
= render 'shared/reshare', :aspects => reshare_aspects, :post => post
|
= render 'shared/reshare', :aspects => reshare_aspects, :post => post
|
||||||
= link_to image_tag('deletelabel.png'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete')
|
= link_to image_tag('deletelabel.png'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete')
|
||||||
|
- else
|
||||||
|
.right.controls
|
||||||
|
= link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('hide')
|
||||||
|
|
||||||
= person_image_link(post.author, :size => :thumb_small)
|
= person_image_link(post.author, :size => :thumb_small)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
%br
|
%br
|
||||||
- if current_user.owns? @status_message
|
- if current_user.owns? @status_message
|
||||||
= link_to t('.destroy'), @status_message, :confirm => t('are_you_sure'), :method => :delete
|
= link_to t('delete'), @status_message, :confirm => t('are_you_sure'), :method => :delete
|
||||||
|
- else
|
||||||
|
= link_to t('hide'), post_visibility_path(:id => "42", :post_id => post.id), :confirm => t('are_you_sure'), :method => :delete, :remote => true
|
||||||
|
|
||||||
.stream.show{:data=>{:guid=>@status_message.id}}
|
.stream.show{:data=>{:guid=>@status_message.id}}
|
||||||
= render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true
|
= render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ en:
|
||||||
ok: "OK"
|
ok: "OK"
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
|
hide: "Hide"
|
||||||
or: "or"
|
or: "or"
|
||||||
ago: "%{time} ago"
|
ago: "%{time} ago"
|
||||||
username: "Username"
|
username: "Username"
|
||||||
|
|
@ -432,6 +433,10 @@ en:
|
||||||
posts:
|
posts:
|
||||||
doesnt_exist: "that post does not exist!"
|
doesnt_exist: "that post does not exist!"
|
||||||
|
|
||||||
|
post_visibility:
|
||||||
|
destroy:
|
||||||
|
success: "Post successfully hidden"
|
||||||
|
|
||||||
profiles:
|
profiles:
|
||||||
edit:
|
edit:
|
||||||
your_public_profile: "Your public profile"
|
your_public_profile: "Your public profile"
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ Diaspora::Application.routes.draw do
|
||||||
|
|
||||||
resources :contacts, :except => [:index, :update]
|
resources :contacts, :except => [:index, :update]
|
||||||
resources :aspect_memberships, :only => [:destroy, :create, :update]
|
resources :aspect_memberships, :only => [:destroy, :create, :update]
|
||||||
|
resources :post_visibilities, :only => [:destroy]
|
||||||
|
|
||||||
resources :people, :except => [:edit, :update] do
|
resources :people, :except => [:edit, :update] do
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
class AddHiddenToPostVisibilities < ActiveRecord::Migration
|
class AddHiddenToPostVisibilities < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
add_column :post_visibilities, :hidden, :boolean, :defalut => false, :null => false
|
add_column :post_visibilities, :hidden, :boolean, :default => false, :null => false
|
||||||
|
add_index :post_visibilities, :hidden
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
|
add_index :post_visibilities, :hidden
|
||||||
remove_column :post_visibilities, :hidden
|
remove_column :post_visibilities, :hidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -212,15 +212,16 @@ ActiveRecord::Schema.define(:version => 20110330230206) do
|
||||||
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
||||||
|
|
||||||
create_table "post_visibilities", :force => true do |t|
|
create_table "post_visibilities", :force => true do |t|
|
||||||
t.integer "post_id", :null => false
|
t.integer "post_id", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.boolean "hidden", :null => false
|
t.boolean "hidden", :default => false, :null => false
|
||||||
t.integer "contact_id", :null => false
|
t.integer "contact_id", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "post_visibilities", ["contact_id", "post_id"], :name => "index_post_visibilities_on_contact_id_and_post_id", :unique => true
|
add_index "post_visibilities", ["contact_id", "post_id"], :name => "index_post_visibilities_on_contact_id_and_post_id", :unique => true
|
||||||
add_index "post_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
|
add_index "post_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
|
||||||
|
add_index "post_visibilities", ["hidden"], :name => "index_post_visibilities_on_hidden"
|
||||||
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
|
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
|
||||||
|
|
||||||
create_table "posts", :force => true do |t|
|
create_table "posts", :force => true do |t|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Feature: posting
|
||||||
|
|
||||||
Scenario: hide a post
|
Scenario: hide a post
|
||||||
Given I expand the publisher
|
Given I expand the publisher
|
||||||
When I fill in "status_message_fake_text" with "I am eating a yogurt"
|
When I fill in "status_message_fake_text" with "Here is a post for you to hide"
|
||||||
And I press "Share"
|
And I press "Share"
|
||||||
And I wait for the ajax to finish
|
And I wait for the ajax to finish
|
||||||
|
|
||||||
|
|
@ -36,10 +36,12 @@ Feature: posting
|
||||||
|
|
||||||
And I hover over the post
|
And I hover over the post
|
||||||
And I preemptively confirm the alert
|
And I preemptively confirm the alert
|
||||||
And I click to hide the first post
|
And I click to delete the first post
|
||||||
And I wait for the ajax to finish
|
And I wait for the ajax to finish
|
||||||
|
And I go to "bob@bob.bob"'s page
|
||||||
|
Then I should not see "Here is a post for you to hide"
|
||||||
And I follow "All Aspects"
|
And I follow "All Aspects"
|
||||||
Then I should not see "I am eating a yogurt"
|
Then I should not see "Here is a post for you to hide"
|
||||||
|
|
||||||
Scenario: delete a post
|
Scenario: delete a post
|
||||||
Given I expand the publisher
|
Given I expand the publisher
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,6 @@ When /^I click to delete the first post$/ do
|
||||||
page.execute_script('$(".stream_element").first().find(".stream_element_delete").click()')
|
page.execute_script('$(".stream_element").first().find(".stream_element_delete").click()')
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I click to hide the first post$/ do
|
|
||||||
page.execute_script('$(".stream_element").first().find(".stream_element_hide").click()')
|
|
||||||
end
|
|
||||||
|
|
||||||
When /^I click to delete the first comment$/ do
|
When /^I click to delete the first comment$/ do
|
||||||
page.execute_script('$(".comment.posted").first().find(".comment_delete").click()')
|
page.execute_script('$(".comment.posted").first().find(".comment_delete").click()')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,11 @@ module Diaspora
|
||||||
opts[:type] ||= ['StatusMessage', 'Photo']
|
opts[:type] ||= ['StatusMessage', 'Photo']
|
||||||
opts[:limit] ||= 20
|
opts[:limit] ||= 20
|
||||||
opts[:order] ||= 'updated_at DESC'
|
opts[:order] ||= 'updated_at DESC'
|
||||||
|
opts[:hidden] ||= false
|
||||||
opts[:order] = '`posts`.' + opts[:order]
|
opts[:order] = '`posts`.' + opts[:order]
|
||||||
opts[:limit] = opts[:limit].to_i * opts[:page].to_i if opts[:page]
|
opts[:limit] = opts[:limit].to_i * opts[:page].to_i if opts[:page]
|
||||||
|
|
||||||
posts_from_others = Post.joins(:contacts).where(:contacts => {:user_id => self.id})
|
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
|
||||||
posts_from_self = self.person.posts.joins(:aspect_visibilities => :aspect).where(:aspects => {:user_id => self.id})
|
posts_from_self = self.person.posts.joins(:aspect_visibilities => :aspect).where(:aspects => {:user_id => self.id})
|
||||||
|
|
||||||
if opts[:by_members_of]
|
if opts[:by_members_of]
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ var Stream = {
|
||||||
var $stream = $(".stream");
|
var $stream = $(".stream");
|
||||||
var $publisher = $("#publisher");
|
var $publisher = $("#publisher");
|
||||||
|
|
||||||
|
$(".status_message_delete").tipsy({trigger: 'hover', gravity: 'n'});
|
||||||
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
$stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
|
$stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
|
||||||
//audio linx
|
//audio linx
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ describe AspectsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@bob = bob
|
||||||
@alice = alice
|
@alice = alice
|
||||||
@alice.getting_started = false
|
@alice.getting_started = false
|
||||||
@alice.save
|
@alice.save
|
||||||
|
|
@ -107,6 +108,23 @@ describe AspectsController do
|
||||||
@alice.build_comment('lalala', :on => @posts.first ).save
|
@alice.build_comment('lalala', :on => @posts.first ).save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "post visibilities" do
|
||||||
|
before do
|
||||||
|
@status = @bob.post(:status_message, :text=> "hello", :to => @bob.aspects.first)
|
||||||
|
@vis = @status.post_visibilities.first
|
||||||
|
end
|
||||||
|
|
||||||
|
it "pulls back non hidden posts" do
|
||||||
|
get :index
|
||||||
|
assigns[:posts].include?(@status).should be_true
|
||||||
|
end
|
||||||
|
it "does not pull back hidden posts" do
|
||||||
|
@vis.update_attributes( :hidden => true )
|
||||||
|
get :index
|
||||||
|
assigns[:posts].include?(@status).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "ordering" do
|
describe "ordering" do
|
||||||
it "orders posts by updated_at by default" do
|
it "orders posts by updated_at by default" do
|
||||||
get :index
|
get :index
|
||||||
|
|
|
||||||
|
|
@ -9,28 +9,47 @@ describe PostVisibilitiesController do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@user1 = alice
|
@user1 = alice
|
||||||
|
@bob = bob
|
||||||
sign_in :user, @user1
|
sign_in :user, @user1
|
||||||
|
|
||||||
|
a2 = bob.aspects.create(:name => "two")
|
||||||
|
a2.contacts << bob.contact_for(alice.person)
|
||||||
|
a2.save
|
||||||
|
|
||||||
|
|
||||||
status = @user1.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
@status = bob.post(:status_message, :text => "hello", :public => true, :to => a2)
|
||||||
@vis = status.post_visibilities.first
|
@vis = @status.post_visibilities.first
|
||||||
pp @vis
|
|
||||||
@vis.reload.hidden.should == false
|
@vis.reload.hidden.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
it 'deletes the visibility' do
|
context "on a post you can see" do
|
||||||
delete :destroy, :conversation_id => @vis.id
|
it 'succeeds' do
|
||||||
@vis.reload.hidden.should == true
|
delete :destroy, :id => 42, :post_id => @status.id
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes the visibility' do
|
||||||
|
delete :destroy, :id => 42, :post_id => @status.id
|
||||||
|
@vis.reload.hidden.should == true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not let a user destroy a visibility that is not theirs' do
|
context "post you do not see" do
|
||||||
user2 = eve
|
before do
|
||||||
sign_in :user, user2
|
user2 = eve
|
||||||
|
sign_in :user, user2
|
||||||
lambda {
|
end
|
||||||
delete :destroy, :conversation_id => @vis.id
|
it 'does not let a user destroy a visibility that is not theirs' do
|
||||||
}.should_not change(@vis.reload, :hidden).to(true)
|
lambda {
|
||||||
|
delete :destroy, :id => 42, :post_id => @status.id
|
||||||
|
}.should_not change(@vis.reload, :hidden).to(true)
|
||||||
|
end
|
||||||
|
it 'does not succceed' do
|
||||||
|
delete :destroy, :id => 42, :post_id => @status.id
|
||||||
|
response.should_not be_success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
22
spec/models/post_visibility_spec.rb
Normal file
22
spec/models/post_visibility_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
#
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe PostVisibility do
|
||||||
|
before do
|
||||||
|
@alice = alice
|
||||||
|
@bob = bob
|
||||||
|
|
||||||
|
@status = @alice.post(:status_message, :text => "hello", :public => true, :to => @alice.aspects.first)
|
||||||
|
@vis = @status.post_visibilities.first
|
||||||
|
@vis.hidden = true
|
||||||
|
@vis.save
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is default scoped to not-hidden' do
|
||||||
|
PostVisibility.where(:id => @vis.id).should == []
|
||||||
|
PostVisibility.unscoped.where(:id => @vis.id).should == [@vis]
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue