summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-04-30 18:04:50 +0200
committerYorhel <git@yorhel.nl>2011-04-30 18:04:50 +0200
commit4873e8583189ee9c611fadd27d491dc104c52b57 (patch)
tree8c3b4e8b6f1c011e85f1ead078b7308b0863345e
parent57b464e826e5f24828dec9401b70baaa43410b6c (diff)
Replaced user ranks with a permission system
This is far more flexible.
-rw-r--r--ChangeLog1
-rw-r--r--data/global.pl12
-rw-r--r--data/lang.txt57
-rw-r--r--lib/VNDB/DB/Users.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm16
-rw-r--r--lib/VNDB/Util/Auth.pm5
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm1
-rw-r--r--util/sql/schema.sql2
-rw-r--r--util/updates/update_2.20.sql13
9 files changed, 37 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index 210880bf..4a362661 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
- Added "All except characters" filter to history browser
- Cleaned up CSS code
- Cleaned up permissions
+ - Replaced user ranks with a permission system
- Bugfix: don't accidentally remove char traits when editing
- Bugfix: fixed possible SQL table name clash on history browser
- Bugfix: properly announce chars and traits in Multi::IRC
diff --git a/data/global.pl b/data/global.pl
index d19056f7..2453ed6b 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -31,15 +31,8 @@ our %S = (%S,
scr_size => [ 136, 102 ], # w*h of screenshot thumbnails
ch_size => [ 256, 300 ], # max. w*h of char images
cv_size => [ 256, 400 ], # max. w*h of cover images
- user_ranks => [
- # allowed actions # DB number
- [qw| |], # 0
- [qw| |], # 1
- [qw| board |], # 2
- [qw| board edit tag |], # 3
- [qw| board boardmod edit charedit tag dbmod tagmod |], # 4
- [qw| board boardmod edit charedit tag dbmod tagmod usermod affiliate |], # 5
- ],
+ # bit flags
+ permissions => {qw| board 1 boardmod 2 edit 4 charedit 8 tag 16 dbmod 32 tagmod 64 usermod 128 affiliate 256 |},
languages => [qw|cs da de en es fi fr hu it ja ko nl no pl pt-br pt-pt ru sk sv tr vi zh|],
producer_types => [qw|co in ng|],
discussion_boards => [qw|an db ge v p u|], # <- note that some properties of these boards are hard-coded
@@ -137,4 +130,3 @@ require $ROOT.'/data/config.pl' if -f $ROOT.'/data/config.pl';
1;
-
diff --git a/data/lang.txt b/data/lang.txt
index b63cc3e4..f3171116 100644
--- a/data/lang.txt
+++ b/data/lang.txt
@@ -104,51 +104,6 @@ ends with ']'. The following options are supported:
# data/global.pl - used in many places
-# user ranks
-
-:_urank_0
-en : visitor
-ru : посетитель
-cs : návštěvník
-hu : vendég
-nl : bezoeker
-
-:_urank_1
-en : banned
-ru : забанен
-cs : zabanovaný
-hu : kicsapva
-nl : gebanned
-
-:_urank_2
-en : loser
-ru : лузер
-cs : loser
-hu : vesztes
-nl : sukkel
-
-:_urank_3
-en : user
-ru : пользователь
-cs : uživatel
-hu : felhasználó
-nl : gebruiker
-
-:_urank_4
-en : mod
-ru : модератор
-cs : moderátor
-hu : mod
-nl :
-
-:_urank_5
-en : admin
-ru : администратор
-cs : administrátor
-hu : admin
-nl :
-
-
# languages
:_lang_cs
@@ -6749,12 +6704,12 @@ cs : Uživatelské jméno
hu : Felhasználónév
nl : Gebruikersnaam
-:_usere_rank
-en : Rank
-ru : Ранг
-cs : Postavení
-hu : Rang
-nl :
+:_usere_perm
+en : Permissions
+ru*:
+cs*:
+hu*:
+nl : Permissies
:_usere_ignvotes
en : Ignore votes in VN statistics
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index 17f360cc..abea9bec 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|,
+ qw|mail perm salt ign_votes|,
q|encode(passwd, 'hex') AS passwd|
) : (),
$o{what} =~ /hide_list/ ? 'up.value AS hide_list' : (),
@@ -118,7 +118,7 @@ sub dbUserEdit {
my %h;
defined $o{$_} && ($h{$_.' = ?'} = $o{$_})
- for (qw| username mail rank salt ign_votes |);
+ for (qw| username mail perm 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 6cedc734..dc748f75 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -301,7 +301,7 @@ sub edit {
$frm = $self->formValidate(
$self->authCan('usermod') ? (
{ post => 'usrname', template => 'pname', minlength => 2, maxlength => 15 },
- { post => 'rank', enum => [ 1..$#{$self->{user_ranks}} ] },
+ { post => 'perms', required => 0, multi => 1, enum => [ keys %{$self->{permissions}} ] },
{ post => 'ign_votes', required => 0, default => 0 },
) : (),
{ post => 'mail', template => 'mail' },
@@ -318,7 +318,10 @@ sub edit {
$self->dbUserPrefSet($uid, $_ => $frm->{$_}) for (qw|skin customcss show_nsfw hide_list |);
my %o;
$o{username} = $frm->{usrname} if $frm->{usrname};
- $o{rank} = $frm->{rank} if $frm->{rank};
+ if($self->authCan('usermod')) {
+ $o{perm} = 0;
+ $o{perm} += $self->{permissions}{$_} for(@{ delete $frm->{perms} });
+ }
$o{mail} = $frm->{mail};
($o{passwd}, $o{salt}) = $self->authPreparePass($frm->{usrpass}) if $frm->{usrpass};
$o{ign_votes} = $frm->{ign_votes} ? 1 : 0 if $self->authCan('usermod');
@@ -330,8 +333,9 @@ sub edit {
}
# fill out default values
- $frm->{usrname} ||= $u->{username};
- $frm->{$_} ||= $u->{$_} for(qw|rank mail|);
+ $frm->{usrname} ||= $u->{username};
+ $frm->{mail} ||= $u->{mail};
+ $frm->{perms} ||= [ grep $u->{perm} & $self->{permissions}{$_}, keys %{$self->{permissions}} ];
$frm->{$_} //= $u->{prefs}{$_} for(qw|skin customcss show_nsfw hide_list|);
$frm->{ign_votes} = $u->{ign_votes} if !defined $frm->{ign_votes};
@@ -350,8 +354,8 @@ sub edit {
[ part => title => mt '_usere_geninfo' ],
$self->authCan('usermod') ? (
[ input => short => 'usrname', name => mt('_usere_username') ],
- [ select => short => 'rank', name => mt('_usere_rank'), options => [
- map [ $_, mt '_urank_'.$_ ], 1..$#{$self->{user_ranks}} ] ],
+ [ select => short => 'perms', name => mt('_usere_perm'), multi => 1, size => (scalar keys %{$self->{permissions}}), options => [
+ map [ $_, $_ ], sort keys %{$self->{permissions}} ] ],
[ check => short => 'ign_votes', name => mt '_usere_ignvotes' ],
) : (
[ static => label => mt('_usere_username'), content => $frm->{usrname} ],
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index 88e68edc..89807bef 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -88,8 +88,7 @@ sub authInfo {
# a certain action. Argument is the action name as defined in global.pl
sub authCan {
my($self, $act) = @_;
- my $r = $self->{_auth} ? $self->{_auth}{rank} : 0;
- return scalar grep $_ eq $act, @{$self->{user_ranks}[$r]}[0..$#{$self->{user_ranks}[$r]}];
+ return $self->{_auth} ? $self->{_auth}{perm} & $self->{permissions}{$act} : 0;
}
@@ -102,7 +101,7 @@ sub _authCheck {
return 0 if !$user || length($user) > 15 || length($user) < 2 || !$pass;
my $d = $self->dbUserGet(username => $user, what => 'extended notifycount')->[0];
- return 0 if !defined $d->{id} || !$d->{rank};
+ return 0 if !$d->{id};
if(_authEncryptPass($self, $pass, $d->{salt}) eq $d->{passwd}) {
$self->{_auth} = $d;
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 5dd8038f..e1e21924 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -89,7 +89,6 @@ sub _menu {
my $nc = $self->authInfo->{notifycount};
h2;
a href => $uid, ucfirst $self->authInfo->{username};
- txt ' ('.mt('_urank_'.$self->authInfo->{rank}).')';
end;
div;
a href => "$uid/edit", mt '_menu_myprofile'; br;
diff --git a/util/sql/schema.sql b/util/sql/schema.sql
index 0a593cec..6cbd2b14 100644
--- a/util/sql/schema.sql
+++ b/util/sql/schema.sql
@@ -357,7 +357,7 @@ CREATE TABLE users (
id SERIAL NOT NULL PRIMARY KEY,
username varchar(20) NOT NULL UNIQUE,
mail varchar(100) NOT NULL,
- rank smallint NOT NULL DEFAULT 3,
+ perm smallint NOT NULL DEFAULT 1+4+16,
passwd bytea NOT NULL DEFAULT '',
registered timestamptz NOT NULL DEFAULT NOW(),
c_votes integer NOT NULL DEFAULT 0,
diff --git a/util/updates/update_2.20.sql b/util/updates/update_2.20.sql
index c4cdb880..390e9a41 100644
--- a/util/updates/update_2.20.sql
+++ b/util/updates/update_2.20.sql
@@ -39,3 +39,16 @@ CREATE TABLE affiliate_links (
CREATE INDEX affiliate_links_rid ON affiliate_links (rid) WHERE NOT hidden;
+
+
+-- rank -> permissions
+
+ALTER TABLE users RENAME rank TO perm;
+ALTER TABLE users ALTER COLUMN perm SET DEFAULT 1+4+16;
+UPDATE users SET perm = CASE
+ WHEN perm = 2 THEN 1
+ WHEN perm = 3 THEN 1+4+16
+ WHEN perm = 4 THEN 1+2+4+8+16+32+64
+ WHEN perm = 5 THEN 1+2+4+8+16+32+64+128+256
+ ELSE 0 END;
+