summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@wirdorange.org>2012-01-25 18:55:43 (GMT)
committerOthmar Gsenger <otti@wirdorange.org>2012-01-25 18:55:43 (GMT)
commitdbb74ceda992bd4d630982de3610c64b84beee47 (patch)
tree5e48e5e3fd9c141eaa6b2d542b3f6b665d3507e9
parent5f854d24b20cc0ab7cfa039aae28233ce525b5dc (diff)
added admin functionality
ADD COLUMN admin (BOOL) to TABLE OWNERS
-rw-r--r--local/db.pm2
-rw-r--r--local/user.pm6
-rw-r--r--nzbget/list.pm1
-rw-r--r--nzbget/remove.pm8
4 files changed, 12 insertions, 5 deletions
diff --git a/local/db.pm b/local/db.pm
index 60c72b3..dbb5d7d 100644
--- a/local/db.pm
+++ b/local/db.pm
@@ -20,7 +20,7 @@ local::db::category->has_many(download => 'local::db::download');
package local::db::owner;
use base 'local::db::dbi';
local::db::owner->table('owner');
-local::db::owner->columns(All => qw/owner_id name quoata quota_used/);
+local::db::owner->columns(All => qw/owner_id name quoata quota_used admin/);
local::db::owner->has_many(download => 'local::db::download');
local::db::owner->has_many(seen => 'local::db::seen');
local::db::owner->has_many(ip => 'local::db::ip');
diff --git a/local/user.pm b/local/user.pm
index a0e24fd..0b32034 100644
--- a/local/user.pm
+++ b/local/user.pm
@@ -41,6 +41,12 @@ sub obj
return local::db::owner->retrieve($self->{id});
}
+sub is_admin
+{
+ my $self = shift;
+ my $user = $self->obj;
+ return ($user->admin and $user->admin ne 'FALSE')?1:0;
+}
sub get_name
{
diff --git a/nzbget/list.pm b/nzbget/list.pm
index fc30069..65d348d 100644
--- a/nzbget/list.pm
+++ b/nzbget/list.pm
@@ -33,6 +33,7 @@ sub handler
foreach my $dl ( @downloads)
{
my $dl_remove;
+ $dl_remove = a({href=>'remove?id='.$dl->download_id},$dl->owner->name) if $user->is_admin();
$dl_remove = a({href=>'remove?id='.$dl->download_id},"löschen") if $dl->owner->owner_id == $user->get_id;
print Tr(td([ (local::db::seen->search(user=>$user->get_id(),download=>$dl->download_id))?'':'x',
a({href=>"$module?category=".$dl->category->category_id},$dl->category->name),a({title=>$dl->description,href=>'read?id='.$dl->download_id},$dl->name),$dl->size.'MB',$dl_remove
diff --git a/nzbget/remove.pm b/nzbget/remove.pm
index 71334bd..4291a2b 100644
--- a/nzbget/remove.pm
+++ b/nzbget/remove.pm
@@ -15,12 +15,12 @@ sub handler
my $del_id = param('id');
my ($dl) = local::db::download->retrieve($del_id) or die 'Error in cancel';
- die "Not allowed" if not $dl->owner->owner_id() eq $user->get_id();
-
+ die "Not allowed" if not ($dl->owner->owner_id() eq $user->get_id() or $user->is_admin() );
+ my $owner = $dl->owner;
my $basedir = $config::config{files_dir} or die 'Missing files_dir in config';
File::Path::rmtree($basedir.'/'.$dl->category->name.'/'.$dl->download_id);
- $user->obj->quota_used($user->obj->quota_used - $dl->size);
- $user->obj->update;
+ $owner->quota_used($owner->quota_used - $dl->size);
+ $owner->update;
my @seens = local::db::seen->search(download=>$del_id);
map {$_->delete()} @seens;
$dl->delete();