Skip to content

Commit 034e6f6

Browse files
committed
fix #22: patch status change by students
1 parent 2c6d14f commit 034e6f6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pages/editpatch.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727

2828
$prev_status = $patch->status;
2929

30+
$new_comment = trim($_POST['text'] ?? '');
31+
if ($new_comment && get_user()->role == ROLE_STUDENT) {
32+
if ($patch->status == PATCH_REVIEWED || $patch->status == PATCH_NOTMERGED) {
33+
$patch->set_status(PATCH_WAITING_REVIEW);
34+
}
35+
}
36+
3037
handle_form($patch, [], $readonly, ['group', 'status', 'type', 'issue_url'],
3138
null, false);
3239

@@ -36,20 +43,13 @@
3643
"</p>\n";
3744
}
3845

39-
$new_comment = trim($_POST['text'] ?? '');
4046
if ($new_comment) {
41-
$user = get_user();
42-
if ($user->role == ROLE_STUDENT) {
43-
if ($patch->status == PATCH_REVIEWED || $patch->status == PATCH_NOTMERGED) {
44-
$patch->set_status(PATCH_WAITING_REVIEW);
45-
}
46-
}
4747
if ($patch->status != $prev_status) {
4848
$old = Patch::get_status_options()[$prev_status];
4949
$new = Patch::get_status_options()[$patch->status];
5050
$new_comment = "Status changed: $old$new\n\n$new_comment";
5151
}
52-
$patch->comments->add(new PatchComment($patch, $new_comment, $user));
52+
$patch->comments->add(new PatchComment($patch, $new_comment, get_user()));
5353
}
5454
db_flush();
5555

templates.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
252252
echo "</select>";
253253
}
254254
else if (method_exists($obj, "get_$name"."_options")) {
255-
echo "<select name=\"$name\" id=\"$name\">\n";
255+
if (in_array($name, $readonly))
256+
$freeze = ' disabled';
257+
echo "<select name=\"$name\" id=\"$name\"$freeze>\n";
256258

257259
$method_name = "get_$name"."_options";
258260
foreach ($obj->$method_name() as $id => $name) {

0 commit comments

Comments
 (0)