[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 2724 - (download) (as text) (annotate)
Thu Sep 2 22:53:00 2004 UTC (8 years, 8 months ago) by sh002i
File size: 2034 byte(s)
cleaned up mike's permission level patch to Feedback.pm:
- added receive_feedback permission (conf/global.conf.dist)
- use standard hasPermissions() function (lib/WeBWorK/ContentGenerator/Feedback.pm)
- check for undefined and empty string in permission field (lib/WeBWorK/Authz.pm)

    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.16 2004/07/12 23:37:54 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   return 0 unless defined $permissionLevel and $permissionLevel ne "";
   50 
   51   my $permissionLevels = $ce->{permissionLevels};
   52   if (exists $permissionLevels->{$activity}) {
   53     if (defined $permissionLevels->{$activity}) {
   54       return $permissionLevel >= $permissionLevels->{$activity};
   55     } else {
   56       return 0;
   57     }
   58   } else {
   59     die "Activity '$activity' not found in %permissionLevels. Can't continue.\n";
   60   }
   61 }
   62 
   63 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9