Merge branch 'stable' into develop

This commit is contained in:
Jonne Haß 2015-06-21 20:48:57 +02:00
commit 188e554b7b
9 changed files with 127 additions and 13 deletions

View file

@ -57,6 +57,7 @@ bind to an UNIX socket at `unix:tmp/diaspora.sock`. Please change your local
## Features
* Add configuration options for some debug logs [#6090](https://github.com/diaspora/diaspora/pull/6090)
* Send new users a welcome message from the podmin [#6128](https://github.com/diaspora/diaspora/pull/6128)
# 0.5.1.1

View file

@ -14,6 +14,7 @@ class RegistrationsController < Devise::RegistrationsController
if @user.sign_up
flash[:notice] = I18n.t 'registrations.create.success'
@user.seed_aspects
@user.send_welcome_message
sign_in_and_redirect(:user, @user)
logger.info "event=registration status=successful user=#{@user.diaspora_handle}"
else

View file

@ -24,7 +24,8 @@ class Conversation < ActiveRecord::Base
def local_recipients
recipients.each do |recipient|
if recipient.local?
if recipient.owner.contacts.where(:person_id => self.author.id).count == 0
unless recipient.owner.contacts.where(person_id: author.id).any? ||
(author.owner && author.owner.podmin_account?)
errors.add(:all_recipients, "recipient not allowed")
end
end

View file

@ -468,6 +468,19 @@ class User < ActiveRecord::Base
aq
end
def send_welcome_message
return unless AppConfig.settings.welcome_message.enabled? && AppConfig.admins.account?
sender_username = AppConfig.admins.account.get
sender = User.find_by(username: sender_username)
conversation = sender.build_conversation(
participant_ids: [sender.person.id, person.id],
subject: AppConfig.settings.welcome_message.subject.get,
message: {text: AppConfig.settings.welcome_message.text.get % {username: username}})
if conversation.save
Postzord::Dispatcher.build(sender, conversation).post
end
end
def encryption_key
OpenSSL::PKey::RSA.new(serialized_private_key)
end
@ -476,6 +489,10 @@ class User < ActiveRecord::Base
Role.is_admin?(self.person)
end
def podmin_account?
username == AppConfig.admins.account
end
def mine?(target)
if target.present? && target.respond_to?(:user_id)
return self.id == target.user_id

View file

@ -99,6 +99,10 @@ defaults:
enable_registrations: true
autofollow_on_join: true
autofollow_on_join_user: 'diasporahq@joindiaspora.com'
welcome_message:
enabled: false
subject: 'Welcome Message'
text: 'Hello %{username}, welcome to diaspora*.'
invitations:
open: true
count: 25

View file

@ -410,6 +410,26 @@ configuration: ## Section
## please consider resharing diaspora* HQ's posts for your pod's users!
#autofollow_on_join_user: 'diasporahq@joindiaspora.com'
## Welcome Message settings
welcome_message: ##Section
## Welcome Message on registration (default=false)
## Send a message to new users after registration
## to tell them about your pod and how things
## are handled on it.
#enabled: false
## Welcome Message subject (default='Welcome Message')
## The subject of the conversation that is started
## by your welcome message.
#subject: "Welcome Message"
## Welcome Message text (default='Hello %{username}, welcome to diaspora.')
## The content of your welcome message.
## The placeholder "%{username}" will be replaced by the username
## of the new user.
#text: "Hello %{username}, welcome to diaspora."
## Invitation settings
invitations: ## Section

View file

@ -85,7 +85,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
end
def contact_required_unless_request
unless @object.is_a?(Request) || @user.contact_for(@author)
unless @object.is_a?(Request) || @user.contact_for(@author) || (@author.owner && @author.owner.podmin_account?)
logger.error "event=receive status=abort reason='sender not connected to recipient' type=#{@object.class} " \
"recipient=#{@user_person.diaspora_handle} sender=#{@author.diaspora_handle}"
return true

View file

@ -134,19 +134,41 @@ describe Conversation, :type => :model do
end
end
describe '#invalid parameters' do
describe "#invalid parameters" do
context "local author" do
before do
@invalid_hash = {
:author => peter.person,
:participant_ids => [peter.person.id, @user1.person.id],
:subject => "cool stuff",
:messages_attributes => [ {:author => peter.person, :text => 'hey'} ]
author: peter.person,
participant_ids: [peter.person.id, @user1.person.id],
subject: "cool stuff",
messages_attributes: [{author: peter.person, text: "hey"}]
}
end
it 'with invalid recipient' do
it "is invalid with invalid recipient" do
conversation = Conversation.create(@invalid_hash)
expect(conversation).to be_invalid
end
end
context "remote author" do
before do
@remote_person = remote_raphael
@local_user = alice
@participant_ids = [@remote_person.id, @local_user.person.id]
@invalid_hash_remote = {
author: @remote_person,
participant_ids: @participant_ids,
subject: "cool stuff",
messages_attributes: [{author: @remote_person, text: "hey"}]
}
end
it "is invalid with invalid recipient" do
conversation = Conversation.create(@invalid_hash_remote)
expect(conversation).to be_invalid
end
end
end
end

View file

@ -934,6 +934,54 @@ describe User, :type => :model do
end
end
describe "#send_welcome_message" do
let(:user) { FactoryGirl.create(:user) }
let(:podmin) { FactoryGirl.create(:user) }
context "with welcome message enabled" do
before do
AppConfig.settings.welcome_message.enabled = true
end
it "should send welcome message from podmin account" do
AppConfig.admins.account = podmin.username
expect {
user.send_welcome_message
}.to change(user.conversations, :count).by(1)
expect(user.conversations.first.author.owner.username).to eq podmin.username
end
it "should send welcome message text from config" do
AppConfig.admins.account = podmin.username
AppConfig.settings.welcome_message.text = "Hello %{username}, welcome!"
user.send_welcome_message
expect(user.conversations.first.messages.first.text).to eq "Hello #{user.username}, welcome!"
end
it "should use subject from config" do
AppConfig.settings.welcome_message.subject = "Welcome Message"
AppConfig.admins.account = podmin.username
user.send_welcome_message
expect(user.conversations.first.subject).to eq "Welcome Message"
end
it "should send no welcome message if no podmin is specified" do
AppConfig.admins.account = ""
user.send_welcome_message
expect(user.conversations.count).to eq 0
end
end
context "with welcome message disabled" do
it "shouldn't send a welcome message" do
AppConfig.settings.welcome_message.enabled = false
AppConfig.admins.account = podmin.username
user.send_welcome_message
expect(user.conversations.count).to eq 0
end
end
end
context "close account" do
before do
@user = bob