summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--data/lang.txt31
-rw-r--r--lib/VNDB/DB/Users.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm29
-rw-r--r--util/sql/all.sql9
-rw-r--r--util/sql/func.sql36
-rw-r--r--util/sql/schema.sql3
-rw-r--r--util/updates/update_2.11.sql7
8 files changed, 112 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b393d32..026a90bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,7 @@ git - ?
- PMs
- Notifying users of a deletion of an entry they contributed to
- Notifying users of a deletion they have in their (wish)list
+ - Notifying users of an edit of an entry they contributed to
- Removed the ?l10n= paremeter
- Remove sessions that haven't been used for more than a month
- Properly copy over search string on switching with the searchtabs
diff --git a/data/lang.txt b/data/lang.txt
index 5bf4ef84..3cc9c1da 100644
--- a/data/lang.txt
+++ b/data/lang.txt
@@ -4696,6 +4696,12 @@ ru*:
cs*:
hu*:
+:_usern_type_dbedit
+en : Entry you contributed to has been edited
+ru*:
+cs*:
+hu*:
+
:_usern_n_t_new
en : New thread [_1] by [_2]
ru*:
@@ -4726,6 +4732,31 @@ ru*:
cs*:
hu*:
+:_usern_set_saved
+en : Settings successfully saved.
+ru*:
+cs*:
+hu*:
+
+:_usern_set_title
+en : Settings
+ru*:
+cs*:
+hu*:
+
+:_usern_set_dbedit
+en : Notify me about edits of database entries I contributed to.
+ru*:
+cs*:
+hu*:
+
+:_usern_set_submit
+en : Save
+ru*:
+cs*:
+hu*:
+
+
#############################################################################
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index bade6ca1..20278688 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -54,7 +54,7 @@ sub dbUserGet {
qw|id username c_votes c_changes show_list c_tags|,
q|extract('epoch' from registered) as registered|,
$o{what} =~ /extended/ ? (
- qw|mail rank salt skin customcss show_nsfw ign_votes|,
+ qw|mail rank salt skin customcss show_nsfw ign_votes notify_dbedit|,
q|encode(passwd, 'hex') AS passwd|
) : (),
$o{what} =~ /notifycount/ ?
@@ -100,7 +100,7 @@ sub dbUserEdit {
my %h;
defined $o{$_} && ($h{$_.' = ?'} = $o{$_})
- for (qw| username mail rank show_nsfw show_list skin customcss salt ign_votes |);
+ for (qw| username mail rank show_nsfw show_list skin customcss salt ign_votes notify_dbedit |);
$h{'passwd = decode(?, \'hex\')'} = $o{passwd}
if defined $o{passwd};
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 13d4c55e..e7822f6e 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -533,7 +533,20 @@ sub notifies {
);
return 404 if $f->{_err};
- if($self->reqMethod() eq 'POST') {
+ # changing the notification settings
+ my $saved;
+ if($self->reqMethod() eq 'POST' && $self->reqParam('set')) {
+ my $frm = $self->formValidate(
+ { name => 'notify_dbedit', required => 0 }
+ );
+ return 404 if $frm->{_err};
+ $frm->{notify_dbedit} = $frm->{notify_dbedit} ? 1 : 0;
+ $self->authInfo->{notify_dbedit} = $frm->{notify_dbedit};
+ $self->dbUserEdit($uid, %$frm);
+ $saved = 1;
+
+ # updating notifications
+ } elsif($self->reqMethod() eq 'POST') {
my $frm = $self->formValidate(
{ name => 'notifysel', multi => 1, required => 0, template => 'int' },
{ name => 'markread', required => 0 },
@@ -609,6 +622,20 @@ sub notifies {
);
end;
}
+
+ form method => 'post', action => "/u$uid/notifies";
+ div class => 'mainbox';
+ h1 mt '_usern_set_title';
+ div class => 'notice', mt '_usern_set_saved' if $saved;
+ p;
+ input type => 'checkbox', name => 'notify_dbedit', id => 'notify_dbedit', value => 1,
+ $self->authInfo->{notify_dbedit} ? (checked => 'checked') : ();
+ label for => 'notify_dbedit', ' '.mt('_usern_set_dbedit');
+ br;
+ input type => 'submit', name => 'set', value => mt '_usern_set_submit';
+ end;
+ end;
+ end;
$self->htmlFooter;
}
diff --git a/util/sql/all.sql b/util/sql/all.sql
index da52f368..5bd314f5 100644
--- a/util/sql/all.sql
+++ b/util/sql/all.sql
@@ -11,7 +11,7 @@ CREATE TYPE dbentry_type AS ENUM ('v', 'r', 'p');
CREATE TYPE edit_rettype AS (iid integer, cid integer, rev integer);
CREATE TYPE language AS ENUM('cs', 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt', 'ru', 'sk', 'sv', 'tr', 'vi', 'zh');
CREATE TYPE medium AS ENUM ('cd', 'dvd', 'gdr', 'blr', 'flp', 'mrt', 'mem', 'umd', 'nod', 'in', 'otc');
-CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel');
+CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit');
CREATE TYPE notification_ltype AS ENUM ('v', 'r', 'p', 't');
CREATE TYPE producer_relation AS ENUM ('old', 'new', 'sub', 'par', 'imp', 'ipa', 'spa', 'ori');
CREATE TYPE release_type AS ENUM ('complete', 'partial', 'trial');
@@ -69,6 +69,9 @@ CREATE TRIGGER notify_dbdel AFTER UPDATE ON producers
CREATE TRIGGER notify_dbdel AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbdel();
CREATE TRIGGER notify_listdel AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_listdel();
CREATE TRIGGER notify_listdel AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_listdel();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON producers FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
-- Sequences used for ID generation of items not in the DB
@@ -76,8 +79,8 @@ CREATE SEQUENCE covers_seq;
-- Rows that are assumed to be available
-INSERT INTO users (id, username, mail, rank) VALUES (0, 'deleted', 'del@vndb.org', 0);
-INSERT INTO users (username, mail, rank) VALUES ('multi', 'multi@vndb.org', 0);
+INSERT INTO users (id, username, mail, rank, notify_dbdel) VALUES (0, 'deleted', 'del@vndb.org', 0, false);
+INSERT INTO users (username, mail, rank, notify_dbdel) VALUES ('multi', 'multi@vndb.org', 0, false);
INSERT INTO stats_cache (section, count) VALUES
('users', 1),
diff --git a/util/sql/func.sql b/util/sql/func.sql
index 89494dd0..8a27a32c 100644
--- a/util/sql/func.sql
+++ b/util/sql/func.sql
@@ -682,3 +682,39 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
+
+-- called on UPDATE vn / producers / releases
+-- this trigger is very similar to notify_dbdel()
+CREATE OR REPLACE FUNCTION notify_dbedit() RETURNS trigger AS $$
+BEGIN
+ -- item is edited but not deleted? (deleted items are handled by the dbdel notify)
+ IF OLD.latest IS DISTINCT FROM NEW.latest AND NOT NEW.hidden THEN
+ INSERT INTO notifications (ntype, ltype, uid, iid, subid, c_title, c_byuser)
+ SELECT DISTINCT 'dbedit'::notification_ntype,
+ (CASE TG_TABLE_NAME WHEN 'vn' THEN 'v' WHEN 'releases' THEN 'r' ELSE 'p' END)::notification_ltype,
+ c.requester, NEW.id, c2.rev, x.title, c2.requester
+ -- look for changes of the edited entry
+ FROM changes c
+ JOIN ( SELECT vr.id, vr2.title FROM vn_rev vr
+ JOIN vn v ON v.id = vr.vid JOIN vn_rev vr2 ON vr2.id = v.latest
+ WHERE TG_TABLE_NAME = 'vn' AND vr.vid = NEW.id
+ UNION SELECT rr.id, rr2.title FROM releases_rev rr
+ JOIN releases r ON r.id = rr.rid JOIN releases_rev rr2 ON rr2.id = r.latest
+ WHERE TG_TABLE_NAME = 'releases' AND rr.rid = NEW.id
+ UNION SELECT pr.id, pr2.name FROM producers_rev pr
+ JOIN producers p ON p.id = pr.pid JOIN producers_rev pr2 ON pr2.id = p.latest
+ WHERE TG_TABLE_NAME = 'producers' AND pr.pid = NEW.id
+ ) x(id, title) ON c.id = x.id
+ -- join info about the deletion itself
+ JOIN changes c2 ON c2.id = NEW.latest
+ -- join info about the user who should get this notification
+ JOIN users u ON u.id = c.requester
+ -- exclude the user who edited the entry
+ WHERE c.requester <> c2.requester
+ -- exclude users who don't want this notify
+ AND u.notify_dbedit;
+ END IF;
+ RETURN NULL;
+END;
+$$ LANGUAGE plpgsql;
+
diff --git a/util/sql/schema.sql b/util/sql/schema.sql
index d5766073..91d7f9bf 100644
--- a/util/sql/schema.sql
+++ b/util/sql/schema.sql
@@ -275,7 +275,8 @@ CREATE TABLE users (
ip inet NOT NULL DEFAULT '0.0.0.0',
c_tags integer NOT NULL DEFAULT 0,
salt character(9) NOT NULL DEFAULT '',
- ign_votes voolean NOT NULL DEFAULT FALSE
+ ign_votes boolean NOT NULL DEFAULT FALSE,
+ notify_dbedit boolean NOT NULL DEFAULT TRUE
);
-- vn
diff --git a/util/updates/update_2.11.sql b/util/updates/update_2.11.sql
index d05d18c0..9184dec9 100644
--- a/util/updates/update_2.11.sql
+++ b/util/updates/update_2.11.sql
@@ -1,6 +1,6 @@
-CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel');
+CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit');
CREATE TYPE notification_ltype AS ENUM ('v', 'r', 'p', 't');
CREATE TABLE notifications (
@@ -27,6 +27,8 @@ INSERT INTO notifications (uid, date, ntype, ltype, iid, subid, c_title, c_byuse
-- ...and drop the now unused lastread column
ALTER TABLE threads_boards DROP COLUMN lastread;
+ALTER TABLE users ADD COLUMN notify_dbedit boolean NOT NULL DEFAULT true;
+UPDATE users SET notify_dbedit = false WHERE id IN(0,1);
-- languages -> ENUM
@@ -110,4 +112,7 @@ CREATE TRIGGER notify_dbdel AFTER UPDATE ON producers
CREATE TRIGGER notify_dbdel AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbdel();
CREATE TRIGGER notify_listdel AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_listdel();
CREATE TRIGGER notify_listdel AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_listdel();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON producers FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_dbedit AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();