summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-03-02 13:15:19 +0100
committerYorhel <git@yorhel.nl>2021-03-02 13:15:19 +0100
commitd3d36aa02c9d1558dea603cd64bcf0d266fe5b00 (patch)
tree8c7ef69a399dc9760a5e02c3f12cd1bba93a9438
parent1d9e8f67e6b746c31717d56789deed212c31d7eb (diff)
Reviews: Add moderator note field + only update lastmod when text is changed
-rw-r--r--css/v2.css10
-rw-r--r--elm/Reviews/Edit.elm10
-rw-r--r--lib/VNWeb/Reviews/Edit.pm14
-rw-r--r--lib/VNWeb/Reviews/Page.pm6
-rw-r--r--lib/VNWeb/Reviews/VNTab.pm6
-rw-r--r--sql/schema.sql3
-rw-r--r--util/updates/2021-03-02-reviews-modnote.sql4
7 files changed, 41 insertions, 12 deletions
diff --git a/css/v2.css b/css/v2.css
index 8db1fae4..67aa7f2b 100644
--- a/css/v2.css
+++ b/css/v2.css
@@ -540,14 +540,16 @@ div#vntags { margin: 0 30px 0 30px; border-top: 1px solid $bo
.reviews { display: flex; justify-content: center; flex-wrap: wrap }
.reviewbox { margin: 10px 12px 30px 12px; flex: 1 1; flex-basis: 450px }
-.reviewbox > div:nth-child(2) > span:first-child { float: right; color: $grayedout; font-style: normal; margin: -5px 0 0 0; visibility: hidden }
-.reviewbox > div:nth-child(2):hover > span:first-child,
-.reviewbox > div:nth-child(2):active > span:first-child { visibility: visible }
+.reviewbox > div:nth-child(3) > span:first-child { float: right; color: $grayedout; font-style: normal; margin: -5px 0 0 0; visibility: hidden }
+.reviewbox > div:nth-child(3):hover > span:first-child,
+.reviewbox > div:nth-child(3):active > span:first-child { visibility: visible }
.reviewbox .review_spoil input:checked ~ span { display: none }
.reviewbox .review_spoil input:not(:checked) ~ div { display: none }
.reviewbox > div:first-child { display: flex; justify-content: space-between; background: $secbg; font-weight: bold }
.reviewbox > div:first-child > span:first-child { font-weight: bold }
-.reviewbox > div:nth-child(2) { box-sizing: border-box; padding: 10px; background: $boxbg }
+.reviewbox > div:nth-child(2) { background: $secbg }
+.reviewbox > div:nth-child(2) p { padding: 2px; text-align: center }
+.reviewbox > div:nth-child(3) { box-sizing: border-box; padding: 10px; background: $boxbg }
.reviewbox > div:last-child { display: flex; justify-content: space-between; border-top: 1px solid $border }
.reviewbox .myvote { font-weight: bold; text-decoration: underline }
diff --git a/elm/Reviews/Edit.elm b/elm/Reviews/Edit.elm
index a2ee425f..35e8b1d7 100644
--- a/elm/Reviews/Edit.elm
+++ b/elm/Reviews/Edit.elm
@@ -32,6 +32,7 @@ type alias Model =
, spoiler : Bool
, locked : Bool
, isfull : Bool
+ , modnote : String
, text : TP.Model
, releases : List GRE.RecvReleases
, delete : Bool
@@ -50,6 +51,7 @@ init d =
, spoiler = d.spoiler
, locked = d.locked
, isfull = d.isfull
+ , modnote = d.modnote
, text = TP.bbcode d.text
, releases = d.releases
, delete = False
@@ -65,6 +67,7 @@ encode m =
, rid = m.rid
, spoiler = m.spoiler
, locked = m.locked
+ , modnote = m.modnote
, isfull = m.isfull
, text = m.text.data
}
@@ -75,6 +78,7 @@ type Msg
| Full Bool
| Spoiler Bool
| Locked Bool
+ | Modnote String
| Text TP.Msg
| Submit
| Submitted GApi.Response
@@ -90,6 +94,7 @@ update msg model =
Full b -> ({ model | isfull = b }, Cmd.none)
Spoiler b -> ({ model | spoiler = b }, Cmd.none)
Locked b -> ({ model | locked = b }, Cmd.none)
+ Modnote s -> ({ model | modnote = s }, Cmd.none)
Text m -> let (nm,nc) = TP.update m model.text in ({ model | text = nm }, Cmd.map Text nc)
Submit -> ({ model | state = Api.Loading }, GRE.send (encode model) Submitted)
@@ -152,6 +157,11 @@ view model =
]
, if not model.mod then text "" else
formField "" [ label [] [ inputCheck "" model.locked Locked, text " Locked for commenting." ] ]
+ , if not model.mod then text "" else
+ formField "modnote::Mod note"
+ [ inputText "modnote" model.modnote Modnote (style "width" "500px" :: GRE.valModnote)
+ , br [] [], text "Moderation note intended to inform readers of the review that its author may be biased and failed to disclose that." ]
+
, tr [ class "newpart" ] [ td [ colspan 2 ] [ text "" ] ]
, formField "text::Review"
[ TP.view "sum" model.text Text 700 ([rows (if model.isfull then 30 else 10), cols 50] ++ GRE.valText)
diff --git a/lib/VNWeb/Reviews/Edit.pm b/lib/VNWeb/Reviews/Edit.pm
index d98b4e42..00002c6b 100644
--- a/lib/VNWeb/Reviews/Edit.pm
+++ b/lib/VNWeb/Reviews/Edit.pm
@@ -11,7 +11,8 @@ my $FORM = {
rid => { vndbid => 'r', required => 0 },
spoiler => { anybool => 1 },
isfull => { anybool => 1 },
- text => { maxlength => 100_000, required => 0, default => '' },
+ modnote => { maxlength => 1024, required => 0, default => '' },
+ text => { maxlength => 100_000, default => '' },
locked => { anybool => 1 },
mod => { _when => 'out', anybool => 1 },
@@ -50,7 +51,7 @@ TUWF::get qr{/$RE{vid}/addreview}, sub {
TUWF::get qr{/$RE{wid}/edit}, sub {
my $e = tuwf->dbRowi(
- 'SELECT r.id, r.uid AS user_id, r.vid, r.rid, r.isfull, r.text, r.spoiler, r.locked, v.title AS vntitle
+ 'SELECT r.id, r.uid AS user_id, r.vid, r.rid, r.isfull, r.modnote, r.text, r.spoiler, r.locked, v.title AS vntitle
FROM reviews r JOIN vn v ON v.id = r.vid WHERE r.id =', \tuwf->capture('id')
);
return tuwf->resNotFound if !$e->{id};
@@ -69,10 +70,13 @@ elm_api ReviewsEdit => $FORM_OUT, $FORM_IN, sub {
my($data) = @_;
my $id = delete $data->{id};
- my $review = $id ? tuwf->dbRowi('SELECT id, locked, uid AS user_id FROM reviews WHERE id =', \$id) : {};
+ my $review = $id ? tuwf->dbRowi('SELECT id, locked, modnote, text, uid AS user_id FROM reviews WHERE id =', \$id) : {};
return elm_Unauth if !can_edit w => $review;
- $data->{locked} = $review->{locked}||0 if !auth->permBoardmod;
+ if(!auth->permBoardmod) {
+ $data->{locked} = $review->{locked}||0;
+ $data->{modnote} = $review->{modnote}||'';
+ }
validate_dbid 'SELECT id FROM vn WHERE id IN', $data->{vid};
validate_dbid 'SELECT id FROM releases WHERE id IN', $data->{rid} if defined $data->{rid};
@@ -81,7 +85,7 @@ elm_api ReviewsEdit => $FORM_OUT, $FORM_IN, sub {
$data->{text} = bb_subst_links $data->{text} if $data->{isfull};
if($id) {
- $data->{lastmod} = sql 'NOW()';
+ $data->{lastmod} = sql 'NOW()' if $review->{text} ne $data->{text};
tuwf->dbExeci('UPDATE reviews SET', $data, 'WHERE id =', \$id) if $id;
auth->audit($review->{user_id}, 'review edit', "edited $review->{id}") if auth->uid ne $review->{user_id};
diff --git a/lib/VNWeb/Reviews/Page.pm b/lib/VNWeb/Reviews/Page.pm
index 72b3b8d0..564f3502 100644
--- a/lib/VNWeb/Reviews/Page.pm
+++ b/lib/VNWeb/Reviews/Page.pm
@@ -66,6 +66,10 @@ sub review_ {
}
}
};
+ tr_ sub {
+ td_ 'Moderator note';
+ td_ sub { lit_ bb_format $w->{modnote} };
+ } if $w->{modnote};
tr_ class => 'reviewnotspoil', sub {
td_ '';
td_ sub {
@@ -89,7 +93,7 @@ sub review_ {
TUWF::get qr{/$RE{wid}(?:(?<sep>[\./])$RE{num})?}, sub {
my($id, $sep, $num) = (tuwf->capture('id'), tuwf->capture('sep')||'', tuwf->capture('num'));
my $w = tuwf->dbRowi(
- 'SELECT r.id, r.vid, r.rid, r.isfull, r.text, r.spoiler, r.locked, COALESCE(c.count,0) AS count, r.c_flagged, r.c_up, r.c_down, uv.vote, rm.id IS NULL AS can
+ 'SELECT r.id, r.vid, r.rid, r.isfull, r.modnote, r.text, r.spoiler, r.locked, COALESCE(c.count,0) AS count, r.c_flagged, r.c_up, r.c_down, uv.vote, rm.id IS NULL AS can
, v.title, rel.title AS rtitle, rel.original AS roriginal, rel.type AS rtype, rv.vote AS my, COALESCE(rv.overrule,false) AS overrule
, ', sql_user(), ',', sql_totime('r.date'), 'AS date,', sql_totime('r.lastmod'), 'AS lastmod
FROM reviews r
diff --git a/lib/VNWeb/Reviews/VNTab.pm b/lib/VNWeb/Reviews/VNTab.pm
index aa2949ec..aebdbbdd 100644
--- a/lib/VNWeb/Reviews/VNTab.pm
+++ b/lib/VNWeb/Reviews/VNTab.pm
@@ -9,7 +9,8 @@ sub reviews_ {
# TODO: Better order, pagination, option to show flagged reviews
my $lst = tuwf->dbAlli(
- 'SELECT r.id, r.rid, r.text, r.spoiler, r.c_count, r.c_up, r.c_down, uv.vote, rv.vote AS my, COALESCE(rv.overrule,false) AS overrule, NOT r.isfull AND rm.id IS NULL AS can
+ 'SELECT r.id, r.rid, r.modnote, r.text, r.spoiler, r.c_count, r.c_up, r.c_down, uv.vote, rv.vote AS my
+ , COALESCE(rv.overrule,false) AS overrule, NOT r.isfull AND rm.id IS NULL AS can
, ', sql_totime('r.date'), 'AS date, ', sql_user(), '
FROM reviews r
LEFT JOIN users u ON r.uid = u.id
@@ -36,6 +37,9 @@ sub reviews_ {
span_ "Vote: ".fmtvote($r->{vote}) if $r->{vote};
};
div_ sub {
+ p_ $r->{modnote} if $r->{modnote};
+ };
+ div_ sub {
span_ sub {
txt_ '<';
if(can_edit w => $r) {
diff --git a/sql/schema.sql b/sql/schema.sql
index fd512332..9ea912fb 100644
--- a/sql/schema.sql
+++ b/sql/schema.sql
@@ -545,7 +545,8 @@ CREATE TABLE reviews (
isfull boolean NOT NULL,
locked boolean NOT NULL DEFAULT false,
c_flagged boolean NOT NULL DEFAULT false,
- text text
+ text text NOT NULL,
+ modnote text NOT NULL DEFAULT ''
);
-- reviews_posts
diff --git a/util/updates/2021-03-02-reviews-modnote.sql b/util/updates/2021-03-02-reviews-modnote.sql
new file mode 100644
index 00000000..f6313303
--- /dev/null
+++ b/util/updates/2021-03-02-reviews-modnote.sql
@@ -0,0 +1,4 @@
+ALTER TABLE reviews ADD COLUMN modnote text NOT NULL DEFAULT '';
+
+-- Not sure why NULL was allowed for the text column, let's fix that while we're here.
+ALTER TABLE reviews ALTER COLUMN text SET NOT NULL;