Parent Directory
|
Revision Log
fix error in last commit
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/Authz.pm,v 1.15 2004/07/12 22:15:56 sh002i Exp $ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 package WeBWorK::Authz; 18 19 =head1 NAME 20 21 WeBWorK::Authz - check user permissions. 22 23 =cut 24 25 use strict; 26 use warnings; 27 28 sub new { 29 my ($invocant, $r) = @_; 30 my $class = ref($invocant) || $invocant; 31 my $self = { 32 r => $r, 33 }; 34 bless $self, $class; 35 return $self; 36 } 37 38 # This currently only uses two of it's arguments, but it accepts any number, in 39 # case in the future calculating certain permissions requires more information. 40 sub hasPermissions { 41 my ($self, $user, $activity) = @_; 42 my $r = $self->{r}; 43 my $ce = $r->ce; 44 my $db = $r->db; 45 46 my $Permission = $db->getPermissionLevel($user); # checked 47 return 0 unless defined $Permission; 48 my $permissionLevel = $Permission->permission(); 49 50 my $permissionLevels = $ce->{permissionLevels}; 51 if (exists $permissionLevels->{$activity}) { 52 if (defined $permissionLevels->{$activity}) { 53 return $permissionLevel >= $permissionLevels->{$activity}; 54 } else { 55 return 0; 56 } 57 } else { 58 die "Activity '$activity' not found in %permissionLevels. Can't continue.\n"; 59 } 60 } 61 62 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |