summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-09-20 08:21:41 +0200
committerYorhel <git@yorhel.nl>2020-09-20 08:21:41 +0200
commit76181a765d26e6ddb27bdd6987ee1a436df2ff47 (patch)
tree18c0681db33ac49b80afada332e4bb9ca2bc5577
parent68c0dd38ada2e468810b8b39379356fa0fb840f5 (diff)
Reviews: Add mod option to lock reviews for comments
-rw-r--r--elm/Reviews/Edit.elm9
-rw-r--r--lib/VNWeb/Reviews/Edit.pm13
-rw-r--r--lib/VNWeb/Reviews/Page.pm12
-rw-r--r--sql/schema.sql3
-rw-r--r--util/updates/2020-09-20-reviews-locked.sql1
5 files changed, 30 insertions, 8 deletions
diff --git a/elm/Reviews/Edit.elm b/elm/Reviews/Edit.elm
index 5b3bc347..925de964 100644
--- a/elm/Reviews/Edit.elm
+++ b/elm/Reviews/Edit.elm
@@ -30,11 +30,13 @@ type alias Model =
, vntitle : String
, rid : Maybe Int
, spoiler : Bool
+ , locked : Bool
, isfull : Bool
, text : TP.Model
, releases : List GRE.RecvReleases
, delete : Bool
, delState : Api.State
+ , mod : Bool
}
@@ -46,11 +48,13 @@ init d =
, vntitle = d.vntitle
, rid = d.rid
, spoiler = d.spoiler
+ , locked = d.locked
, isfull = d.isfull
, text = TP.bbcode d.text
, releases = d.releases
, delete = False
, delState = Api.Normal
+ , mod = d.mod
}
@@ -60,6 +64,7 @@ encode m =
, vid = m.vid
, rid = m.rid
, spoiler = m.spoiler
+ , locked = m.locked
, isfull = m.isfull
, text = m.text.data
}
@@ -69,6 +74,7 @@ type Msg
= Release (Maybe Int)
| Full Bool
| Spoiler Bool
+ | Locked Bool
| Text TP.Msg
| Submit
| Submitted GApi.Response
@@ -83,6 +89,7 @@ update msg model =
Release i -> ({ model | rid = i }, Cmd.none)
Full b -> ({ model | isfull = b }, Cmd.none)
Spoiler b -> ({ model | spoiler = b }, Cmd.none)
+ Locked b -> ({ model | locked = b }, 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)
@@ -143,6 +150,8 @@ view model =
, br [] []
, b [ class "grayedout" ] [ text "You do not have to check this option if all spoilers in your review are marked with [spoiler] tags." ]
]
+ , if not model.mod then text "" else
+ formField "" [ label [] [ inputCheck "" model.locked Locked, text " Locked for commenting." ] ]
, 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 34930489..a3323d62 100644
--- a/lib/VNWeb/Reviews/Edit.pm
+++ b/lib/VNWeb/Reviews/Edit.pm
@@ -12,7 +12,9 @@ my $FORM = {
spoiler => { anybool => 1 },
isfull => { anybool => 1 },
text => { maxlength => 100_000, required => 0, default => '' },
+ locked => { anybool => 1 },
+ mod => { _when => 'out', anybool => 1 },
releases => { _when => 'out', $VNWeb::Elm::apis{Releases}[0]->%* },
};
@@ -38,7 +40,9 @@ TUWF::get qr{/$RE{vid}/addreview}, sub {
p_ 'You can only submit 5 reviews per day. Check back later!';
};
} else {
- elm_ 'Reviews.Edit' => $FORM_OUT, { elm_empty($FORM_OUT)->%*, vid => $v->{id}, vntitle => $v->{title}, releases => releases_by_vn $v->{id} };
+ elm_ 'Reviews.Edit' => $FORM_OUT, { elm_empty($FORM_OUT)->%*,
+ vid => $v->{id}, vntitle => $v->{title}, releases => releases_by_vn($v->{id}), mod => auth->permBoardmod()
+ };
}
};
};
@@ -46,13 +50,14 @@ 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, v.title AS vntitle
+ 'SELECT r.id, r.uid AS user_id, r.vid, r.rid, r.isfull, 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};
return tuwf->resDenied if !can_edit w => $e;
$e->{releases} = releases_by_vn $e->{vid};
+ $e->{mod} = auth->permBoardmod;
framework_ title => "Edit review for $e->{vntitle}", type => 'w', dbobj => $e, tab => 'edit', sub {
elm_ 'Reviews.Edit' => $FORM_OUT, $e;
};
@@ -64,9 +69,11 @@ elm_api ReviewsEdit => $FORM_OUT, $FORM_IN, sub {
my($data) = @_;
my $id = delete $data->{id};
- my $review = $id ? tuwf->dbRowi('SELECT id, uid AS user_id FROM reviews WHERE id =', \$id) : {};
+ my $review = $id ? tuwf->dbRowi('SELECT id, locked, 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;
+
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};
diff --git a/lib/VNWeb/Reviews/Page.pm b/lib/VNWeb/Reviews/Page.pm
index 8822b2ed..927a39f4 100644
--- a/lib/VNWeb/Reviews/Page.pm
+++ b/lib/VNWeb/Reviews/Page.pm
@@ -12,7 +12,7 @@ my $COMMENT = form_compile any => {
elm_api ReviewsComment => undef, $COMMENT, sub {
my($data) = @_;
- my $w = tuwf->dbRowi('SELECT id, false AS locked FROM reviews WHERE id =', \$data->{id});
+ my $w = tuwf->dbRowi('SELECT id, locked FROM reviews WHERE id =', \$data->{id});
return tuwf->resNotFound if !$w->{id};
return elm_Unauth if !can_edit t => $w;
@@ -51,11 +51,15 @@ sub review_ {
my($date, $lastmod) = map $_&&fmtdate($_,'compact'), $w->@{'date', 'lastmod'};
txt_ " on $date";
b_ class => 'grayedout', " last updated on $lastmod" if $lastmod && $date ne $lastmod;
+ br_ if $w->{c_flagged} || $w->{locked};
if($w->{c_flagged}) {
br_;
- br_;
b_ class => 'grayedout', 'Flagged: this review is below the voting threshold and not visible on the VN page.';
}
+ if($w->{locked}) {
+ br_;
+ b_ class => 'grayedout', 'Locked: commenting on this review has been disabled.';
+ }
}
};
tr_ class => 'reviewnotspoil', sub {
@@ -81,7 +85,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, 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.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
@@ -135,7 +139,7 @@ TUWF::get qr{/$RE{wid}(?:(?<sep>[\./])$RE{num})?}, sub {
} else {
div_ id => 'threadstart', '';
}
- elm_ 'Reviews.Comment' => $COMMENT, { id => $w->{id}, msg => '' } if $w->{count} <= $page*25 && can_edit t => {%$w,locked=>0};
+ elm_ 'Reviews.Comment' => $COMMENT, { id => $w->{id}, msg => '' } if $w->{count} <= $page*25 && can_edit t => $w;
};
};
diff --git a/sql/schema.sql b/sql/schema.sql
index 2ee7d24d..3605e9cc 100644
--- a/sql/schema.sql
+++ b/sql/schema.sql
@@ -511,7 +511,8 @@ CREATE TABLE reviews (
c_count smallint NOT NULL DEFAULT 0,
c_lastnum smallint,
isfull boolean NOT NULL,
- c_flagged boolean NOT NULL DEFAULT false
+ c_flagged boolean NOT NULL DEFAULT false,
+ locked boolean NOT NULL DEFAULT false
);
-- reviews_posts
diff --git a/util/updates/2020-09-20-reviews-locked.sql b/util/updates/2020-09-20-reviews-locked.sql
new file mode 100644
index 00000000..ee66cf71
--- /dev/null
+++ b/util/updates/2020-09-20-reviews-locked.sql
@@ -0,0 +1 @@
+ALTER TABLE reviews ADD COLUMN locked boolean NOT NULL DEFAULT false;