[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 2505 - (download) (as text) (annotate)
Mon Jul 12 22:15:57 2004 UTC (8 years, 10 months ago) by sh002i
File size: 1915 byte(s)
Generalized %can settings in Problem.pm with new permissions. Closes bug
#541. See said bug for more details.

    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.14 2004/03/15 20:17:35 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   if (exists $permissionLevels->{$activity}) {
   51     if (defined $permissionLevels->{$activity}) {
   52       return $permissionLevel >= $permissionLevels->{$activity};
   53     } else {
   54       return 0;
   55     }
   56   } else {
   57     die "Activity '$activity' not found in %permissionLevels. Can't continue.\n";
   58   }
   59 }
   60 
   61 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9