[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm /publisher lonrights.pm /xml londefdef.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 22 Jun 2007 00:11:37 -0000
This is a MIME encoded message
--albertel1182471097
Content-Type: text/plain
albertel Thu Jun 21 20:11:37 2007 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
/loncom/publisher lonrights.pm
/loncom/xml londefdef.pm
Log:
- BUG#3370, BUG#1750 - add explict user allowing in the rights file
- convert rights display to use data_table formatting
- some &mt updates
--albertel1182471097
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070621201137.txt"
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.892 loncom/lonnet/perl/lonnet.pm:1.893
--- loncom/lonnet/perl/lonnet.pm:1.892 Mon Jun 18 18:52:33 2007
+++ loncom/lonnet/perl/lonnet.pm Thu Jun 21 20:11:04 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.892 2007/06/18 22:52:33 albertel Exp $
+# $Id: lonnet.pm,v 1.893 2007/06/22 00:11:04 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3804,26 +3804,40 @@
$ucrs = &LONCAPA::clean_username($ucrs);
my $access=0;
foreach my $right (split(/\s*\,\s*/,&metadata($uri,'rule_rights'))) {
- my ($effect,$realm,$role)=split(/\:/,$right);
- if ($role) {
- if ($role ne $urole) { next; }
- }
- foreach my $scope (split(/\s*\,\s*/,$realm)) {
- my ($tdom,$tcrs,$tsec)=split(/\_/,$scope);
- if ($tdom) {
- if ($tdom ne $udom) { next; }
- }
- if ($tcrs) {
- if ($tcrs ne $ucrs) { next; }
- }
- if ($tsec) {
- if ($tsec ne $usec) { next; }
- }
- $access=($effect eq 'allow');
- last;
- }
- if ($realm eq '' && $role eq '') {
- $access=($effect eq 'allow');
+ my ($effect,$realm,$role,$type)=split(/\:/,$right);
+ if ($type eq 'user') {
+ foreach my $scope (split(/\s*\,\s*/,$realm)) {
+ my ($tdom,$tcrs)=split(/\_/,$scope);
+ if ($tdom) {
+ if ($tdom ne $env{'user.domain'}) { next; }
+ }
+ if ($tcrs) {
+ if ($tcrs ne $env{'user.name'}) { next; }
+ }
+ $access=($effect eq 'allow');
+ last;
+ }
+ } else {
+ if ($role) {
+ if ($role ne $urole) { next; }
+ }
+ foreach my $scope (split(/\s*\,\s*/,$realm)) {
+ my ($tdom,$tcrs,$tsec)=split(/\_/,$scope);
+ if ($tdom) {
+ if ($tdom ne $udom) { next; }
+ }
+ if ($tcrs) {
+ if ($tcrs ne $ucrs) { next; }
+ }
+ if ($tsec) {
+ if ($tsec ne $usec) { next; }
+ }
+ $access=($effect eq 'allow');
+ last;
+ }
+ if ($realm eq '' && $role eq '') {
+ $access=($effect eq 'allow');
+ }
}
}
return $access;
Index: loncom/publisher/lonrights.pm
diff -u loncom/publisher/lonrights.pm:1.22 loncom/publisher/lonrights.pm:1.23
--- loncom/publisher/lonrights.pm:1.22 Tue May 1 21:34:23 2007
+++ loncom/publisher/lonrights.pm Thu Jun 21 20:11:22 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to show and edit custom distribution rights
#
-# $Id: lonrights.pm,v 1.22 2007/05/02 01:34:23 albertel Exp $
+# $Id: lonrights.pm,v 1.23 2007/06/22 00:11:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,8 +55,8 @@
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- my $js = &Apache::loncommon::coursebrowser_javascript();
-
+ my $js = &Apache::loncommon::coursebrowser_javascript().
+ &Apache::loncommon::studentbrowser_javascript();
$r->print(&Apache::loncommon::start_page('Custom Distribution Rights',$js));
$r->rflush();
@@ -66,90 +66,101 @@
my $constructmode=($uri=~/^\/\~/);
# ============================================================ Modify and store
- if ($constructmode) {
- if ($env{'form.store'}) {
- my @newrules=();
- undef @newrules;
+ if ($constructmode && $env{'form.store'}) {
+
+ my @newrules;
+
# read rules from form
- foreach (keys %env) {
- if ($_=~/^form\.effect\_(\d+)$/) {
- my $number=$1;
- my %rulehash=();
- foreach ('effect','domain','course','section','role') {
- $rulehash{$_}=$env{'form.'.$_.'_'.$number};
- }
- if ($rulehash{'role'} eq 'au') {
- $rulehash{'course'}='';
- $rulehash{'section'}='';
- }
- if ($rulehash{'role'} eq 'cc') {
- $rulehash{'section'}='';
- }
- unless (($rulehash{'effect'} eq 'deny') ||
- ($rulehash{'effect'} eq 'allow')) {
- $rulehash{'effect'}='deny';
- }
- $rulehash{'domain'} = &LONCAPA::clean_domain($rulehash{'domain'});
- $rulehash{'course'} = &LONCAPA::clean_courseid($rulehash{'course'});
- $rulehash{'section'}=~s/\W//g;
- unless ($rulehash{'domain'}) {
- $rulehash{'domain'}=$env{'user.domain'};
- }
- my $realm='';
- if ($number) {
- $realm=$rulehash{'domain'};
- if ($rulehash{'course'}) {
- $realm.='_'.$rulehash{'course'};
- }
- if ($rulehash{'section'}) {
- $realm.='_'.$rulehash{'section'};
- }
- }
- $newrules[$number]=$rulehash{'effect'}.':'.
- $realm.':'.$rulehash{'role'};
- }
- }
+ foreach my $key (keys(%env)) {
+ next if ($key!~/^form\.effect\_(\d+)$/);
+ my $number=$1;
+ my %rulehash;
+ foreach my $action ('effect','type','domain','course','section','role') {
+ $rulehash{$action}=$env{'form.'.$action.'_'.$number};
+ }
+ if ($rulehash{'type'} !~ /^(user|course)$/) {
+ $rulehash{'type'} = 'course';
+ }
+ if ($rulehash{'type'} eq 'user') {
+ $rulehash{'section'}='';
+ $rulehash{'role'}='';
+ }
+ if ($rulehash{'role'} eq 'au') {
+ $rulehash{'course'}='';
+ $rulehash{'section'}='';
+ }
+ if ($rulehash{'role'} eq 'cc') {
+ $rulehash{'section'}='';
+ }
+ unless (($rulehash{'effect'} eq 'deny') ||
+ ($rulehash{'effect'} eq 'allow')) {
+ $rulehash{'effect'}='deny';
+ }
+ $rulehash{'domain'} =
+ &LONCAPA::clean_domain($rulehash{'domain'});
+ if ($rulehash{'type'} eq 'course') {
+ $rulehash{'course'} =
+ &LONCAPA::clean_courseid($rulehash{'course'});
+ } else {
+ $rulehash{'course'} =
+ &LONCAPA::clean_username($rulehash{'course'});
+ }
+ $rulehash{'section'}=~s/\W//g;
+ if (!$rulehash{'domain'}) {
+ $rulehash{'domain'}=$env{'user.domain'};
+ }
+ my $realm='';
+ if ($number) {
+ $realm=$rulehash{'domain'};
+ if ($rulehash{'course'}) {
+ $realm.='_'.$rulehash{'course'};
+ }
+ if ($rulehash{'section'}) {
+ $realm.='_'.$rulehash{'section'};
+ }
+ }
+ $newrules[$number]=$rulehash{'effect'}.':'.
+ $realm.':'.$rulehash{'role'}.':'.$rulehash{'type'};
+ }
# edit actions?
- foreach (keys %env) {
- if ($_=~/^form\.action\_(\d+)$/) {
- my $number=$1;
- if ($env{$_} eq 'delete') { $newrules[$number]=''; }
- if (($env{$_} eq 'moveup') && ($number>1)) {
- my $buffer=$newrules[$number];
- $newrules[$number]=$newrules[$number-1];
- $newrules[$number-1]=$buffer;
- }
- if (($env{$_} eq 'movedown') && ($number<$#newrules)) {
- my $buffer=$newrules[$number];
- $newrules[$number]=$newrules[$number+1];
- $newrules[$number+1]=$buffer;
- }
- if ($env{$_} eq 'insertabove') {
- for (my $i=$#newrules;$i>=$number;$i--) {
- $newrules[$i+1]=$newrules[$i];
- }
- $newrules[$number]='deny';
- }
- if ($env{$_} eq 'insertbelow') {
- for (my $i=$#newrules;$i>$number;$i--) {
- $newrules[$i+1]=$newrules[$i];
- }
- $newrules[$number+1]='deny';
- }
+ foreach my $key (keys(%env)) {
+ next if ($key!~/^form\.action\_(\d+)$/);
+ my $number=$1;
+ if ($env{$key} eq 'delete') { $newrules[$number]=''; }
+ if (($env{$key} eq 'moveup') && ($number>1)) {
+ my $buffer=$newrules[$number];
+ $newrules[$number]=$newrules[$number-1];
+ $newrules[$number-1]=$buffer;
+ }
+ if (($env{$key} eq 'movedown') && ($number<$#newrules)) {
+ my $buffer=$newrules[$number];
+ $newrules[$number]=$newrules[$number+1];
+ $newrules[$number+1]=$buffer;
+ }
+ if ($env{$key} eq 'insertabove') {
+ for (my $i=$#newrules;$i>=$number;$i--) {
+ $newrules[$i+1]=$newrules[$i];
}
- }
-
+ $newrules[$number]='deny';
+ }
+ if ($env{$key} eq 'insertbelow') {
+ for (my $i=$#newrules;$i>$number;$i--) {
+ $newrules[$i+1]=$newrules[$i];
+ }
+ $newrules[$number+1]='deny';
+ }
+ }
+
# store file
- my $fh=Apache::File->new('>'.$fn);
- foreach (my $i=0;$i<=$#newrules;$i++) {
- if ($newrules[$i]) {
- my ($effect,$realm,$role)=split(/\:/,$newrules[$i]);
- print $fh
- "<accessrule effect='$effect' realm='$realm' role='$role' />\n";
- }
- }
- $fh->close;
+ my $fh=Apache::File->new('>'.$fn);
+ foreach (my $i=0;$i<=$#newrules;$i++) {
+ if ($newrules[$i]) {
+ my ($effect,$realm,$role,$type)=split(/\:/,$newrules[$i]);
+ print $fh
+ "<accessrule effect='$effect' realm='$realm' role='$role' type='$type' />\n";
+ }
}
+ $fh->close;
}
# ============================================================ Read and display
unless ($constructmode) {
@@ -178,17 +189,17 @@
'se' => 'Section',
'ro' => 'Role');
# ---------------------------------------------------------- Start table output
- $r->print(<<ENDSTARTTABLE);
-<table border="2">
- <tr><th>$colzero</th><th>$lt{'ef'}</th><th>$lt{'do'}</th><th>$lt{'co'}</th>
-<th>$lt{'se'}</th><th>$lt{'ro'}</th></tr>
-ENDSTARTTABLE
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ "<th>$colzero</th><th>$lt{'ef'}</th><th>Type</th><th>$lt{'do'}</th>".
+ "<th>$lt{'co'}</th><th>$lt{'se'}</th><th>$lt{'ro'}</th>".
+ &Apache::loncommon::end_data_table_header_row());
# --------------------------------------------------------------------- Default
# Fast forward to first rule
$token=$parser->get_token;
while ($token->[1] ne 'accessrule') { $token=$parser->get_token; }
# print default
- $r->print('<tr><td align="right">');
+ $r->print(&Apache::loncommon::start_data_table_row().'<td align="right">');
if ($constructmode) {
$r->print(&Apache::loncommon::select_form('','action_0',
('' => '',
@@ -206,19 +217,20 @@
} else {
$r->print($token->[2]->{'effect'});
}
- $r->print('</td><td colspan="4">Default');
+ $r->print('</td><td colspan="5">'.&mt('Default'));
if (($token->[2]->{'realm'}) || ($token->[2]->{'role'})) {
- $r->print(' - <font color="red">'.&mt('Error! No default set.').
- '</font>');
+ $r->print(' - <span class="LC_error">'.&mt('Error! No default set.').
+ '</span>');
}
- $r->print('</td></tr>');
+ $r->print('</td>'.&Apache::loncommon::end_data_table_row());
# Additional roles
while ($token=$parser->get_token) {
if (($token->[0] eq 'S') && ($token->[1] eq 'accessrule')) {
$rulecounter++;
- $r->print('<tr><td align="right" rowspan="2">');
+ $r->print(&Apache::loncommon::start_data_table_row().
+ '<td align="right" rowspan="2">');
# insert, delete, etc
- $r->print($rulecounter.'. ');
+ $r->print('<span class="LC_nobreak">'.$rulecounter.'. ');
if ($constructmode) {
$r->print(&Apache::loncommon::select_form(
'','action_'.$rulecounter,
@@ -229,7 +241,8 @@
'moveup' => 'Move rule up',
'movedown' => 'Move rule down')));
}
- $r->print('</td><td rowspan="2">');
+ $r->print('</span></td>'.
+ '<td rowspan="2">');
# effect
if ($constructmode) {
$r->print(&Apache::loncommon::select_form
@@ -240,12 +253,31 @@
} else {
$r->print($token->[2]->{'effect'});
}
- $r->print('</td><td>');
+
+# type
+ $r->print('</td><td rowspan="2">');
+ my $type = ($token->[2]{'type'} || 'course');
+ if ($constructmode) {
+ $r->print(&Apache::loncommon::select_form($type,
+ 'type_'.$rulecounter,
+ ('course' => 'Course',
+ 'user' => 'User')));
+ } else {
+ $r->print($type);
+ }
+
# ---- realm
my $realm=$token->[2]->{'realm'};
my ($rdom,$rcourse,$rsec)=split(/[\/\_]/,$realm);
$rdom = &LONCAPA::clean_domain($rdom);
- $rcourse = &LONCAPA::clean_courseid($rcourse);
+ if ($type eq 'course') {
+ $rcourse = &LONCAPA::clean_courseid($rcourse);
+ } else {
+ $rcourse = &LONCAPA::clean_username($rcourse);
+ }
+
+
+ $r->print('</td><td>');
# realm domain
if ($constructmode) {
unless ($rdom) { $rdom=$env{'user.domain'}; }
@@ -257,52 +289,69 @@
$r->print('</td><td>');
# realm course
if ($constructmode) {
- $r->print('<input input type="text" size="25" name="course_'.
+ $r->print('<input type="text" size="25" name="course_'.
$rulecounter.'" value="'.$rcourse.'" />');
} else {
$r->print($rcourse);
}
- $r->print('</td><td>');
+ $r->print('</td><td rowspan="2">');
# realm section
- if ($constructmode) {
- $r->print('<input input type="text" size="5" name="section_'.
- $rulecounter.'" value="'.$rsec.'" />');
- } else {
- $r->print($rsec);
- }
+ if ($type eq 'course') {
+ if ($constructmode) {
+ $r->print('<input type="text" size="5" name="section_'.
+ $rulecounter.'" value="'.$rsec.'" />');
+ } else {
+ $r->print($rsec);
+ }
+ }
$r->print('</td><td rowspan="2">');
# role
- if ($constructmode) {
- my %hash=('' => '');
- foreach ('au','cc','in','ta','st') {
- $hash{$_}=&Apache::lonnet::plaintext($_);
- }
- my $role=$token->[2]->{'role'};
- unless ($role) { $role=''; }
- $r->print(&Apache::loncommon::select_form(
- $role,'role_'.$rulecounter,%hash));
- } else {
- $r->print(&Apache::lonnet::plaintext($token->[2]->{'role'}));
- }
+ if ($type eq 'course') {
+ if ($constructmode) {
+ my %hash=('' => '');
+ foreach ('au','cc','in','ta','st') {
+ $hash{$_}=&Apache::lonnet::plaintext($_);
+ }
+ my $role=$token->[2]->{'role'};
+ unless ($role) { $role=''; }
+ $r->print(&Apache::loncommon::select_form(
+ $role,'role_'.$rulecounter,%hash));
+ } else {
+ $r->print(&Apache::lonnet::plaintext($token->[2]->{'role'}));
+ }
+ }
# course selection link
- $r->print('</td></tr><tr><td colspan="3" align="right">');
- if ($rcourse) {
- my %descript=
- &Apache::lonnet::coursedescription($rdom.'_'.$rcourse,
- {'one_time' => 1});
- $r->print($descript{'description'}.' ');
- }
- if ($constructmode) {
- $r->print(&Apache::loncommon::selectcourse_link('rules',
- 'course_'.$rulecounter,'domain_'.$rulecounter));
+ $r->print('</td>'.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::continue_data_table_row().
+ '<td colspan="2" align="right">');
+ if ($type eq 'course') {
+ if ($rcourse) {
+ my %descript=
+ &Apache::lonnet::coursedescription($rdom.'_'.$rcourse,
+ {'one_time' => 1});
+ $r->print($descript{'description'}.' ');
+ }
+ if ($constructmode) {
+ $r->print(&Apache::loncommon::selectcourse_link('rules',
+ 'course_'.$rulecounter,'domain_'.$rulecounter));
+ }
+ } else {
+ if ($rcourse) {
+ my $name = &Apache::loncommon::plainname($rcourse,$rdom);
+ $r->print($name.' ');
+ }
+ if ($constructmode) {
+ $r->print(&Apache::loncommon::selectstudent_link('rules','course_'.$rulecounter,'domain_'.$rulecounter));
+ }
}
# close row
- $r->print('</td></tr>');
+ $r->print('</td>'.&Apache::loncommon::end_data_table_row());
}
}
- $r->print('</table>');
+ $r->print(&Apache::loncommon::end_data_table());
# ------------------------------------------------------------ End table output
if ($constructmode) {
$r->print('<input type="submit" name="store" value="'.&mt('Save').'" /></form>');
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.368 loncom/xml/londefdef.pm:1.369
--- loncom/xml/londefdef.pm:1.368 Tue Jun 19 16:25:45 2007
+++ loncom/xml/londefdef.pm Thu Jun 21 20:11:32 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.368 2007/06/19 20:25:45 banghart Exp $
+# $Id: londefdef.pm,v 1.369 2007/06/22 00:11:32 albertel Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -481,13 +481,21 @@
('realm',$parstack,$safeeval,undef,1);
my $role=&Apache::lonxml::get_param
('role',$parstack,$safeeval,undef,1);
- $realm=~s/\s+//g;
- $realm=~s/\//\_/g;
- $realm=~s/^\_//;
- $realm=~s/\W/\;/g;
- $role=~s/\s+//g;
- $role=~s/\//\_/g;
- $role=~s/\W/\;/g;
+ my ($dom,$crs,$sec)=split(/\_/,$realm);
+ $dom = &LONCAPA::clean_domain($dom);
+ my $type=&Apache::lonxml::get_param
+ ('type',$parstack,$safeeval,undef,1);
+ if ($type eq 'user') {
+ $crs = &LONCAPA::clean_username($crs);
+ } else {
+ $crs = &LONCAPA::clean_courseid($crs);
+ }
+ $sec =~s/\W//;
+ $realm = $dom;
+ if ($crs =~ /\S/) { $realm .= '_'.$crs; }
+ if ($sec =~ /\S/) { $realm .= '_'.$sec; }
+ $role=~s/\W//g;
+
if ($target eq 'web') {
my $args='';
if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
@@ -498,7 +506,7 @@
}
}
if ($target eq 'meta') {
- $currentstring='<rule>'.$eff.':'.$realm.':'.$role.'</rule>';
+ $currentstring='<rule>'.$eff.':'.$realm.':'.$role.':'.$type.'</rule>';
}
return $currentstring;
}
--albertel1182471097--