summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-09-29 14:19:51 +0200
committerYorhel <git@yorhel.nl>2020-09-29 14:19:54 +0200
commit7e4b41874ff68c1f470240ad8e550d1e867f4ac4 (patch)
tree7d553f969f6ea45015b873bccf16d62a81656411 /lib
parent7e4097baaddb3b3cf37343bb204f65beeb8a27f6 (diff)
TagEdit/TraitEdit: Bump "added" date on approval
This functionality was also present in the old forms. (+ irrelevant cleanup in TagEdit.elm)
Diffstat (limited to 'lib')
-rw-r--r--lib/VNWeb/Tags/Edit.pm4
-rw-r--r--lib/VNWeb/Traits/Edit.pm3
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/VNWeb/Tags/Edit.pm b/lib/VNWeb/Tags/Edit.pm
index 3f1a468d..d8e02506 100644
--- a/lib/VNWeb/Tags/Edit.pm
+++ b/lib/VNWeb/Tags/Edit.pm
@@ -88,11 +88,10 @@ TUWF::get qr{/(?:$RE{gid}/add|g/new)}, sub {
elm_api TagEdit => $FORM_OUT, $FORM_IN, sub {
my($data) = @_;
my $id = delete $data->{id};
- my $g = !$id ? {} : tuwf->dbRowi('SELECT id, addedby FROM tags WHERE id =', \$id);
+ my $g = !$id ? {} : tuwf->dbRowi('SELECT id, addedby, state FROM tags WHERE id =', \$id);
return tuwf->resNotFound if $id && !$g->{id};
return elm_Unauth if !can_edit g => $g;
-
$data->{addedby} = $g->{addedby} // auth->uid;
if(!auth->permTagmod) {
$data->{state} = 0;
@@ -117,6 +116,7 @@ elm_api TagEdit => $FORM_OUT, $FORM_IN, sub {
}, map $_->{id}, $data->{parents}->@*;
my %set = map +($_,$data->{$_}), qw/name description state addedby cat defaultspoil searchable applicable/;
+ $set{added} = sql 'NOW()' if $id && $data->{state} == 2 && $g->{state} != 2;
tuwf->dbExeci('UPDATE tags SET', \%set, 'WHERE id =', \$id) if $id;
$id = tuwf->dbVali('INSERT INTO tags', \%set, 'RETURNING id') if !$id;
diff --git a/lib/VNWeb/Traits/Edit.pm b/lib/VNWeb/Traits/Edit.pm
index c3299ad5..afb44fa4 100644
--- a/lib/VNWeb/Traits/Edit.pm
+++ b/lib/VNWeb/Traits/Edit.pm
@@ -86,7 +86,7 @@ TUWF::get qr{/(?:$RE{iid}/add|i/new)}, sub {
elm_api TraitEdit => $FORM_OUT, $FORM_IN, sub {
my($data) = @_;
my $id = delete $data->{id};
- my $e = !$id ? {} : tuwf->dbRowi('SELECT id, addedby FROM traits WHERE id =', \$id);
+ my $e = !$id ? {} : tuwf->dbRowi('SELECT id, addedby, state FROM traits WHERE id =', \$id);
return tuwf->resNotFound if $id && !$e->{id};
return elm_Unauth if !can_edit i => $e;
@@ -126,6 +126,7 @@ elm_api TraitEdit => $FORM_OUT, $FORM_IN, sub {
my %set = map +($_,$data->{$_}), qw/name alias description state addedby sexual defaultspoil searchable applicable order/;
$set{'"group"'} = delete $set{group};
$set{'"order"'} = delete $set{order};
+ $set{added} = sql 'NOW()' if $id && $data->{state} == 2 && $e->{state} != 2;
tuwf->dbExeci('UPDATE traits SET', \%set, 'WHERE id =', \$id) if $id;
$id = tuwf->dbVali('INSERT INTO traits', \%set, 'RETURNING id') if !$id;