Skip to content

Commit

Permalink
Allow authors to leave comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jul 9, 2017
1 parent 0d41881 commit a8973da
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 29 deletions.
4 changes: 4 additions & 0 deletions etc/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"name": "Allow comments even if reviewing is closed",
"type": "checkbox"
},
"cmt_author": {
"name": "Allow authors to post comments",
"type": "checkbox"
},
"decisions": {
"parser": "Decision_SettingParser"
},
Expand Down
2 changes: 2 additions & 0 deletions paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ function update_paper(PaperStatus $ps, $pj, $opj, $qreq, $action, $diffs) {
}
if (!$j) {
$j = (object) ["is_new" => true, "editable" => true];
if ($Me->act_author_view($prow))
$j->by_author = true;
if ($preferred_resp_round !== false)
$j->response = $Conf->resp_round_name($preferred_resp_round);
}
Expand Down
20 changes: 14 additions & 6 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,8 @@ function comment_identity_time(cj) {
t.push('<div class="cmtname">[' + cj.author + ']</div>');
else if (cj.author)
t.push('<div class="cmtname">' + cj.author + '</div>');
else if (cj.by_author && !cj.is_new)
t.push('<div class="cmtname">[Anonymous author]</div>');
if (cj.modified_at)
t.push('<div class="cmttime">' + cj.modified_at_text + '</div>');
if (!cj.response && cj.tags) {
Expand Down Expand Up @@ -2867,7 +2869,7 @@ function render_editing(hc, cj) {
fmtnote += (fmtnote ? ' <span class="barsep">·</span> ' : "") + '<a href="#" class="togglepreview" data-format="' + (fmt.format || 0) + '">Preview</a>';
fmtnote && hc.push('<div class="formatdescription">' + fmtnote + '</div>');
hc.push('<textarea name="comment" class="reviewtext cmttext" rows="5" cols="60" style="clear:both"></textarea>');
if (!cj.response) {
if (!cj.response && !cj.by_author) {
// visibility
hc.push('<div class="cmteditinfo f-i fold2o">', '</div>');
hc.push('<div class="f-ix">', '</div>');
Expand Down Expand Up @@ -2901,9 +2903,11 @@ function render_editing(hc, cj) {
} else {
// actions
// XXX allow_administer
hc.push('<input type="hidden" name="response" value="' + cj.response + '" />');
if (cj.is_new || cj.draft)
actions.push('<button type="button" name="savedraft" class="btn">Save draft</button>' + bnote);
if (cj.response) {
hc.push('<input type="hidden" name="response" value="' + cj.response + '" />');
if (cj.is_new || cj.draft)
actions.push('<button type="button" name="savedraft" class="btn">Save draft</button>' + bnote);
}
actions.push('<button type="button" name="bsubmit" class="btn btn-default">Submit</button>' + bnote);
}
actions.push('<button type="button" name="cancel" class="btn">Cancel</button>');
Expand Down Expand Up @@ -3117,8 +3121,12 @@ function render_cmt(j, cj, editing, msg) {
if (cj.response && editing && papercomment.nonauthor)
hc.push('<div class="xmsg xinfo">Although you aren’t a contact for this paper, as an administrator you can edit the authors’ response.</div>');
else if (!cj.response && editing && cj.author_email && hotcrp_user.email
&& cj.author_email.toLowerCase() != hotcrp_user.email.toLowerCase())
hc.push('<div class="xmsg xinfo">You didn’t write this comment, but as an administrator you can still make changes.</div>');
&& cj.author_email.toLowerCase() != hotcrp_user.email.toLowerCase()) {
if (hotcrp_status.myperm && hotcrp_status.myperm.act_author)
hc.push('<div class="xmsg xinfo">You didn’t write this comment, but as a fellow author you can still make changes.</div>')
else
hc.push('<div class="xmsg xinfo">You didn’t write this comment, but as an administrator you can still make changes.</div>');
}
if (editing)
render_editing(hc, cj);
else
Expand Down
12 changes: 10 additions & 2 deletions src/commentinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CommentInfo {
public $prow;
public $commentId = 0;
public $paperId;
public $contactId;
public $timeModified;
public $timeNotified;
public $timeDisplayed;
Expand Down Expand Up @@ -218,6 +219,8 @@ function unparse_json($contact, $include_displayed_at = false) {
$cj = (object) array("pid" => $this->prow->paperId, "is_new" => true, "editable" => true);
if ($this->commentType & COMMENTTYPE_RESPONSE)
$cj->response = $this->conf->resp_round_name($this->commentRound);
else if ($this->commentType & COMMENTTYPE_BYAUTHOR)
$cj->by_author = true;
return $cj;
}

Expand All @@ -231,6 +234,8 @@ function unparse_json($contact, $include_displayed_at = false) {
$cj->draft = true;
if ($this->commentType & COMMENTTYPE_RESPONSE)
$cj->response = $this->conf->resp_round_name($this->commentRound);
else if ($this->commentType & COMMENTTYPE_BYAUTHOR)
$cj->by_author = true;
if ($contact->can_comment($this->prow, $this))
$cj->editable = true;

Expand Down Expand Up @@ -338,7 +343,7 @@ private function save_ordinal($cmtid, $ctype, $Table, $LinkTable, $LinkColumn) {
Dbl::qe($q);
}

function save($req, $contact) {
function save($req, Contact $contact) {
global $Now;
if (is_array($req))
$req = (object) $req;
Expand All @@ -352,6 +357,8 @@ function save($req, $contact) {
$ctype = COMMENTTYPE_RESPONSE | COMMENTTYPE_AUTHOR;
else if ($is_response)
$ctype = COMMENTTYPE_RESPONSE | COMMENTTYPE_AUTHOR | COMMENTTYPE_DRAFT;
else if ($contact->act_author_view($this->prow))
$ctype = COMMENTTYPE_AUTHOR | COMMENTTYPE_BYAUTHOR;
else if ($req_visibility == "a" || $req_visibility == "au")
$ctype = COMMENTTYPE_AUTHOR;
else if ($req_visibility == "p" || $req_visibility == "pc")
Expand All @@ -371,7 +378,8 @@ function save($req, $contact) {
if (($rname = $this->conf->resp_round_name($this->commentRound)) != "1")
$ctags .= "{$rname}response ";
} else if (get($req, "tags")
&& preg_match_all(',\S+,', $req->tags, $m)) {
&& preg_match_all(',\S+,', $req->tags, $m)
&& !$contact->act_author_view($this->prow)) {
$tagger = new Tagger($contact);
$ctags = array();
foreach ($m[0] as $text)
Expand Down
30 changes: 19 additions & 11 deletions src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2639,19 +2639,23 @@ function can_comment(PaperInfo $prow, $crow, $submit = false) {
if ($crow && ($crow->commentType & COMMENTTYPE_RESPONSE))
return $this->can_respond($prow, $crow, $submit);
$rights = $this->rights($prow);
return $rights->allow_review
&& ($prow->timeSubmitted > 0
|| $rights->review_status != 0
|| ($rights->allow_administer && $rights->rights_forced))
&& ($this->conf->setting("cmt_always") > 0
|| $this->conf->time_review(null, $rights->allow_pc, true)
|| ($rights->allow_administer
&& (!$submit || $this->override_deadlines($rights))))
$author = $rights->act_author && $this->conf->setting("cmt_author") > 0;
return ($author
|| ($rights->allow_review
&& ($prow->timeSubmitted > 0
|| $rights->review_status != 0
|| ($rights->allow_administer && $rights->rights_forced))
&& ($this->conf->setting("cmt_always") > 0
|| $this->conf->time_review(null, $rights->allow_pc, true)
|| ($rights->allow_administer
&& (!$submit || $this->override_deadlines($rights))))))
&& (!$crow
|| $crow->contactId == $this->contactId
|| $rights->allow_administer
|| ($crow->contactId == $rights->review_token_cid
&& $rights->review_token_cid)
|| $rights->allow_administer);
|| ($author
&& ($crow->commentType & COMMENTTYPE_BYAUTHOR)));
}

function can_submit_comment(PaperInfo $prow, $crow) {
Expand All @@ -2668,7 +2672,10 @@ function perm_comment(PaperInfo $prow, $crow, $submit = false) {
if ($crow && $crow->contactId != $this->contactId
&& !$rights->allow_administer)
$whyNot["differentReviewer"] = 1;
else if (!$rights->allow_pc && !$rights->allow_review)
else if (!$rights->allow_pc
&& !$rights->allow_review
&& (!$rights->act_author
|| $this->conf->setting("cmt_author", 0) <= 0))
$whyNot["permission"] = 1;
else if ($prow->timeWithdrawn > 0)
$whyNot["withdrawn"] = 1;
Expand Down Expand Up @@ -2748,6 +2755,7 @@ function can_view_comment(PaperInfo $prow, $crow, $forceShow) {
|| ($rights->act_author_view
&& $ctype >= COMMENTTYPE_AUTHOR
&& (($ctype & COMMENTTYPE_RESPONSE) // author's response
|| ($ctype & COMMENTTYPE_BYAUTHOR)
|| (!($ctype & COMMENTTYPE_DRAFT) // author-visible cmt
&& $this->can_view_submitted_review_as_author($prow))))
|| (!$rights->view_conflict_type
Expand Down Expand Up @@ -2787,7 +2795,7 @@ function canViewCommentReviewWheres() {
}

function can_view_comment_identity(PaperInfo $prow, $crow, $forceShow) {
if ($crow && ($crow->commentType & COMMENTTYPE_RESPONSE))
if ($crow && ($crow->commentType & (COMMENTTYPE_RESPONSE | COMMENTTYPE_BYAUTHOR)))
return $this->can_view_authors($prow, $forceShow);
$rights = $this->rights($prow, $forceShow);
return $rights->can_administer
Expand Down
1 change: 1 addition & 0 deletions src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
define("COMMENTTYPE_DRAFT", 1);
define("COMMENTTYPE_BLIND", 2);
define("COMMENTTYPE_RESPONSE", 4);
define("COMMENTTYPE_BYAUTHOR", 8);
define("COMMENTTYPE_ADMINONLY", 0x00000);
define("COMMENTTYPE_PCONLY", 0x10000);
define("COMMENTTYPE_REVIEWER", 0x20000);
Expand Down
5 changes: 4 additions & 1 deletion src/papertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,10 @@ private function render_rcjs($rcjs) {
if ($this->include_comments()) {
if ($Me->can_comment($this->prow, null)) {
++$ncmt;
$s .= "papercomment.add({is_new:true,editable:true});\n";
if ($Me->act_author_view($this->prow))
$s .= "papercomment.add({is_new:true,editable:true,by_author:true});\n";
else
$s .= "papercomment.add({is_new:true,editable:true});\n";
}
if ($this->prow->has_author($Me))
foreach ($this->conf->time_author_respond() as $i => $rname) {
Expand Down
5 changes: 5 additions & 0 deletions src/settings/s_decisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function render(SettingValues $sv) {
'<button type="button" onclick="settings_add_resp_round()">Add response round</button>',
'</div></td></tr></table>';

echo '<p><table>';
$sv->echo_checkbox_row("cmt_author", "Authors can <strong>exchange comments</strong> with reviewers");
echo "</table></p>\n";


echo "<h3 class=\"settings g\">Decisions</h3>\n";

echo "Who can see paper <b>decisions</b> (accept/reject)?<br />\n";
Expand Down
4 changes: 0 additions & 4 deletions stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2774,10 +2774,6 @@ body#offline .revcard {
padding: 8px 12px;
font-size: 90%;
}
.cmtg .xmerror {
border-top: 2px solid red;
border-bottom: 2px solid red;
}
.response .cmtg .xinfo {
background: rgba(255, 221, 193, 0.5);
background: linear-gradient(to bottom, rgba(255,221,193,0), rgba(255,221,193,0.4) 4px, rgba(255,221,193,0.4) 51%, transparent 51%),
Expand Down
14 changes: 9 additions & 5 deletions test/test01.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,24 +456,28 @@ function check_paper1($paper1) {
assert_search_papers($user_mgbaker, "#none", "3 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30");

// comment searches
$paper2 = $Conf->paperRow(2, $user_chair);
xassert($user_mgbaker->can_comment($paper2, null));
xassert(!$user_mgbaker->can_comment($paper18, null));
xassert($user_marina->can_comment($paper1, null));
xassert($user_marina->can_comment($paper18, null));
assert_search_papers($user_chair, "cmt:any", "1");
assert_search_papers($user_chair, "has:comment", "1");
assert_search_papers($user_chair, "has:response", "");
assert_search_papers($user_chair, "has:author-comment", "1");
$comment2 = new CommentInfo(null, $paper18);
$c2ok = $comment2->save(array("text" => "test", "visibility" => "a", "blind" => false), $user_mgbaker);
$c2ok = $comment2->save(array("text" => "test", "visibility" => "a", "blind" => false), $user_marina);
xassert($c2ok);
assert_search_papers($user_chair, "cmt:any", "1 18");
assert_search_papers($user_chair, "cmt:any>1", "");
$comment3 = new CommentInfo(null, $paper18);
$c3ok = $comment3->save(array("text" => "test", "visibility" => "a", "blind" => false, "tags" => "redcmt"), $user_mgbaker);
$c3ok = $comment3->save(array("text" => "test", "visibility" => "a", "blind" => false, "tags" => "redcmt"), $user_marina);
xassert($c3ok);
assert_search_papers($user_chair, "cmt:any>1", "18");
assert_search_papers($user_chair, "cmt:jon", "");
assert_search_papers($user_chair, "cmt:mgbaker", "1 18");
assert_search_papers($user_chair, "cmt:mgbaker>1", "18");
assert_search_papers($user_chair, "cmt:marina", "18");
assert_search_papers($user_chair, "cmt:marina>1", "18");
assert_search_papers($user_chair, "cmt:#redcmt", "18");
$paper2 = $Conf->paperRow(2, $user_chair);
$comment4 = new CommentInfo(null, $paper2);
$c2ok = $comment4->save(array("text" => "test", "visibility" => "p", "blind" => false), $user_mgbaker);
assert_search_papers($user_chair, "has:comment", "1 2 18");
Expand Down

0 comments on commit a8973da

Please sign in to comment.