Merge branch 'stable' into develop
This commit is contained in:
commit
188e554b7b
9 changed files with 127 additions and 13 deletions
|
|
@ -57,6 +57,7 @@ bind to an UNIX socket at `unix:tmp/diaspora.sock`. Please change your local
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Add configuration options for some debug logs [#6090](https://github.com/diaspora/diaspora/pull/6090)
|
* 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
|
# 0.5.1.1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
if @user.sign_up
|
if @user.sign_up
|
||||||
flash[:notice] = I18n.t 'registrations.create.success'
|
flash[:notice] = I18n.t 'registrations.create.success'
|
||||||
@user.seed_aspects
|
@user.seed_aspects
|
||||||
|
@user.send_welcome_message
|
||||||
sign_in_and_redirect(:user, @user)
|
sign_in_and_redirect(:user, @user)
|
||||||
logger.info "event=registration status=successful user=#{@user.diaspora_handle}"
|
logger.info "event=registration status=successful user=#{@user.diaspora_handle}"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ class Conversation < ActiveRecord::Base
|
||||||
def local_recipients
|
def local_recipients
|
||||||
recipients.each do |recipient|
|
recipients.each do |recipient|
|
||||||
if recipient.local?
|
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")
|
errors.add(:all_recipients, "recipient not allowed")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -468,6 +468,19 @@ class User < ActiveRecord::Base
|
||||||
aq
|
aq
|
||||||
end
|
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
|
def encryption_key
|
||||||
OpenSSL::PKey::RSA.new(serialized_private_key)
|
OpenSSL::PKey::RSA.new(serialized_private_key)
|
||||||
end
|
end
|
||||||
|
|
@ -476,6 +489,10 @@ class User < ActiveRecord::Base
|
||||||
Role.is_admin?(self.person)
|
Role.is_admin?(self.person)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def podmin_account?
|
||||||
|
username == AppConfig.admins.account
|
||||||
|
end
|
||||||
|
|
||||||
def mine?(target)
|
def mine?(target)
|
||||||
if target.present? && target.respond_to?(:user_id)
|
if target.present? && target.respond_to?(:user_id)
|
||||||
return self.id == target.user_id
|
return self.id == target.user_id
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,10 @@ defaults:
|
||||||
enable_registrations: true
|
enable_registrations: true
|
||||||
autofollow_on_join: true
|
autofollow_on_join: true
|
||||||
autofollow_on_join_user: 'diasporahq@joindiaspora.com'
|
autofollow_on_join_user: 'diasporahq@joindiaspora.com'
|
||||||
|
welcome_message:
|
||||||
|
enabled: false
|
||||||
|
subject: 'Welcome Message'
|
||||||
|
text: 'Hello %{username}, welcome to diaspora*.'
|
||||||
invitations:
|
invitations:
|
||||||
open: true
|
open: true
|
||||||
count: 25
|
count: 25
|
||||||
|
|
|
||||||
|
|
@ -410,6 +410,26 @@ configuration: ## Section
|
||||||
## please consider resharing diaspora* HQ's posts for your pod's users!
|
## please consider resharing diaspora* HQ's posts for your pod's users!
|
||||||
#autofollow_on_join_user: 'diasporahq@joindiaspora.com'
|
#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
|
## Invitation settings
|
||||||
invitations: ## Section
|
invitations: ## Section
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_required_unless_request
|
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} " \
|
logger.error "event=receive status=abort reason='sender not connected to recipient' type=#{@object.class} " \
|
||||||
"recipient=#{@user_person.diaspora_handle} sender=#{@author.diaspora_handle}"
|
"recipient=#{@user_person.diaspora_handle} sender=#{@author.diaspora_handle}"
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -134,19 +134,41 @@ describe Conversation, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#invalid parameters' do
|
describe "#invalid parameters" do
|
||||||
before do
|
context "local author" do
|
||||||
@invalid_hash = {
|
before do
|
||||||
:author => peter.person,
|
@invalid_hash = {
|
||||||
:participant_ids => [peter.person.id, @user1.person.id],
|
author: peter.person,
|
||||||
:subject => "cool stuff",
|
participant_ids: [peter.person.id, @user1.person.id],
|
||||||
:messages_attributes => [ {:author => peter.person, :text => 'hey'} ]
|
subject: "cool stuff",
|
||||||
}
|
messages_attributes: [{author: peter.person, text: "hey"}]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is invalid with invalid recipient" do
|
||||||
|
conversation = Conversation.create(@invalid_hash)
|
||||||
|
expect(conversation).to be_invalid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'with invalid recipient' do
|
context "remote author" do
|
||||||
conversation = Conversation.create(@invalid_hash)
|
before do
|
||||||
expect(conversation).to be_invalid
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -934,6 +934,54 @@ describe User, :type => :model do
|
||||||
end
|
end
|
||||||
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
|
context "close account" do
|
||||||
before do
|
before do
|
||||||
@user = bob
|
@user = bob
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue