source: trunk/core/lib/Foswiki/If/OP_allows.pm @ 1050

Revision 1050, 8.3 KB checked in by OlivierRaginel, 4 years ago (diff)

Item329: Fixed tagline

Line 
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
9package Foswiki::If::OP_allows;
10use base 'Foswiki::Query::BinaryOP';
11
12use strict;
13
14sub new {
15    my $class = shift;
16    return $class->SUPER::new( name => 'allows', prec => 600 );
17}
18
19sub 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
611;
62
63__DATA__
64
65Module 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#
78This program is free software; you can redistribute it and/or
79modify it under the terms of the GNU General Public License
80as published by the Free Software Foundation; either version 2
81of the License, or (at your option) any later version. For
82more details read LICENSE in the root of this distribution.
83
84This program is distributed in the hope that it will be useful,
85but WITHOUT ANY WARRANTY; without even the implied warranty of
86MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
87
88As per the GPL, removal of this notice is prohibited.
89
90Author: 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
99package Foswiki::If::OP_allows;
100use base 'Foswiki::Query::BinaryOP';
101
102use strict;
103
104sub new {
105    my $class = shift;
106    return $class->SUPER::new( name => 'allows', prec => 600 );
107}
108
109sub 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
1411;
142
143__DATA__
144
145Module 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#
158This program is free software; you can redistribute it and/or
159modify it under the terms of the GNU General Public License
160as published by the Free Software Foundation; either version 2
161of the License, or (at your option) any later version. For
162more details read LICENSE in the root of this distribution.
163
164This program is distributed in the hope that it will be useful,
165but WITHOUT ANY WARRANTY; without even the implied warranty of
166MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
167
168As per the GPL, removal of this notice is prohibited.
169
170Author: 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
179package Foswiki::If::OP_allows;
180use base 'Foswiki::Query::BinaryOP';
181
182use strict;
183
184sub new {
185    my $class = shift;
186    return $class->SUPER::new( name => 'allows', prec => 600 );
187}
188
189sub 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
2211;
222
223__DATA__
224
225Module 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#
238This program is free software; you can redistribute it and/or
239modify it under the terms of the GNU General Public License
240as published by the Free Software Foundation; either version 2
241of the License, or (at your option) any later version. For
242more details read LICENSE in the root of this distribution.
243
244This program is distributed in the hope that it will be useful,
245but WITHOUT ANY WARRANTY; without even the implied warranty of
246MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
247
248As per the GPL, removal of this notice is prohibited.
249
250Author: Crawford Currie http://c-dot.co.uk
Note: See TracBrowser for help on using the repository browser.