Don't send "Follows" notification on request friendship (#5526)

* Don't send "Follows" notification on request friendship

* Fixed tests

* Fixed tests

* Fixed tests, reduce count without following emails

Co-authored-by: Lucas Bartholemy <lucas@bartholemy.com>
This commit is contained in:
Yuriy Bakhtin 2022-02-04 23:13:42 +03:00 committed by GitHub
parent 5a239af7d9
commit 6e831f5428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View File

@ -5,6 +5,7 @@ HumHub Changelog
-------------------
- Fix #5480: `el` language file in Admin section broken
- Fix #5479: Fix ContentContainerPermissionAccess without provided container
- Fix #5517: Don't send "Follows" notification on request friendship
1.10.3 (December 20, 2021)

View File

@ -27,7 +27,7 @@ class FriendshipTest extends HumHubDbTestCase
// Request Friendship
$this->assertTrue(Friendship::add(Yii::$app->user->getIdentity(), $friendUser));
$this->assertMailSent(2, 'Friendship request mail sent.');
$this->assertMailSent(1, 'Friendship request mail sent.');
$fiendship = Friendship::findOne(['user_id' => Yii::$app->user->id, 'friend_user_id' => 2]);
$this->assertNotNull($fiendship, 'Friendship model persisted.');
@ -37,7 +37,7 @@ class FriendshipTest extends HumHubDbTestCase
// Accept friendship
$this->assertTrue(Friendship::add($friendUser, Yii::$app->user->getIdentity()));
$this->assertEquals(Friendship::getStateForUser($friendUser, Yii::$app->user->getIdentity()), Friendship::STATE_FRIENDS, 'Check Friend Status');
$this->assertMailSent(4, 'Friendship acknowledged mail sent.');
$this->assertMailSent(2, 'Friendship acknowledged mail sent.');
}
public function testDeclineFriendShip()
@ -51,7 +51,7 @@ class FriendshipTest extends HumHubDbTestCase
// Request Friendship
$this->assertTrue(Friendship::add(Yii::$app->user->getIdentity(), $friendUser));
$this->assertMailSent(2, 'Friendship request mail sent.');
$this->assertMailSent(1, 'Friendship request mail sent.');
$fiendship = Friendship::findOne(['user_id' => Yii::$app->user->id, 'friend_user_id' => 2]);
$this->assertNotNull($fiendship, 'Friendship model persisted.');
@ -61,6 +61,6 @@ class FriendshipTest extends HumHubDbTestCase
// Cancel request
Friendship::cancel($friendUser, Yii::$app->user->getIdentity());
$this->assertEquals(Friendship::getStateForUser($friendUser, Yii::$app->user->getIdentity()), Friendship::STATE_NONE, 'Check Friend Status');
$this->assertMailSent(3, 'Friendship acknowledged mail sent.');
$this->assertMailSent(2, 'Friendship acknowledged mail sent.');
}
}

View File

@ -103,7 +103,7 @@ class ProfileController extends ContentContainerController
}
$this->forcePostRequest();
$this->getUser()->follow(Yii::$app->user->getIdentity(), false);
$this->getUser()->follow(Yii::$app->user->getIdentity());
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';

View File

@ -96,7 +96,7 @@ class Follow extends ActiveRecord
*/
public function afterSave($insert, $changedAttributes)
{
if ($insert && $this->object_model == User::class) {
if ($insert && $this->send_notifications && $this->object_model == User::class) {
Followed::instance()
->from($this->user)
->about($this)