[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 1885 - (download) (as text) (annotate)
Mon Mar 15 20:17:35 2004 UTC (9 years, 3 months ago) by sh002i
File size: 1838 byte(s)
Authen and Authz are now passed only a WeBWorK::Request.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork-modperl/lib/WeBWorK/Authz.pm,v 1.13 2003/12/09 01:12:30 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 $permissionLevels = $ce->{permissionLevels};
   47 
   48   my $Permission = $db->getPermissionLevel($user); # checked
   49   return 0 unless defined $Permission;
   50   my $permissionLevel = $Permission->permission();
   51   if (defined $permissionLevels->{$activity}
   52       and $permissionLevel >= $permissionLevels->{$activity}) {
   53     return 1;
   54   } else {
   55     return 0;
   56   }
   57 }
   58 
   59 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9