summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--data/lang.txt2
-rw-r--r--lib/VNDB/DB/Users.pm6
-rw-r--r--lib/VNDB/Handler/Users.pm17
-rw-r--r--lib/VNDB/Util/Auth.pm9
-rw-r--r--lib/VNDB/Util/FormHTML.pm2
-rw-r--r--util/sql/all.sql8
-rw-r--r--util/sql/func.sql8
-rw-r--r--util/sql/schema.sql4
-rw-r--r--util/updates/update_2.16.sql24
10 files changed, 43 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index eadb6205..ad508ffa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,7 +17,7 @@
- Don't send 'tagspoil' filter when 'tag_inc' isn't active
- Don't allow page > 100 or sorting on username or title on tag link browser
- Added users_prefs table and removed the following columns from users:
- skin, customcss, show_nsfw, show_list
+ skin, customcss, show_nsfw, show_list, notify_announce, notify_dbedit
2.15 - 2010-12-15
- Removed expand/collapse from history browser and /u+/posts and switched to
diff --git a/data/lang.txt b/data/lang.txt
index afd1ff25..8a83326e 100644
--- a/data/lang.txt
+++ b/data/lang.txt
@@ -5798,7 +5798,7 @@ cs : Nastavení
hu : Beállítások
nl : Instellingen
-:_usern_set_dbedit
+:_usern_set_nodbedit
en : Notify me about edits of database entries I contributed to.
ru : Уведомлять меня о правках записей базы данных, которые я редактировал(а).
cs : Upozorňovat mne na úpravy databáze, ke kterým jsem přispěl/a.
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index 48e8d7ff..bd7db201 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -55,7 +55,7 @@ sub dbUserGet {
qw|id username c_votes c_changes c_tags|,
q|extract('epoch' from registered) as registered|,
$o{what} =~ /extended/ ? (
- qw|mail rank salt ign_votes notify_dbedit notify_announce|,
+ qw|mail rank salt ign_votes|,
q|encode(passwd, 'hex') AS passwd|
) : (),
$o{what} =~ /hide_list/ ? 'up.value AS hide_list' : (),
@@ -95,7 +95,7 @@ sub dbUserGet {
join(', ', @select), join(' ', @join), \%where, $order
);
- if($o{what} =~ /prefs/) {
+ if(@$r && $o{what} =~ /prefs/) {
my %r = map {
$r->[$_]{prefs} = {};
($r->[$_]{id}, $r->[$_])
@@ -118,7 +118,7 @@ sub dbUserEdit {
my %h;
defined $o{$_} && ($h{$_.' = ?'} = $o{$_})
- for (qw| username mail rank salt ign_votes notify_dbedit notify_announce |);
+ for (qw| username mail rank salt ign_votes |);
$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 d19b2f74..044c72b2 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -559,15 +559,11 @@ sub notifies {
if($self->reqMethod() eq 'POST' && $self->reqParam('set')) {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
- { name => 'notify_dbedit', required => 0 },
- { name => 'notify_announce', required => 0 }
+ { name => 'notify_nodbedit', required => 0, default => 1, enum => [0,1] },
+ { name => 'notify_announce', required => 0, default => 0, enum => [0,1] }
);
return 404 if $frm->{_err};
- for ('notify_dbedit', 'notify_announce') {
- $frm->{$_} = $frm->{$_} ? 1 : 0;
- $self->authInfo->{$_} = $frm->{$_};
- }
- $self->dbUserEdit($uid, %$frm);
+ $self->authPref($_, $frm->{$_}) for ('notify_nodbedit', 'notify_announce');
$saved = 1;
# updating notifications
@@ -658,9 +654,10 @@ sub notifies {
h1 mt '_usern_set_title';
div class => 'notice', mt '_usern_set_saved' if $saved;
p;
- for('dbedit', 'announce') {
- input type => 'checkbox', name => "notify_$_", id => "notify_$_", value => 1,
- $self->authInfo->{"notify_$_"} ? (checked => 'checked') : ();
+ for('nodbedit', 'announce') {
+ my $def = $_ eq 'nodbedit'? 0 : 1;
+ input type => 'checkbox', name => "notify_$_", id => "notify_$_", value => $def,
+ ($self->authPref("notify_$_")||0) == $def ? (checked => 'checked') : ();
label for => "notify_$_", ' '.mt("_usern_set_$_");
br;
}
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index 50b81eb2..932a48ee 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -198,10 +198,11 @@ sub _incorrectcode {
sub authPref {
my($self, $key, $val) = @_;
- return '' if !$self->authInfo->{id};
- return $self->{_auth}{prefs}{$key}||'' if @_ == 2;
- $self->{_auth}{prefs}{$key} = $val;
- $self->dbUserPrefSet($key, $val);
+ my $nfo = $self->authInfo;
+ return '' if !$nfo->{id};
+ return $nfo->{prefs}{$key}||'' if @_ == 2;
+ $nfo->{prefs}{$key} = $val;
+ $self->dbUserPrefSet($nfo->{id}, $key, $val);
}
1;
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 7956a4c2..41ee0ccc 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -89,7 +89,7 @@ sub htmlFormPart {
end;
td class => 'field';
input type => 'checkbox', name => $o{short}, id => $o{short},
- value => $o{value}||1, $frm->{$o{short}} ? ( checked => 'checked' ) : ();
+ value => $o{value}||1, ($frm->{$o{short}}||0) eq ($o{value}||1) ? ( checked => 'checked' ) : ();
label for => $o{short};
lit $o{name};
end;
diff --git a/util/sql/all.sql b/util/sql/all.sql
index 6ecb96f1..eb0d724d 100644
--- a/util/sql/all.sql
+++ b/util/sql/all.sql
@@ -10,7 +10,7 @@ CREATE TYPE language AS ENUM('cs', 'da', 'de', 'en', 'es', 'fi', 'fr',
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', 'dbedit', 'announce');
CREATE TYPE notification_ltype AS ENUM ('v', 'r', 'p', 't');
-CREATE TYPE prefs_key AS ENUM ('l10n', 'skin', 'customcss', 'show_nsfw', 'hide_list', 'notify_dbedit', 'notify_announce');
+CREATE TYPE prefs_key AS ENUM ('l10n', 'skin', 'customcss', 'show_nsfw', 'hide_list', 'notify_nodbedit', 'notify_announce');
CREATE TYPE producer_relation AS ENUM ('old', 'new', 'sub', 'par', 'imp', 'ipa', 'spa', 'ori');
CREATE TYPE release_type AS ENUM ('complete', 'partial', 'trial');
CREATE TYPE vn_relation AS ENUM ('seq', 'preq', 'set', 'alt', 'char', 'side', 'par', 'ser', 'fan', 'orig');
@@ -106,8 +106,10 @@ CREATE SEQUENCE covers_seq;
-- Rows that are assumed to be available
-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 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_prefs (uid, key, value) VALUES (0, 'notify_nodbedit', '1');
+INSERT INTO users_prefs (uid, key, value) VALUES (1, 'notify_nodbedit', '1');
INSERT INTO stats_cache (section, count) VALUES
('users', 1),
diff --git a/util/sql/func.sql b/util/sql/func.sql
index 3f1372b5..0248c69a 100644
--- a/util/sql/func.sql
+++ b/util/sql/func.sql
@@ -790,12 +790,10 @@ BEGIN
) 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;
+ AND NOT EXISTS(SELECT 1 FROM users_prefs up WHERE uid = c.requester AND key = 'notify_nodbedit');
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
@@ -805,11 +803,11 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION notify_announce() RETURNS trigger AS $$
BEGIN
INSERT INTO notifications (ntype, ltype, uid, iid, subid, c_title, c_byuser)
- SELECT 'announce', 't', u.id, t.id, 1, t.title, NEw.uid
+ SELECT 'announce', 't', up.uid, t.id, 1, t.title, NEw.uid
FROM threads t
JOIN threads_boards tb ON tb.tid = t.id
-- get the users who want this announcement
- JOIN users u ON u.notify_announce
+ JOIN users_prefs up ON up.key = 'notify_announce'
WHERE t.id = NEW.tid
AND tb.type = 'an' -- announcement board
AND NOT t.hidden;
diff --git a/util/sql/schema.sql b/util/sql/schema.sql
index 638191c3..ec5d8e58 100644
--- a/util/sql/schema.sql
+++ b/util/sql/schema.sql
@@ -271,9 +271,7 @@ 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 boolean NOT NULL DEFAULT FALSE,
- notify_dbedit boolean NOT NULL DEFAULT TRUE,
- notify_announce boolean NOT NULL DEFAULT FALSE
+ ign_votes boolean NOT NULL DEFAULT FALSE
);
-- users_prefs
diff --git a/util/updates/update_2.16.sql b/util/updates/update_2.16.sql
index b401a7a4..c1b3358b 100644
--- a/util/updates/update_2.16.sql
+++ b/util/updates/update_2.16.sql
@@ -50,7 +50,7 @@ ALTER TABLE rlists RENAME COLUMN rstat TO status;
-- add users_prefs table
-CREATE TYPE prefs_key AS ENUM ('l10n', 'skin', 'customcss', 'show_nsfw', 'hide_list', 'notify_dbedit', 'notify_announce');
+CREATE TYPE prefs_key AS ENUM ('l10n', 'skin', 'customcss', 'show_nsfw', 'hide_list', 'notify_nodbedit', 'notify_announce');
CREATE TABLE users_prefs (
uid integer NOT NULL REFERENCES users (id) ON DELETE CASCADE,
key prefs_key NOT NULL,
@@ -61,15 +61,23 @@ CREATE TABLE users_prefs (
-- convert from users.* to users_prefs
INSERT INTO users_prefs (uid, key, value)
SELECT id, 'skin'::prefs_key, skin FROM users WHERE skin <> ''
- UNION
- SELECT id, 'customcss', customcss FROM users WHERE customcss <> '';
- UNION
- SELECT id, 'show_nsfw'::prefs_key, '1' FROM users WHERE show_nsfw;
- UNION
- SELECT id, 'hide_list'::prefs_key, '1' FROM users WHERE NOT show_list;
-
+ UNION ALL
+ SELECT id, 'customcss', customcss FROM users WHERE customcss <> ''
+ UNION ALL
+ SELECT id, 'show_nsfw', '1' FROM users WHERE show_nsfw
+ UNION ALL
+ SELECT id, 'hide_list', '1' FROM users WHERE NOT show_list
+ UNION ALL
+ SELECT id, 'notify_nodbedit', '1' FROM users WHERE NOT notify_dbedit
+ UNION ALL
+ SELECT id, 'notify_announce', '1' FROM users WHERE notify_announce;
+
+-- remove unused columns from the user table
ALTER TABLE users DROP COLUMN skin;
ALTER TABLE users DROP COLUMN customcss;
ALTER TABLE users DROP COLUMN show_nsfw;
ALTER TABLE users DROP COLUMN show_list;
+ALTER TABLE users DROP COLUMN notify_dbedit;
+ALTER TABLE users DROP COLUMN notify_announce;
+