Commit 898ba89b authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-57115 blocks: Remove block_messages from core

parent 32f9550e
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mentees block.
*
* @package block_messages
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_messages extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_messages');
}
function get_content() {
global $USER, $CFG, $DB, $OUTPUT;
if (!$CFG->messaging) {
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('disabled', 'message');
}
return $this->content;
}
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) {
return $this->content;
}
$link = '/message/index.php';
$action = null; //this was using popup_action() but popping up a fullsize window seems wrong
$this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action);
$ufields = user_picture::fields('u', array('lastaccess'));
$users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count
FROM {user} u, {message} m
WHERE m.useridto = ? AND u.id = m.useridfrom AND m.notification = 0
GROUP BY $ufields", array($USER->id));
//Now, we have in users, the list of users to show
//Because they are online
if (!empty($users)) {
$this->content->text .= '<ul class="list">';
foreach ($users as $user) {
$timeago = format_time(time() - $user->lastaccess);
$this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'" title="'.$timeago.'">';
$this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>SITEID)); //TODO: user might not have capability to view frontpage profile :-(
$this->content->text .= fullname($user).'</a></div>';
$link = '/message/index.php?usergroup=unread&id='.$user->id;
$anchortagcontents = $OUTPUT->pix_icon('t/message', fullname($user)) . '&nbsp;' . $user->count;
$action = null; // popup is gone now
$anchortag = $OUTPUT->action_link($link, $anchortagcontents, $action);
$this->content->text .= '<div class="message">'.$anchortag.'</div></li>';
}
$this->content->text .= '</ul>';
} else {
$this->content->text .= '<div class="info">';
$this->content->text .= get_string('nomessages', 'message');
$this->content->text .= '</div>';
}
return $this->content;
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Messages block caps.
*
* @package block_messages
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/messages:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/messages:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'block_messages', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_messages
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['messages:addinstance'] = 'Add a new messages block';
$string['messages:myaddinstance'] = 'Add a new messages block to Dashboard';
$string['pluginname'] = 'Messages';
.block_messages .content {
text-align: left;
padding-top: 5px;
}
.block_messages .content .list li.listentry {
clear: both;
}
.block_messages .content .list li.listentry .user {
float: left;
position: relative;
}
.block_messages .content .list li.listentry .message {
float: right;
}
.block_messages .content .info {
text-align: center;
}
.block_messages .content .footer {
clear: both;
}
@block @block_messages
Feature: The messages block allows users to list new messages an a course
In order to enable the messages block in a course
As a teacher
I can add the messages block to a course and view my messages
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
Scenario: View the block by a user with messaging disabled.
Given the following config values are set as admin:
| messaging | 0 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Messages" block
Then I should see "Messaging is disabled on this site" in the "Messages" "block"
Scenario: View the block by a user who does not have any messages.
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Messages" block
Then I should see "No messages" in the "Messages" "block"
@javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I send "This is message 1" message to "Teacher 1" user
And I send "This is message 2" message to "Teacher 1" user
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Messages" block
Then I should see "Student 1" in the "Messages" "block"
@javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Messages" block
And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "Teacher 1" in the "Messages" "block"
@block @block_messages
Feature: The messages block allows users to list new messages on the dashboard
In order to enable the messages block on the dashboard
As a user
I can add the messages block to a my dashboard and view my messages
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
Scenario: View the block by a user with messaging disabled.
Given the following config values are set as admin:
| messaging | 0 |
And I log in as "teacher1"
And I press "Customise this page"
When I add the "Messages" block
Then I should see "Messaging is disabled on this site" in the "Messages" "block"
Scenario: View the block by a user who does not have any messages.
Given I log in as "teacher1"
And I press "Customise this page"
When I add the "Messages" block
Then I should see "No messages" in the "Messages" "block"
@javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I send "This is message 1" message to "Teacher 1" user
And I send "This is message 2" message to "Teacher 1" user
And I log out
When I log in as "teacher1"
And I press "Customise this page"
And I add the "Messages" block
Then I should see "Student 1" in the "Messages" "block"
@javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I press "Customise this page"
And I add the "Messages" block
And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
And I press "Customise this page"
And I add the "Messages" block
Then I should see "Teacher 1" in the "Messages" "block"
@block @block_messages
Feature: The messages block allows users to list new messages on the frontpage
In order to enable the messages block on the frontpage
As an admin
I can add the messages block to a the frontpage and view my messages
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And I log in as "admin"
And I am on site homepage
And I navigate to "Turn editing on" node in "Front page settings"
And I add the "Messages" block
And I log out
Scenario: View the block by a user with messaging disabled.
Given the following config values are set as admin:
| messaging | 0 |
And I log in as "admin"
And I am on site homepage
When I navigate to "Turn editing on" node in "Front page settings"
And I should see "Messaging is disabled on this site" in the "Messages" "block"
Then I navigate to "Turn editing off" node in "Front page settings"
And I should not see "Messaging is disabled on this site"
Scenario: View the block by a user who does not have any messages.
Given I log in as "teacher1"
When I am on site homepage
Then I should see "No messages" in the "Messages" "block"
Scenario: Try to view the block as a guest user.
Given I log in as "guest"
When I am on site homepage
Then I should not see "Messages"
@javascript
Scenario: View the block by a user who has messages.
Given I log in as "student1"
And I follow "Messages" in the user menu
And I send "This is message 1" message to "Teacher 1" user
And I send "This is message 2" message to "Teacher 1" user
And I log out
When I log in as "teacher1"
And I am on site homepage
Then I should see "Student 1" in the "Messages" "block"
@javascript
Scenario: Use the block to send a message to a user.
Given I log in as "teacher1"
And I am on site homepage
And I click on "//a[normalize-space(.) = 'Messages']" "xpath_element" in the "Messages" "block"
And I send "This is message 1" message to "Student 1" user
And I log out
When I log in as "student1"
And I am on site homepage
Then I should see "Teacher 1" in the "Messages" "block"
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package block_messages
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2017050500; // Requires this Moodle version
$plugin->component = 'block_messages'; // Full name of the plugin (used for diagnostics)
Supports Markdown
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