Skip to content
Extraits de code Groupes Projets
Valider 226554be rédigé par Jonne Hass's avatar Jonne Hass
Parcourir les fichiers

auto follow back feature

parent 0e08c598
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -68,6 +68,12 @@ class UsersController < ApplicationController ...@@ -68,6 +68,12 @@ class UsersController < ApplicationController
else else
flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed' flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed'
end end
elsif u[:auto_follow_back]
if @user.update_attributes(u)
flash[:notice] = I18n.t 'users.update.follow_settings_changed'
else
flash[:error] = I18n.t 'users.update.follow_settings_not_changed'
end
end end
elsif aspect_order = params[:reorder_aspects] elsif aspect_order = params[:reorder_aspects]
@user.reorder_aspects(aspect_order) @user.reorder_aspects(aspect_order)
......
...@@ -79,4 +79,12 @@ LISTITEM ...@@ -79,4 +79,12 @@ LISTITEM
def dropdown_may_create_new_aspect def dropdown_may_create_new_aspect
@aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification || params[:action] == "getting_started" @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification || params[:action] == "getting_started"
end end
def aspect_options_for_select(aspects)
options = {}
aspects.each do |aspect|
options[aspect.to_s] = aspect.id
end
options
end
end end
...@@ -69,6 +69,7 @@ class Request ...@@ -69,6 +69,7 @@ class Request
end end
# Finds or initializes a corresponding [Contact], and will set Contact#sharing to true # Finds or initializes a corresponding [Contact], and will set Contact#sharing to true
# Follows back if user setting is set so
# @note A [Contact] may already exist if the [Request]'s recipient is sharing with the sender # @note A [Contact] may already exist if the [Request]'s recipient is sharing with the sender
# @return [Request] # @return [Request]
def receive(user, person) def receive(user, person)
...@@ -77,6 +78,8 @@ class Request ...@@ -77,6 +78,8 @@ class Request
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id) contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
contact.sharing = true contact.sharing = true
contact.save contact.save
user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back
self self
end end
......
...@@ -36,6 +36,7 @@ class User < ActiveRecord::Base ...@@ -36,6 +36,7 @@ class User < ActiveRecord::Base
has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id, :dependent => :destroy has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id, :dependent => :destroy
has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id, :dependent => :destroy has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id, :dependent => :destroy
has_many :aspects, :order => 'order_id ASC' has_many :aspects, :order => 'order_id ASC'
belongs_to :auto_follow_back_aspect, :class_name => 'Aspect'#, :foreign_key => 'auto_follow_back_aspect_id'
has_many :aspect_memberships, :through => :aspects has_many :aspect_memberships, :through => :aspects
has_many :contacts has_many :contacts
has_many :contact_people, :through => :contacts, :source => :person has_many :contact_people, :through => :contacts, :source => :person
...@@ -60,7 +61,9 @@ class User < ActiveRecord::Base ...@@ -60,7 +61,9 @@ class User < ActiveRecord::Base
:disable_mail, :disable_mail,
:invitation_service, :invitation_service,
:invitation_identifier, :invitation_identifier,
:show_community_spotlight_in_stream :show_community_spotlight_in_stream,
:auto_follow_back,
:auto_follow_back_aspect_id
def self.all_sharing_with_person(person) def self.all_sharing_with_person(person)
......
...@@ -90,6 +90,29 @@ ...@@ -90,6 +90,29 @@
%br %br
%hr %hr
%br %br
%h3#auto-follow-back-preferences
= t('.following')
= form_for current_user, :url => user_path, :html => { :method => :put } do |f|
= f.error_messages
%p.checkbox_select
= f.label :auto_follow_back, t('.auto_follow_back')
= f.check_box :auto_follow_back
%br
%p.checkbox_select
%span{:style => "color: #999"}
= t('.auto_follow_aspect')
= f.select :auto_follow_back_aspect_id, aspect_options_for_select(current_user.aspects)
%br
= f.submit t('.change'), :class => 'button'
%br
%br
%hr
%br
%h3#getting-started-preferences %h3#getting-started-preferences
= t('.show_getting_started') = t('.show_getting_started')
......
...@@ -944,6 +944,9 @@ en: ...@@ -944,6 +944,9 @@ en:
show_community_spotlight: "Show Community Spotlight in Stream?" show_community_spotlight: "Show Community Spotlight in Stream?"
show_getting_started: 'Re-enable Getting Started' show_getting_started: 'Re-enable Getting Started'
getting_started: 'New User Prefrences' getting_started: 'New User Prefrences'
following: "Following Settings"
auto_follow_back: "Automatically follow back if a someone follows you"
auto_follow_aspect: "Aspect for automatically followed users:"
privacy_settings: privacy_settings:
title: "Privacy Settings" title: "Privacy Settings"
...@@ -984,6 +987,8 @@ en: ...@@ -984,6 +987,8 @@ en:
email_notifications_changed: "Email notifications changed" email_notifications_changed: "Email notifications changed"
unconfirmed_email_changed: "Email changed. Needs activation." unconfirmed_email_changed: "Email changed. Needs activation."
unconfirmed_email_not_changed: "Email change failed" unconfirmed_email_not_changed: "Email change failed"
follow_settings_changed: "Follow settings changed"
follow_settings_not_changed: "Follow settings change failed."
public: public:
does_not_exist: "User %{username} does not exist!" does_not_exist: "User %{username} does not exist!"
confirm_email: confirm_email:
......
class AddAutoFollowBackToUsers < ActiveRecord::Migration
def self.up
add_column :users, :auto_follow_back, :boolean, :default => false
add_column :users, :auto_follow_back_aspect_id, :integer
end
def self.down
remove_column :users, :auto_follow_back
remove_column :users, :auto_follow_back_aspect
end
end
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
...@@ -11,7 +10,7 @@ ...@@ -11,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111101202137) do ActiveRecord::Schema.define(:version => 20111114173111) do
create_table "aspect_memberships", :force => true do |t| create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false t.integer "aspect_id", :null => false
...@@ -54,17 +53,17 @@ ActiveRecord::Schema.define(:version => 20111101202137) do ...@@ -54,17 +53,17 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
end end
create_table "comments", :force => true do |t| create_table "comments", :force => true do |t|
t.text "text", :null => false t.text "text", :null => false
t.integer "commentable_id", :null => false t.integer "commentable_id", :null => false
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.string "guid", :null => false t.string "guid", :null => false
t.text "author_signature" t.text "author_signature"
t.text "parent_author_signature" t.text "parent_author_signature"
t.text "youtube_titles" t.text "youtube_titles"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "likes_count", :default => 0, :null => false t.integer "likes_count", :default => 0, :null => false
t.string "commentable_type", :default => "Post", :null => false t.string "commentable_type", :limit => 60, :default => "Post", :null => false
end end
add_index "comments", ["author_id"], :name => "index_comments_on_person_id" add_index "comments", ["author_id"], :name => "index_comments_on_person_id"
...@@ -253,6 +252,7 @@ ActiveRecord::Schema.define(:version => 20111101202137) do ...@@ -253,6 +252,7 @@ ActiveRecord::Schema.define(:version => 20111101202137) 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 "photos", :force => true do |t| create_table "photos", :force => true do |t|
t.integer "tmp_old_id"
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.boolean "public", :default => false, :null => false t.boolean "public", :default => false, :null => false
t.string "diaspora_handle" t.string "diaspora_handle"
...@@ -371,12 +371,12 @@ ActiveRecord::Schema.define(:version => 20111101202137) do ...@@ -371,12 +371,12 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
add_index "services", ["user_id"], :name => "index_services_on_user_id" add_index "services", ["user_id"], :name => "index_services_on_user_id"
create_table "share_visibilities", :force => true do |t| create_table "share_visibilities", :force => true do |t|
t.integer "shareable_id", :null => false t.integer "shareable_id", :null => false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "hidden", :default => false, :null => false t.boolean "hidden", :default => false, :null => false
t.integer "contact_id", :null => false t.integer "contact_id", :null => false
t.string "shareable_type", :default => "Post", :null => false t.string "shareable_type", :limit => 60, :default => "Post", :null => false
end end
add_index "share_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id" add_index "share_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
...@@ -453,6 +453,8 @@ ActiveRecord::Schema.define(:version => 20111101202137) do ...@@ -453,6 +453,8 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
t.string "confirm_email_token", :limit => 30 t.string "confirm_email_token", :limit => 30
t.datetime "locked_at" t.datetime "locked_at"
t.boolean "show_community_spotlight_in_stream", :default => true, :null => false t.boolean "show_community_spotlight_in_stream", :default => true, :null => false
t.boolean "auto_follow_back", :default => false
t.integer "auto_follow_back_aspect_id"
end end
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
......
...@@ -92,6 +92,28 @@ describe Request do ...@@ -92,6 +92,28 @@ describe Request do
:into => eve.aspects.first).receive(alice, eve.person) :into => eve.aspects.first).receive(alice, eve.person)
alice.contact_for(eve.person).should be_sharing alice.contact_for(eve.person).should be_sharing
end end
it 'shares back if auto_following is enabled' do
alice.auto_follow_back = true
alice.auto_follow_back_aspect = alice.aspects.first
eve.save
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
eve.contact_for(alice.person).should be_sharing
end
it 'shares not back if auto_following is not enabled' do
alice.auto_follow_back = false
alice.auto_follow_back_aspect = alice.aspects.first
eve.save
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
eve.contact_for(alice.person).should be_nil
end
end end
context 'xml' do context 'xml' do
......
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