Skip to content

Commit

Permalink
Merge branch 'MDL-29801_master' of git://github.com/markn86/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 2, 2015
2 parents 8a6900f + 9cf81a1 commit e45f622
Show file tree
Hide file tree
Showing 18 changed files with 813 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
$string['context'] = 'context';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deletemessage'] = 'Delete message';
$string['deletemessageconfirmation'] = 'Are you sure you want to delete this message? It will only be deleted from your messaging history and will still be viewable by the user who sent or received the message.';
$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
$string['disableall'] = 'Temporarily disable notifications';
$string['disableall_help'] = 'Temporarily disable all notifications except those marked as "forced" by the site administrator';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@
$string['site:approvecourse'] = 'Approve course creation';
$string['site:backup'] = 'Backup courses';
$string['site:config'] = 'Change site configuration';
$string['site:deleteanymessage'] = 'Delete any messages on the site';
$string['site:deleteownmessage'] = 'Delete messages sent by and to the user';
$string['site:doanything'] = 'Allowed to do everything';
$string['site:doclinks'] = 'Show links to offsite docs';
$string['site:forcelanguage'] = 'Override course language';
Expand Down
20 changes: 20 additions & 0 deletions lib/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
)
),

'moodle/site:deleteanymessage' => array(

'riskbitmask' => RISK_DATALOSS,

'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
)
),

'moodle/site:sendmessage' => array(

'riskbitmask' => RISK_SPAM,
Expand All @@ -89,6 +100,15 @@
)
),

'moodle/site:deleteownmessage' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
)
),

'moodle/site:approvecourse' => array(

'riskbitmask' => RISK_XSS,
Expand Down
8 changes: 6 additions & 2 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,15 @@
<FIELD NAME="contexturl" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="If this message is a notification of an event contexturl should contain a link to view this event. For example if its a notification of a forum post contexturl should contain a link to the forum post."/>
<FIELD NAME="contexturlname" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeuserfromdeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeusertodeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="useridto" UNIQUE="false" FIELDS="useridto"/>
<INDEX NAME="useridfromto" UNIQUE="false" FIELDS="useridfrom, useridto"/>
<INDEX NAME="useridfromtodeleted" UNIQUE="false" FIELDS="useridfrom, useridto, timeuserfromdeleted, timeusertodeleted"/>
</INDEXES>
</TABLE>
<TABLE NAME="message_read" COMMENT="Stores all messages that have been read">
Expand All @@ -558,13 +560,15 @@
<FIELD NAME="contexturlname" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeuserfromdeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeusertodeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="useridto" UNIQUE="false" FIELDS="useridto"/>
<INDEX NAME="useridfromto" UNIQUE="false" FIELDS="useridfrom, useridto"/>
<INDEX NAME="useridfromtodeleted" UNIQUE="false" FIELDS="useridfrom, useridto, timeuserfromdeleted, timeusertodeleted"/>
</INDEXES>
</TABLE>
<TABLE NAME="message_contacts" COMMENT="Maintains lists of relationships between users">
Expand Down
60 changes: 60 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4470,5 +4470,65 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015082400.00);
}

if ($oldversion < 2015090200.00) {
$table = new xmldb_table('message');

// Define the deleted fields to be added to the message tables.
$field1 = new xmldb_field('timeuserfromdeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$field2 = new xmldb_field('timeusertodeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$oldindex = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto'));
$newindex = new xmldb_index('useridfromtodeleted', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto', 'timeuserfromdeleted', 'timeusertodeleted'));

// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}

// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}

// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}

// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}

// Now add them to the message_read table.
$table = new xmldb_table('message_read');

// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}

// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}

// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}

// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2015090200.00);
}

return true;
}
39 changes: 39 additions & 0 deletions message/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
$blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact
$unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact
$deletemessageid = optional_param('deletemessageid', 0, PARAM_INT);
$deletemessageconfirm = optional_param('deletemessageconfirm', 0, PARAM_BOOL);
if ($deletemessageid) {
$deletemessagetype = required_param('deletemessagetype', PARAM_ALPHAEXT);
}

//for search
$advancedsearch = optional_param('advanced', 0, PARAM_INT);
Expand Down Expand Up @@ -135,6 +140,17 @@
$PAGE->navigation->extend_for_user($user2);
}

$strmessages = get_string('messages', 'message');
if ($user2realuser) {
$user2fullname = fullname($user2);

$PAGE->set_title("$strmessages: $user2fullname");
$PAGE->set_heading("$strmessages: $user2fullname");
} else {
$PAGE->set_title("{$SITE->shortname}: $strmessages");
$PAGE->set_heading("{$SITE->shortname}: $strmessages");
}

/// Process any contact maintenance requests there may be
if ($addcontact and confirm_sesskey()) {
message_add_contact($addcontact);
Expand All @@ -149,6 +165,29 @@
if ($unblockcontact and confirm_sesskey()) {
message_unblock_contact($unblockcontact);
}
if ($deletemessageid and confirm_sesskey()) {
// Check that the message actually exists.
if ($message = $DB->get_record($deletemessagetype, array('id' => $deletemessageid))) {
// Check that we are allowed to delete this message.
if (message_can_delete_message($message, $user1->id)) {
if (!$deletemessageconfirm) {
$confirmurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id,
'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $deletemessagetype,
'deletemessageconfirm' => 1, 'sesskey' => sesskey()));
$confirmbutton = new single_button($confirmurl, get_string('delete'), 'post');
$strdeletemessage = get_string('deletemessage', 'message');
$PAGE->set_title($strdeletemessage);
echo $OUTPUT->header();
echo $OUTPUT->heading($strdeletemessage);
echo $OUTPUT->confirm(get_string('deletemessageconfirmation', 'message'), $confirmbutton, $url);
echo $OUTPUT->footer();
exit();
}
message_delete_message($message, $user1->id);
}
}
redirect($url);
}

//was a message sent? Do NOT allow someone looking at someone else's messages to send them.
$messageerror = null;
Expand Down
Loading

0 comments on commit e45f622

Please sign in to comment.