Commit 65475755 authored by Kevin Dibble's avatar Kevin Dibble Committed by Robert Lyon

Bug 1763517: Comments can't be deleted when work is submitted for marking

behatnotneeded

Change-Id: I402d90f2e89466aa266b28451b7511ba35a2305a
parent 22dabf52
......@@ -787,6 +787,16 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
$item->highlight = 1;
}
$is_export_preview = param_integer('export', $data->export);
// Comment authors can edit recent comments if they're private or if no one has replied yet.
if (!$item->deletedby && $item->isauthor && !$is_export_preview
&& ($item->private || $item->id == $lastcomment->id) && $item->ts > $editableafter) {
$item->canedit = 1;
}
else {
$item->canedit = 0;
}
if ($item->deletedby) {
$item->deletedmessage = $deletedmessage[$item->deletedby];
}
......@@ -794,13 +804,12 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
(!$isadminfeedback || ($isadminfeedback && ($data->owner === $item->author)))) {
// If the auther was admin/staff and not the owner of the annotation,
// the feedback can't be deleted.
$item->deleteform = pieform(self::delete_annotation_feedback_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
}
// Comment authors can edit recent comments if they're private or if no one has replied yet.
if (!$item->deletedby && $item->isauthor && !$is_export_preview
&& ($item->private || $item->id == $lastcomment->id) && $item->ts > $editableafter) {
$item->canedit = 1;
$check = get_record_sql('SELECT v.* FROM {view} v WHERE v.id = ?', array($data->view), ERROR_MULTIPLE);
if ($check->submittedstatus == View::UNSUBMITTED ||
($item->canedit && $item->id == $lastcomment->id && $item->ts > $editableafter)
) {
$item->deleteform = pieform(self::delete_annotation_feedback_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
}
}
// Form to make private comment public, or request that a
......@@ -1606,55 +1615,68 @@ function delete_annotation_feedback_submit(Pieform $form, $values) {
$url = $view->get_url(false);
}
db_begin();
// If this page is being marked, make annotation feedback un-deletable until released
// unless it is the last fedback still with in the editable timeframe
$editableafter = time() - 60 * get_config_plugin('artefact', 'annotation', 'commenteditabletime');
$lastcomment = $annotationfeedback::last_public_annotation_feedback($annotationid, $viewid, null);
if ($annotationfeedback->get('id') == $lastcomment->id && $annotationfeedback->get('mtime') > $editableafter) {
$candelete = 1;
}
else {
$candelete = 0;
}
$annotationfeedback->set('deletedby', $deletedby);
$annotationfeedback->commit();
if ($view->get('submittedstatus') == View::UNSUBMITTED || $candelete) {
db_begin();
if ($deletedby != 'author') {
// Notify author
if ($artefactid) {
$title = get_field('artefact', 'title', 'id', $artefactid);
}
else {
$title = get_field('view', 'title', 'id', $viewid);
}
$title = hsc($title);
$data = (object) array(
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'annotationfeedbackdeletednotificationsubject',
'section' => 'artefact.annotation',
'args' => array($title),
),
'message' => (object) array(
'key' => 'annotationfeedbackdeletedauthornotification',
'section' => 'artefact.annotation',
'args' => array($title, html2text($annotationfeedback->get('description'))),
),
'urltext' => (object) array(
'key' => $artefactid ? 'artefact' : 'view',
$annotationfeedback->set('deletedby', $deletedby);
$annotationfeedback->commit();
if ($deletedby != 'author') {
// Notify author
if ($artefactid) {
$title = get_field('artefact', 'title', 'id', $artefactid);
}
else {
$title = get_field('view', 'title', 'id', $viewid);
}
$title = hsc($title);
$data = (object) array(
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'annotationfeedbackdeletednotificationsubject',
'section' => 'artefact.annotation',
'args' => array($title),
),
'message' => (object) array(
'key' => 'annotationfeedbackdeletedauthornotification',
'section' => 'artefact.annotation',
'args' => array($title, html2text($annotationfeedback->get('description'))),
),
'urltext' => (object) array(
'key' => $artefactid ? 'artefact' : 'view',
),
),
),
'users' => array($annotationfeedback->get('author')),
'url' => $url,
);
activity_occurred('maharamessage', $data);
}
if ($deletedby != 'owner' && $annotationfeedback->get('owner') != $USER->get('id')) {
// Notify owner
$data = (object) array(
'annotationfeedbackid' => $annotationfeedback->get('id'),
'annotationid' => $annotationid,
'viewid' => $viewid,
'artefactid' => $artefactid,
);
activity_occurred('annotationfeedback', $data, 'artefact', 'annotation');
}
'users' => array($annotationfeedback->get('author')),
'url' => $url,
);
activity_occurred('maharamessage', $data);
}
if ($deletedby != 'owner' && $annotationfeedback->get('owner') != $USER->get('id')) {
// Notify owner
$data = (object) array(
'annotationfeedbackid' => $annotationfeedback->get('id'),
'annotationid' => $annotationid,
'viewid' => $viewid,
'artefactid' => $artefactid,
);
activity_occurred('annotationfeedback', $data, 'artefact', 'annotation');
}
db_commit();
db_commit();
}
if (param_exists('offset')) {
$options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
......
......@@ -776,18 +776,27 @@ class ArtefactTypeComment extends ArtefactType {
$item->highlight = 1;
}
$is_export_preview = param_integer('export',0);
if ($item->deletedby) {
$item->deletedmessage = $deletedmessage[$item->deletedby];
}
else if (($candelete || $item->isauthor) && !$is_export_preview) {
$item->deleteform = pieform(self::delete_comment_form($item->id));
}
// Comment authors can edit recent comments if they're private or if no one has replied yet.
if (!$item->deletedby && $item->isauthor && !$is_export_preview
&& ($item->private || $item->id == $lastcomment->id) && $item->ts > $editableafter) {
$item->canedit = 1;
}
else {
$item->canedit = 0;
}
if ($item->deletedby) {
$item->deletedmessage = $deletedmessage[$item->deletedby];
}
else if (($candelete || $item->isauthor) && !$is_export_preview) {
$check = get_record_sql('SELECT v.* FROM {view} v WHERE v.id = ?', array($data->view), ERROR_MULTIPLE);
if ($check->submittedstatus == View::UNSUBMITTED ||
($item->canedit && $item->id == $lastcomment->id && $item->ts > $editableafter)
) {
$item->deleteform = pieform(self::delete_comment_form($item->id));
}
}
// Form to make private comment public, or request that a
// private comment be made public
......@@ -1420,69 +1429,82 @@ function delete_comment_submit(Pieform $form, $values) {
$url = $view->get_url(false);
}
db_begin();
$comment->set('deletedby', $deletedby);
if (!$comment->has_visible_descendants()) {
$comment->set('hidden', 1);
// If this page is being marked, make comments un-deletable until released
// unless it is the last comment still with in the editable timeframe
$editableafter = time() - 60 * get_config_plugin('artefact', 'comment', 'commenteditabletime');
$lastcomment = $comment::last_public_comment($viewid, null);
if ($comment->get('id') == $lastcomment->id && $comment->get('mtime') > $editableafter) {
$candelete = 1;
}
else {
$candelete = 0;
}
$comment->commit();
if ($view->get('submittedstatus') == View::UNSUBMITTED || $candelete) {
db_begin();
// If this comment was hidden, check to see if its parent now also needs to be
// hidden (i.e. has no visible replies). And then its grandparent, etc
if ($comment->get('hidden')) {
$comment->hide_deleted_parents();
}
$comment->set('deletedby', $deletedby);
if ($deletedby != 'author') {
// Notify author
if ($artefact) {
$title = get_field('artefact', 'title', 'id', $artefact);
if (!$comment->has_visible_descendants()) {
$comment->set('hidden', 1);
}
else {
$title = get_field('view', 'title', 'id', $comment->get('onview'));
$comment->commit();
// If this comment was hidden, check to see if its parent now also needs to be
// hidden (i.e. has no visible replies). And then its grandparent, etc
if ($comment->get('hidden')) {
$comment->hide_deleted_parents();
}
$title = hsc($title);
$data = (object) array(
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'commentdeletednotificationsubject',
'section' => 'artefact.comment',
'args' => array($title),
),
'message' => (object) array(
'key' => 'commentdeletedauthornotification',
'section' => 'artefact.comment',
'args' => array($title, html2text($comment->get('description'))),
),
'urltext' => (object) array(
'key' => $artefact ? 'artefact' : 'view',
if ($deletedby != 'author') {
// Notify author
if ($artefact) {
$title = get_field('artefact', 'title', 'id', $artefact);
}
else {
$title = get_field('view', 'title', 'id', $comment->get('onview'));
}
$title = hsc($title);
$data = (object) array(
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'commentdeletednotificationsubject',
'section' => 'artefact.comment',
'args' => array($title),
),
'message' => (object) array(
'key' => 'commentdeletedauthornotification',
'section' => 'artefact.comment',
'args' => array($title, html2text($comment->get('description'))),
),
'urltext' => (object) array(
'key' => $artefact ? 'artefact' : 'view',
),
),
),
'users' => array($comment->get('author')),
'url' => $url,
);
activity_occurred('maharamessage', $data);
}
if ($deletedby != 'owner' && $comment->get('owner') != $USER->get('id')) {
// Notify owner
$data = (object) array(
'commentid' => $comment->get('id'),
'viewid' => $view->get('id'),
);
activity_occurred('feedback', $data, 'artefact', 'comment');
}
'users' => array($comment->get('author')),
'url' => $url,
);
activity_occurred('maharamessage', $data);
}
if ($deletedby != 'owner' && $comment->get('owner') != $USER->get('id')) {
// Notify owner
$data = (object) array(
'commentid' => $comment->get('id'),
'viewid' => $view->get('id'),
);
activity_occurred('feedback', $data, 'artefact', 'comment');
}
// Delete embedded images in the comment
require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('comment', $comment->get('id'));
db_commit();
// Delete embedded images in the comment
require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('comment', $comment->get('id'));
db_commit();
$SESSION->add_ok_msg(get_string('commentremoved', 'artefact.comment'));
$SESSION->add_ok_msg(get_string('commentremoved', 'artefact.comment'));
}
redirect(get_config('wwwroot') . $url);
}
......
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