| 1 | # See bottom of file for copyright and license details |
|---|
| 2 | |
|---|
| 3 | =begin TML |
|---|
| 4 | |
|---|
| 5 | ---+ package Foswiki::If::OP_allows |
|---|
| 6 | |
|---|
| 7 | =cut |
|---|
| 8 | |
|---|
| 9 | package Foswiki::If::OP_allows; |
|---|
| 10 | use base 'Foswiki::Query::BinaryOP'; |
|---|
| 11 | |
|---|
| 12 | use strict; |
|---|
| 13 | |
|---|
| 14 | sub new { |
|---|
| 15 | my $class = shift; |
|---|
| 16 | return $class->SUPER::new( name => 'allows', prec => 600 ); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | sub evaluate { |
|---|
| 20 | my $this = shift; |
|---|
| 21 | my $node = shift; |
|---|
| 22 | my $a = $node->{params}->[0]; # topic name (string) |
|---|
| 23 | my $b = $node->{params}->[1]; # access mode (string) |
|---|
| 24 | my $mode = $b->_evaluate(@_) || 'view'; |
|---|
| 25 | my %domain = @_; |
|---|
| 26 | my $session = $domain{tom}->session; |
|---|
| 27 | throw Error::Simple( |
|---|
| 28 | 'No context in which to evaluate "' . $a->stringify() . '"' ) |
|---|
| 29 | unless $session; |
|---|
| 30 | my $str = $a->evaluate(@_); |
|---|
| 31 | return 0 unless $str; |
|---|
| 32 | my ( $web, $topic ) = |
|---|
| 33 | $session->normalizeWebTopicName( $session->{webName}, $str ); |
|---|
| 34 | my $ok = 0; |
|---|
| 35 | |
|---|
| 36 | if ( $session->{store}->topicExists( $web, $topic ) ) { |
|---|
| 37 | |
|---|
| 38 | #try the non-precise name as an existant topic first. |
|---|
| 39 | $ok = |
|---|
| 40 | $session->security->checkAccessPermission( uc($mode), |
|---|
| 41 | $session->{user}, undef, undef, $topic, $web ); |
|---|
| 42 | } |
|---|
| 43 | elsif ( $session->{store}->webExists($str) ) { |
|---|
| 44 | $ok = |
|---|
| 45 | $session->security->checkAccessPermission( uc($mode), |
|---|
| 46 | $session->{user}, undef, undef, undef, $str ); |
|---|
| 47 | } |
|---|
| 48 | elsif ( $session->{store}->webExists($web) ) { |
|---|
| 49 | |
|---|
| 50 | #not an existing topic or web - assume any lone name is a topic without a web specified |
|---|
| 51 | $ok = |
|---|
| 52 | $session->security->checkAccessPermission( uc($mode), |
|---|
| 53 | $session->{user}, undef, undef, $topic, $web ); |
|---|
| 54 | } |
|---|
| 55 | else { |
|---|
| 56 | $ok = 0; |
|---|
| 57 | } |
|---|
| 58 | return $ok ? 1 : 0; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | 1; |
|---|
| 62 | |
|---|
| 63 | __DATA__ |
|---|
| 64 | |
|---|
| 65 | Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/ |
|---|
| 66 | |
|---|
| 67 | # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. |
|---|
| 68 | # Foswiki Contributors are listed in the AUTHORS file in the root |
|---|
| 69 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 70 | # |
|---|
| 71 | # Additional copyrights apply to some or all of the code in this |
|---|
| 72 | # file as follows: |
|---|
| 73 | # |
|---|
| 74 | # Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved. |
|---|
| 75 | # TWiki Contributors are listed in the AUTHORS file in the root |
|---|
| 76 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 77 | # |
|---|
| 78 | This program is free software; you can redistribute it and/or |
|---|
| 79 | modify it under the terms of the GNU General Public License |
|---|
| 80 | as published by the Free Software Foundation; either version 2 |
|---|
| 81 | of the License, or (at your option) any later version. For |
|---|
| 82 | more details read LICENSE in the root of this distribution. |
|---|
| 83 | |
|---|
| 84 | This program is distributed in the hope that it will be useful, |
|---|
| 85 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 86 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 87 | |
|---|
| 88 | As per the GPL, removal of this notice is prohibited. |
|---|
| 89 | |
|---|
| 90 | Author: Crawford Currie http://c-dot.co.uk |
|---|
| 91 | # See bottom of file for copyright and license details |
|---|
| 92 | |
|---|
| 93 | =begin TML |
|---|
| 94 | |
|---|
| 95 | ---+ package Foswiki::If::OP_allows |
|---|
| 96 | |
|---|
| 97 | =cut |
|---|
| 98 | |
|---|
| 99 | package Foswiki::If::OP_allows; |
|---|
| 100 | use base 'Foswiki::Query::BinaryOP'; |
|---|
| 101 | |
|---|
| 102 | use strict; |
|---|
| 103 | |
|---|
| 104 | sub new { |
|---|
| 105 | my $class = shift; |
|---|
| 106 | return $class->SUPER::new( name => 'allows', prec => 600 ); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | sub evaluate { |
|---|
| 110 | my $this = shift; |
|---|
| 111 | my $node = shift; |
|---|
| 112 | my $a = $node->{params}->[0]; # topic name (string) |
|---|
| 113 | my $b = $node->{params}->[1]; # access mode (string) |
|---|
| 114 | my $mode = $b->_evaluate(@_) || 'view'; |
|---|
| 115 | my %domain = @_; |
|---|
| 116 | my $session = $domain{tom}->session; |
|---|
| 117 | throw Error::Simple('No context in which to evaluate "'. |
|---|
| 118 | $a->stringify().'"') unless $session; |
|---|
| 119 | my $str = $a->evaluate(@_); |
|---|
| 120 | return 0 unless $str; |
|---|
| 121 | my ($web, $topic) = $session->normalizeWebTopicName( |
|---|
| 122 | $session->{webName}, $str); |
|---|
| 123 | my $ok = 0; |
|---|
| 124 | if ($session->{store}->topicExists($web, $topic)) { |
|---|
| 125 | #try the non-precise name as an existant topic first. |
|---|
| 126 | $ok = $session->security->checkAccessPermission( |
|---|
| 127 | uc($mode), $session->{user}, undef, undef, $topic, $web); |
|---|
| 128 | } elsif ($session->{store}->webExists($str)) { |
|---|
| 129 | $ok = $session->security->checkAccessPermission( |
|---|
| 130 | uc($mode), $session->{user}, undef, undef, undef, $str); |
|---|
| 131 | } elsif ($session->{store}->webExists($web)) { |
|---|
| 132 | #not an existing topic or web - assume any lone name is a topic without a web specified |
|---|
| 133 | $ok = $session->security->checkAccessPermission( |
|---|
| 134 | uc($mode), $session->{user}, undef, undef, $topic, $web); |
|---|
| 135 | } else { |
|---|
| 136 | $ok = 0; |
|---|
| 137 | } |
|---|
| 138 | return $ok ? 1 : 0; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | 1; |
|---|
| 142 | |
|---|
| 143 | __DATA__ |
|---|
| 144 | |
|---|
| 145 | Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/ |
|---|
| 146 | |
|---|
| 147 | # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. |
|---|
| 148 | # Foswiki Contributors are listed in the AUTHORS file in the root |
|---|
| 149 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 150 | # |
|---|
| 151 | # Additional copyrights apply to some or all of the code in this |
|---|
| 152 | # file as follows: |
|---|
| 153 | # |
|---|
| 154 | # Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved. |
|---|
| 155 | # TWiki Contributors are listed in the AUTHORS file in the root |
|---|
| 156 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 157 | # |
|---|
| 158 | This program is free software; you can redistribute it and/or |
|---|
| 159 | modify it under the terms of the GNU General Public License |
|---|
| 160 | as published by the Free Software Foundation; either version 2 |
|---|
| 161 | of the License, or (at your option) any later version. For |
|---|
| 162 | more details read LICENSE in the root of this distribution. |
|---|
| 163 | |
|---|
| 164 | This program is distributed in the hope that it will be useful, |
|---|
| 165 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 166 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 167 | |
|---|
| 168 | As per the GPL, removal of this notice is prohibited. |
|---|
| 169 | |
|---|
| 170 | Author: Crawford Currie http://c-dot.co.uk |
|---|
| 171 | # See bottom of file for copyright and license details |
|---|
| 172 | |
|---|
| 173 | =begin TML |
|---|
| 174 | |
|---|
| 175 | ---+ package Foswiki::If::OP_allows |
|---|
| 176 | |
|---|
| 177 | =cut |
|---|
| 178 | |
|---|
| 179 | package Foswiki::If::OP_allows; |
|---|
| 180 | use base 'Foswiki::Query::BinaryOP'; |
|---|
| 181 | |
|---|
| 182 | use strict; |
|---|
| 183 | |
|---|
| 184 | sub new { |
|---|
| 185 | my $class = shift; |
|---|
| 186 | return $class->SUPER::new( name => 'allows', prec => 600 ); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | sub evaluate { |
|---|
| 190 | my $this = shift; |
|---|
| 191 | my $node = shift; |
|---|
| 192 | my $a = $node->{params}->[0]; # topic name (string) |
|---|
| 193 | my $b = $node->{params}->[1]; # access mode (string) |
|---|
| 194 | my $mode = $b->_evaluate(@_) || 'view'; |
|---|
| 195 | my %domain = @_; |
|---|
| 196 | my $session = $domain{tom}->session; |
|---|
| 197 | throw Error::Simple('No context in which to evaluate "'. |
|---|
| 198 | $a->stringify().'"') unless $session; |
|---|
| 199 | my $str = $a->evaluate(@_); |
|---|
| 200 | return 0 unless $str; |
|---|
| 201 | my ($web, $topic) = $session->normalizeWebTopicName( |
|---|
| 202 | $session->{webName}, $str); |
|---|
| 203 | my $ok = 0; |
|---|
| 204 | if ($session->{store}->topicExists($web, $topic)) { |
|---|
| 205 | #try the non-precise name as an existant topic first. |
|---|
| 206 | $ok = $session->security->checkAccessPermission( |
|---|
| 207 | uc($mode), $session->{user}, undef, undef, $topic, $web); |
|---|
| 208 | } elsif ($session->{store}->webExists($str)) { |
|---|
| 209 | $ok = $session->security->checkAccessPermission( |
|---|
| 210 | uc($mode), $session->{user}, undef, undef, undef, $str); |
|---|
| 211 | } elsif ($session->{store}->webExists($web)) { |
|---|
| 212 | #not an existing topic or web - assume any lone name is a topic without a web specified |
|---|
| 213 | $ok = $session->security->checkAccessPermission( |
|---|
| 214 | uc($mode), $session->{user}, undef, undef, $topic, $web); |
|---|
| 215 | } else { |
|---|
| 216 | $ok = 0; |
|---|
| 217 | } |
|---|
| 218 | return $ok ? 1 : 0; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | 1; |
|---|
| 222 | |
|---|
| 223 | __DATA__ |
|---|
| 224 | |
|---|
| 225 | Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/ |
|---|
| 226 | |
|---|
| 227 | # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. |
|---|
| 228 | # Foswiki Contributors are listed in the AUTHORS file in the root |
|---|
| 229 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 230 | # |
|---|
| 231 | # Additional copyrights apply to some or all of the code in this |
|---|
| 232 | # file as follows: |
|---|
| 233 | # |
|---|
| 234 | # Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved. |
|---|
| 235 | # TWiki Contributors are listed in the AUTHORS file in the root |
|---|
| 236 | # of this distribution. NOTE: Please extend that file, not this notice. |
|---|
| 237 | # |
|---|
| 238 | This program is free software; you can redistribute it and/or |
|---|
| 239 | modify it under the terms of the GNU General Public License |
|---|
| 240 | as published by the Free Software Foundation; either version 2 |
|---|
| 241 | of the License, or (at your option) any later version. For |
|---|
| 242 | more details read LICENSE in the root of this distribution. |
|---|
| 243 | |
|---|
| 244 | This program is distributed in the hope that it will be useful, |
|---|
| 245 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 246 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 247 | |
|---|
| 248 | As per the GPL, removal of this notice is prohibited. |
|---|
| 249 | |
|---|
| 250 | Author: Crawford Currie http://c-dot.co.uk |
|---|