diff options
author | Yorhel <git@yorhel.nl> | 2021-11-29 13:47:23 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-11-29 13:47:25 +0100 |
commit | 5c95351cce9e7d8628a9a6c30456c714d4848593 (patch) | |
tree | abc0f4c0301a1173356633e428087a32d697a5c7 | |
parent | fa86ca885a5aa08543207ad8a64d42f05ab52caf (diff) |
Move undefbool validation to TUWF for better Elm interop
Requires upgrading TUWF to commit
cbff0b7e7841ffce68cacea763fe3e59385f73e4
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Edit.pm | 4 | ||||
-rw-r--r-- | lib/VNWeb/Reviews/Elm.pm | 4 | ||||
-rw-r--r-- | lib/VNWeb/User/Notifications.pm | 3 | ||||
-rw-r--r-- | lib/VNWeb/Validation.pm | 2 |
5 files changed, 5 insertions, 10 deletions
@@ -1,7 +1,7 @@ FROM alpine:3.13 MAINTAINER Yorhel <contact@vndb.org> -ENV VNDB_DOCKER_VERSION=8 +ENV VNDB_DOCKER_VERSION=9 CMD /var/www/util/docker-init.sh RUN apk add --no-cache \ diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm index 65cff99e..1c44ffb3 100644 --- a/lib/VNWeb/Releases/Edit.pm +++ b/lib/VNWeb/Releases/Edit.pm @@ -24,7 +24,7 @@ my $FORM = { catalog => { required => 0, default => '', maxlength => 50 }, released => { default => 99999999, min => 1, rdate => 1 }, minage => { required => 0, default => undef, int => 1, enum => \%AGE_RATING }, - uncensored => { required => 0, jsonbool => 1 }, + uncensored => { undefbool => 1 }, reso_x => { uint => 1, range => [0,32767] }, reso_y => { uint => 1, range => [0,32767] }, voiced => { uint => 1, enum => \%VOICED }, @@ -131,8 +131,6 @@ elm_api ReleaseEdit => $FORM_OUT, $FORM_IN, sub { my $e = $new ? { id => 0 } : db_entry $data->{id} or return tuwf->resNotFound; return elm_Unauth if !can_edit r => $e; - $data->{uncensored} = $data->{uncensored}?1:0 if defined $data->{uncensored}; - if(!auth->permDbmod) { $data->{hidden} = $e->{hidden}||0; $data->{locked} = $e->{locked}||0; diff --git a/lib/VNWeb/Reviews/Elm.pm b/lib/VNWeb/Reviews/Elm.pm index f3e28516..2bd149de 100644 --- a/lib/VNWeb/Reviews/Elm.pm +++ b/lib/VNWeb/Reviews/Elm.pm @@ -4,7 +4,7 @@ use VNWeb::Prelude; my $VOTE = { id => { vndbid => 'w' }, - my => { required => 0, jsonbool => 1 }, + my => { undefbool => 1 }, overrule => { anybool => 1 }, mod => { _when => 'out', anybool => 1 }, }; @@ -15,7 +15,7 @@ our $VOTE_OUT = form_compile out => $VOTE; elm_api ReviewsVote => $VOTE_OUT, $VOTE_IN, sub { my($data) = @_; my %id = (auth ? (uid => auth->uid) : (ip => norm_ip tuwf->reqIP), id => $data->{id}); - my %val = (vote => $data->{my}?1:0, overrule => auth->permBoardmod ? $data->{overrule}?1:0 : 0, date => sql 'NOW()'); + my %val = (vote => $data->{my}, overrule => auth->permBoardmod ? $data->{overrule} : 0, date => sql 'NOW()'); tuwf->dbExeci( defined $data->{my} ? sql 'INSERT INTO reviews_votes', {%id,%val}, 'ON CONFLICT (id,', auth ? 'uid' : 'ip', ') DO UPDATE SET', \%val diff --git a/lib/VNWeb/User/Notifications.pm b/lib/VNWeb/User/Notifications.pm index 9bdffba9..7c5c2f42 100644 --- a/lib/VNWeb/User/Notifications.pm +++ b/lib/VNWeb/User/Notifications.pm @@ -220,7 +220,7 @@ TUWF::hook before => sub { our $SUB = form_compile any => { id => { vndbid => [qw|t w v r p c s d i g|] }, - subnum => { required => 0, jsonbool => 1 }, + subnum => { undefbool => 1 }, subreview => { anybool => 1 }, subapply => { anybool => 1 }, noti => { uint => 1 }, # Whether the user already gets 'subnum' notifications for this entry (see HTML.pm for possible values) @@ -230,7 +230,6 @@ elm_api Subscribe => undef, $SUB, sub { my($data) = @_; delete $data->{noti}; - $data->{subnum} = $data->{subnum}?1:0 if defined $data->{subnum}; # 'jsonbool' isn't understood by SQL $data->{subreview} = 0 if $data->{id} !~ /^v/; my %where = (iid => delete $data->{id}, uid => auth->uid); diff --git a/lib/VNWeb/Validation.pm b/lib/VNWeb/Validation.pm index 9b5bb9c8..bc49d847 100644 --- a/lib/VNWeb/Validation.pm +++ b/lib/VNWeb/Validation.pm @@ -43,8 +43,6 @@ TUWF::set custom_validations => { gtin => { required => 0, default => 0, func => sub { $_[0] = 0 if !length $_[0]; $_[0] eq 0 || gtintype($_[0]) } }, rdate => { uint => 1, func => \&_validate_rdate }, fuzzyrdate => { func => \&_validate_fuzzyrdate }, - # A tri-state bool, returns undef if not present or empty, normalizes to 0/1 otherwise - undefbool => { required => 0, default => undef, anybool => 1, func => sub { $_[0] = $_[0] ? 1 : 0; 1 } }, # An array that may be either missing (returns undef), a single scalar (returns single-element array) or a proper array undefarray => sub { +{ required => 0, default => undef, type => 'array', scalar => 1, values => $_[0] } }, # Accepts a user-entered vote string (or '-' or empty) and converts that into a DB vote number (or undef) - opposite of fmtvote() |