[system] / trunk / webwork2 / lib / WeBWorK / Authz.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/Authz.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1221 - (download) (as text) (annotate)
Thu Jun 19 19:09:43 2003 UTC (10 years ago) by sh002i
File size: 1189 byte(s)
if permission level does not exist in database, has_permissions will
return a false value.

    1 ################################################################################
    2 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
    3 # $Id$
    4 ################################################################################
    5 
    6 package WeBWorK::Authz;
    7 
    8 =head1 NAME
    9 
   10 WeBWorK::Authz - check user permissions.
   11 
   12 =cut
   13 
   14 use strict;
   15 use warnings;
   16 
   17 # WeBWorK::Authz->new($r, $ce, $db)
   18 sub new($$$$) {
   19   my $invocant = shift;
   20   my $class = ref($invocant) || $invocant;
   21   my $self = {};
   22   ($self->{r}, $self->{ce}, $self->{db}) = @_;
   23   bless $self, $class;
   24   return $self;
   25 }
   26 
   27 # This currently only uses two of it's arguments, but it accepts any number, in
   28 # case in the future calculating certain permissions requires more information.
   29 sub hasPermissions {
   30   my ($self, $user, $activity) = @_;
   31   my $r = $self->{r};
   32   my $courseEnvironment = $self->{ce};
   33   my $permissionLevels = $courseEnvironment->{permissionLevels};
   34 
   35   my $Permission = $self->{db}->getPermissionLevel($user);
   36   return 0 unless defined $Permission;
   37   my $permissionLevel = $Permission->permission();
   38   if (defined $permissionLevels->{$activity}
   39       and $permissionLevel >= $permissionLevels->{$activity}) {
   40     return 1;
   41   } else {
   42     return 0;
   43   }
   44 }
   45 
   46 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9