Commit ab0a0975 authored by Peter Spicer's avatar Peter Spicer Committed by Robert Lyon

Bug 1837194: Allow going directly to a message from a URL

For normal messages, going to the inbox and unhiding a message is fine,
but if the message is one that will have been synced to an LMS, the user
is quite likely to come from the LMS via a direct link to the message itself.

This allows us to expand a message - albeit on the proviso that it is on
the first page of results, though this is a scenario that never came up in
a year of user testing.

I did include a Behat test, though I had to write a new step to cover the
specifics of 'going directly to a message'.

Change-Id: I0e68fcc37f1ed453b6c43ce939d8c2a3a60b292e
parent 29091c94
......@@ -131,6 +131,19 @@ jQuery(function($) {
});
JAVASCRIPT;
$externalmsg = param_integer('msg', 0);
$externalmsgtype = param_variable('msgtype', '');
$externalmsgtype = preg_replace('/[^a-z0-9_]+/i', '', $externalmsgtype);
if ($externalmsg && $externalmsgtype) {
$paginationjavascript .= '
jQuery(function($) {
$(document).ready(function() {
$("#notification-' . $externalmsgtype . '-' . $externalmsg . '").collapse("show");
});
});';
}
$deleteall = pieform(array(
'name' => 'delete_all_notifications',
'class' => 'form-deleteall sr-only',
......
......@@ -246,4 +246,35 @@ class BehatNavigation extends BehatBase {
}
$node->click();
}
/**
* Goes directly to the URL to open a notification based on its author.
*
* @Given I go directly to the message from :author
* @param string $author The message's author
*/
public function i_go_directly_to_the_message($author = null) {
if (!$this->running_javascript()) {
return true;
}
// First go to the inbox, we'll find our message from there.
$this->visitPath("/module/multirecipientnotification/inbox.php");
// Now find the message itself.
$exception = new ExpectationException('The inbox item from ' . $author . ' could not be found.', $this->getSession());
$authorliteral = $this->escaper->escapeLiteral($author);
$xpath = "//span[@class='username'][contains(normalize-space(.),{$authorliteral})]/ancestor::a";
$node = $this->find('xpath', $xpath, new ExpectationException($xpath, $this->getSession()));
if (!$node->hasAttribute('data-id') || !$node->hasAttribute('data-list')) {
throw new ExpectationException('No data-id or data-list for inbox item "' . $author . '".', $this->getSession());
}
// Having found the message, let's go to it directly.
$msg = $node->getAttribute('data-id');
$msgtype = $node->getAttribute('data-list');
$this->visitPath("/module/multirecipientnotification/inbox.php?msgtype={$msgtype}&msg={$msg}");
}
}
......@@ -172,7 +172,6 @@ jQuery(function($) {
}
else if (self) {
$(self).removeClass('text-weight-bold js-card-unread').addClass('card');
$(self).find('.control').removeClass('control');
$(self).find('.unread').removeClass('unread'); // for inbox block
}
$('#selectall').attr('checked', false); // Need to uncheck bulk checkbox
......
@javascript @core @core_messages
Feature: Opening inbox messages from outside
In order to open messages in my inbox from a direct link
As a user
So I can click on a link in another platform to get to my message
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| UserA | Kupuh1pa! | UserA@example.org | Angela | User | mahara | internal | member |
| UserB | Kupuh1pa! | UserB@example.org | Bob | User | mahara | internal | member |
| UserC | Kupuh1pa! | UserC@example.org | Cecilia | User | mahara | internal | member |
| UserD | Kupuh1pa! | UserD@example.org | Dmitri | User | mahara | internal | member |
And the following "messages" exist:
| emailtype | to | from | subject | messagebody | read | url | urltext |
| friendrequest | UserA | UserB | New friend request | Friend request from Bob | 1 | user/view.php?id=[from] | Requests |
| friendrequest | UserA | UserC | New friend request | Friend request from Cecilia | 1 | user/view.php?id=[from] | Requests |
| friendrequest | UserA | UserD | New friend request | Friend request from Dmitri | 1 | user/view.php?id=[from] | Requests |
| friendaccept | UserB | UserA | Friend request accepted - Bob | Friend request accepted from Bob | 1 | user/view.php?id=[to] | |
| friendaccept | UserC | UserA | Friend request accepted - Cecilia | Friend request accepted from Cecilia | 1 | user/view.php?id=[to] | |
| friendaccept | UserD | UserA | Friend request accepted - Dmitri | Friend request accepted from Dmitri | 1 | user/view.php?id=[to] | |
Scenario: Going to a direct link to a message will open the message directly in the inbox (Bug 1837194)
# Log in as users
Given I log in as "UserA" with password "Kupuh1pa!"
# Go to a specific message and verify its body is visible - but not another's body.
When I go directly to the message from "Cecilia User"
Then I should see "Friend request from Cecilia" in the "#activitylist" "css_element"
And I should not see "Friend request from Bob" in the "#activitylist" "css_element"
# Go to another specific message and verify its body is visible - but not another's body.
And I go directly to the message from "Bob User"
And I should see "Friend request from Bob" in the "#activitylist" "css_element"
And I should not see "Friend request from Cecilia" in the "#activitylist" "css_element"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment