diff --git a/privatemsg.module b/privatemsg.module index 995b97b..cde606c 100644 --- a/privatemsg.module +++ b/privatemsg.module @@ -1421,6 +1421,13 @@ function privatemsg_privatemsg_block_message($author, $recipients, $context = ar 'message' => t('%recipient has disabled private message receiving.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), ); } + // Do not send private messages to blocked users. + else if (isset($recipient->status) && (!$recipient->status)) { + $blocked[] = array( + 'recipient' => 'user_' . $recipient->uid, + 'message' => t('%recipient has disabled his or her account.', array('%recipient' => privatemsg_recipient_format($recipient, array('plain' => TRUE)))), + ); + } } return $blocked; diff --git a/privatemsg.test b/privatemsg.test index 8e15c98..cc236d9 100644 --- a/privatemsg.test +++ b/privatemsg.test @@ -76,7 +76,8 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { * Create user with 'read privatemsg' permission. Try to access mailbox and see if it gives allows access */ function testPrivatemsgReadPrivatemsgPermission() { - $user_no_read_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission + // Set up a user with the default permissions. + $user_no_read_msg = $this->drupalCreateUser(); $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg')); $recipient = $this->drupalCreateUser(array('read privatemsg')); $no_recipient = $this->drupalCreateUser(array('read privatemsg')); @@ -112,12 +113,15 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { * Create user with 'write privatemsg' permission. Try to access Write New Message page and see if it gives allows access */ function testPrivatemsgWritePrivatemsgPermission() { - $user_no_write_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission + // Set up a user with the default permissions (no "read privatemsg" + // permission). + $user_no_write_msg = $this->drupalCreateUser(); $this->drupalLogin($user_no_write_msg); $this->drupalGet('messages/new'); $this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user without "write privatemsg" permission')); - $user_write_msg = $this->drupalCreateUser(array('write privatemsg')); // set up user with write privatemsg permissions + // Set up a user with "write privatemsg" permissions. + $user_write_msg = $this->drupalCreateUser(array('write privatemsg')); $this->drupalLogin($user_write_msg); $this->drupalGet('messages/new'); $this->assertResponse(200, t('HTTP Response 200: Access to Write New Message page was authorized to user with "write privatemsg" permission')); @@ -242,6 +246,11 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $author = $this->drupalCreateUser(array('write privatemsg', 'select text format for privatemsg', filter_permission_name(filter_format_load('full_html')))); $recipient = $this->drupalCreateUser(array('read privatemsg')); $recipient2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); + // Set up a user with "read/write privatemsg" permissions. + $blocked_recipient = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); + // Block one of the recipients to make sure that no messages are delivered + // to invalid recipients. + user_save($blocked_recipient, array('status' => 0)); // Login author and go to new message form. $this->drupalLogin($author); @@ -271,6 +280,12 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { 'subject' => $this->randomName(20), 'body[value]' => $this->randomName(100), ); + // Blocked recipient + $editblocked = array( + 'recipient' => $blocked_recipient, + 'subject' => $this->randomName(20), + 'body[value]' => $this->randomName(100), + ); // Empty body. $editnobody = array( 'recipient' => $recipient->name, @@ -324,6 +339,10 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $this->assertText(t('You must include at least one valid recipient.'), 'Message was not sent.'); $this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $editinvalid['recipient'])), 'Message about non-existing user displayed.'); + $this->drupalPost('messages/new', $editblocked, t('Send message')); + $this->assertText(t('%recipient has disabled his or her account.', array('%recipient' => $editblocked->name)), 'Message about blocked user displayed.'); + $this->assertText(t('You are not allowed to send this message because all recipients are blocked.'), 'Message was not sent.'); + $this->drupalPost('messages/new', $editnobody, t('Send message')); $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.'); @@ -416,6 +435,14 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $this->assertText($edit2['body[value]'], 'Found message body.'); // Confirm that we can read the reply that was sent. $this->assertText($reply['body[value]'], 'Found reply body.'); + + // Block the author. + user_save($author, array('status' => 0)); + // Navigate into the message. + $this->drupalGet('messages'); + $this->clickLink($edit2['subject']); + // Confirm that the reply form is not shown. + $this->assertNoText(t('Reply to thread:'), 'Reply form is not displayed.'); } /** @@ -423,9 +450,12 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { */ function testDisablePrivatemsg() { $admin_user = $this->drupalCreateUser(array('administer permissions')); - $enableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); // set up user with read/write privatemsg permissions - $enableduser2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); // set up user with read/write privatemsg permissions - $disableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'allow disabling privatemsg')); // set up user with read/write privatemsg permissions + // Set up a user with "read/write privatemsg" permissions. + $enableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); + // Set up a user with "read/write privatemsg" permissions. + $enableduser2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); + // Set up a user with "read/write privatemsg" permissions. + $disableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'allow disabling privatemsg')); // Create a message between the users that we can use to test $return = privatemsg_new_thread(array($disableduser), $this->randomName(20), $this->randomName(100), array('author' => $enableduser));