Skip to content
Extraits de code Groupes Projets
Valider 10ce4426 rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

Merge branch 'block-user'

parents 609894fb b56dc920
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 149 ajouts et 38 suppressions
......@@ -154,7 +154,7 @@ class ApplicationController < ActionController::Base
@stream = stream_klass.new(current_user, :max_time => max_time, :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
else
render 'aspects/index'
end
......
......@@ -46,12 +46,11 @@ class AspectMembershipsController < ApplicationController
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
if @contact = current_user.share_with(@person, @aspect)
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
flash.now[:notice] = I18n.t('aspects.add_to_aspect.success')
respond_with AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first
else
flash[:error] = I18n.t 'contacts.create.failure'
#TODO(dan) take this out once the .js template is removed
render :nothing => true
flash.now[:error] = I18n.t('contacts.create.failure')
render :nothing => true, :status => 409
end
end
......
......@@ -20,7 +20,7 @@ class AspectsController < ApplicationController
:max_time => params[:max_time].to_i)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
end
end
......
class BlocksController < ApplicationController
before_filter :authenticate_user!
def create
block = current_user.blocks.new(params[:block])
if block.save
disconnect_if_contact(block.person)
notice = {:notice => t('blocks.create.success')}
else
notice = {:error => t('blocks.create.failure')}
end
redirect_to :back, notice
end
def destroy
if current_user.blocks.find(params[:id]).delete
notice = {:notice => t('blocks.destroy.success')}
else
notice = {:error => t('blocks.destroy.failure')}
end
redirect_to :back, notice
end
protected
def disconnect_if_contact(person)
if contact = current_user.contact_for(person)
current_user.disconnect(contact, :force => true)
end
end
end
......@@ -95,6 +95,7 @@ class PeopleController < ApplicationController
unless params[:format] == "json" # hovercard
if current_user
@block = current_user.blocks.where(:person_id => @person.id).first
@contact = current_user.contact_for(@person)
@aspects_with_person = []
if @contact && !params[:only_posts]
......@@ -112,7 +113,7 @@ class PeopleController < ApplicationController
end
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
else
respond_to do |format|
format.all { respond_with @person, :locals => {:post_type => :all} }
......
......@@ -38,7 +38,7 @@ class TagsController < ApplicationController
@stream = Stream::Tag.new(current_user, params[:name], :max_time => max_time, :page => params[:page])
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
return
end
end
......
......@@ -20,6 +20,10 @@ class UsersController < ApplicationController
end
end
def privacy_settings
@blocks = current_user.blocks.includes(:person)
end
def update
password_changed = false
@user = current_user
......
module StreamElementHelper
def block_user_control(author)
if user_signed_in? && current_user.person.id != author.id
link_to image_tag('deletelabel.png'), blocks_path(:block => {:person_id => author.id}),
:class => 'block_user delete',
:confirm => t('.ignore_user_description'),
:title => t('.ignore_user', :name => author.first_name),
:method => :post
end
end
def delete_or_hide_button(post)
if user_signed_in? && current_user.owns?(post)
link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete remove_post", :title => t('delete')
else
link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete remove_post vis_hide", :title => t('.hide_and_mute')
end
end
end
......@@ -10,15 +10,15 @@ module StreamHelper
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
elsif controller.instance_of?(PeopleController)
person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream))
elsif controller.instance_of?(TagFollowingsController)
elsif controller.instance_of?(TagFollowingsController)
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(CommunitySpotlightController)
elsif controller.instance_of?(CommunitySpotlightController)
spotlight_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(MentionsController)
elsif controller.instance_of?(MentionsController)
mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(MultisController)
elsif controller.instance_of?(MultisController)
multi_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(PostsController)
elsif controller.instance_of?(PostsController)
public_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(AspectsController)
aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids, :sort_order => session[:sort_order])
......@@ -28,15 +28,14 @@ module StreamHelper
end
def time_for_scroll(ajax_stream, stream)
if ajax_stream || stream.posts.empty?
if ajax_stream || stream.stream_posts.empty?
(Time.now() + 1).to_i
else
stream.posts.last.send(stream.order.to_sym).to_i
stream.stream_posts.last.send(stream.order.to_sym).to_i
end
end
def time_for_sort post
def time_for_sort(post)
if controller.instance_of?(AspectsController)
post.send(session[:sort_order].to_sym)
else
......
class Block < ActiveRecord::Base
belongs_to :person
belongs_to :user
validates :user_id, :presence => true
validates :person_id, :presence => true, :uniqueness => { :scope => :user_id }
validate :not_blocking_yourself
def not_blocking_yourself
if self.user.person.id == self.person_id
errors[:person_id] << "stop blocking yourself!"
end
end
end
\ No newline at end of file
......@@ -15,11 +15,13 @@ class Contact < ActiveRecord::Base
has_many :share_visibilities, :source => :shareable, :source_type => 'Post'
has_many :posts, :through => :share_visibilities, :source => :shareable, :source_type => 'Post'
validate :not_contact_for_self
validate :not_contact_for_self,
:not_blocked_user
validates_uniqueness_of :person_id, :scope => :user_id
before_destroy :destroy_notifications
before_destroy :destroy_notifications,
:repopulate_cache!
# contact.sharing is true when contact.person is sharing with contact.user
scope :sharing, lambda {
......@@ -39,7 +41,14 @@ class Contact < ActiveRecord::Base
Notification.where(:target_type => "Person",
:target_id => person_id,
:recipient_id => user_id,
:type => "Notifications::StartedSharing").delete_all
:type => "Notifications::StartedSharing").delete_all
end
def repopulate_cache!
if RedisCache.configured?
cache = RedisCache.new(self.user)
cache.repopulate!
end
end
def dispatch_request
......@@ -90,5 +99,14 @@ class Contact < ActiveRecord::Base
errors[:base] << 'Cannot create self-contact'
end
end
def not_blocked_user
if user.blocks.where(:person_id => person_id).exists?
errors[:base] << 'Cannot connect to an ignored user'
false
else
true
end
end
end
......@@ -21,11 +21,25 @@ class Post < ActiveRecord::Base
after_create :cache_for_author
#scopes
scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message
scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message
def self.for_a_stream(max_time, order)
self.for_visible_shareable_sql(max_time, order).
includes_for_a_stream
def self.excluding_blocks(user)
people = user.blocks.includes(:person).map{|b| b.person}
if people.present?
where("posts.author_id NOT IN (?)", people.map { |person| person.id })
else
scoped
end
end
def self.for_a_stream(max_time, order, user=nil)
scope = self.for_visible_shareable_sql(max_time, order).
includes_for_a_stream
scope = scope.excluding_blocks(user) if user.present?
scope
end
#############
......
......@@ -37,8 +37,7 @@ class StatusMessage < Post
def self.tag_stream(user, tag_array, max_time, order)
owned_or_visible_by_user(user).
joins(:tags).where(:tags => {:name => tag_array}).
for_a_stream(max_time, order)
joins(:tags).where(:tags => {:name => tag_array})
end
def text(opts = {})
......
......@@ -18,7 +18,7 @@ class User < ActiveRecord::Base
before_validation :strip_and_downcase_username
before_validation :set_current_language, :on => :create
validates :username, :presence => true, :uniqueness => true
validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
validates_length_of :username, :maximum => 32
......@@ -43,6 +43,7 @@ class User < ActiveRecord::Base
has_many :user_preferences, :dependent => :destroy
has_many :tag_followings, :dependent => :destroy
has_many :followed_tags, :through => :tag_followings, :source => :tag, :order => 'tags.name'
has_many :blocks
has_many :authorizations, :class_name => 'OAuth2::Provider::Models::ActiveRecord::Authorization', :foreign_key => :resource_owner_id
has_many :applications, :through => :authorizations, :source => :client
......
......@@ -19,8 +19,8 @@
#gs-shim{:title => "3. #{t('.stay_updated')}", 'data-content' => t('.stay_updated_explanation')}
#main_stream.stream{:data => {:guids => stream.aspect_ids.join(','), :time_for_scroll => time_for_scroll(stream.ajax_stream?, stream)}}
- if !stream.ajax_stream? && stream.posts.length > 0
= render 'shared/stream', :posts => stream.posts
- if !stream.ajax_stream? && stream.stream_posts.length > 0
= render 'shared/stream', :posts => stream.stream_posts
#pagination
=link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?), :class => 'paginate')
......
......@@ -9,8 +9,8 @@
= @stream.aspect
#main_stream.stream
= render 'shared/stream', :posts => @stream.posts
-if @stream.posts.length > 0
= render 'shared/stream', :posts => @stream.stream_posts
-if @stream.stream_posts.length > 0
#pagination
%a.more-link.paginate{:href => next_page_path}
%h1
......
#author_info
.right
- if user_signed_in? && current_user.person != person
= aspect_membership_dropdown(contact, person, 'right')
- if @block.present?
= link_to t('users.privacy_settings.stop_ignoring'), block_path(@block),
:method => :delete,
:class => "button"
- else
= aspect_membership_dropdown(contact, person, 'right')
- elsif user_signed_in? && current_user.person == person
= link_to t('people.profile_sidebar.edit_my_profile'), edit_profile_path, :class => 'button creation'
......
......@@ -27,17 +27,20 @@
= render 'people/sub_header', :person => @person, :contact => @contact
/ hackity hack until we get a photo stream
- if (@posts && @posts.length > 0) || (defined?(@stream) && @stream.posts.length > 0)
- if (@posts && @posts.length > 0) || @stream.stream_posts.length > 0
-if @post_type == :photos
= render 'photos/index', :photos => @posts
- else
#main_stream.stream
= render 'shared/stream', :posts => @stream.posts
= render 'shared/stream', :posts => @stream.stream_posts
#pagination
=link_to(t('more'), next_page_path, :class => 'paginate')
- else
#main_stream
%div{:style=>"text-align:center;", :class => "dull"}
= t('.has_not_shared_with_you_yet', :name => @person.first_name)
- if @block.present?
= t('.ignoring', :name => @person.first_name)
- else
= t('.has_not_shared_with_you_yet', :name => @person.first_name)
......@@ -20,12 +20,12 @@
= link_to t('.return_to_aspects'), aspects_manage_path
= t('.to_accept_or_ignore')
- if @stream.posts.length > 0
- if @stream.stream_posts.length > 0
-if @post_type == :photos
= render 'photos/index', :photos => @stream.posts
= render 'photos/index', :photos => @stream.stream_posts
- else
#main_stream.stream
= render 'shared/stream', :posts => @stream.posts
= render 'shared/stream', :posts => @stream.stream_posts
#pagination
=link_to(t('more'), next_page_path, :class => 'paginate')
- else
......
%ul#settings_nav
%li= link_to_unless_current t('profile'), edit_profile_path
%li= link_to_unless_current t('account'), edit_user_path
%li= link_to_unless_current t('privacy'), privacy_settings_path
%li= link_to_unless_current t('_services'), services_path
%li= link_to_unless_current t('_applications'), authorizations_path
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter