line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Root.pm,v 1.24 2005/02/03 00:06:30 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2001 Online Office Berlin. All rights reserved. |
8
|
|
|
|
|
|
|
# Copyright (C) 2002 Slaven Rezic. |
9
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
10
|
|
|
|
|
|
|
# terms of the GNU General Public License, see the file COPYING. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
14
|
|
|
|
|
|
|
# WWW: http://we-framework.sourceforge.net |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package WE_Singlesite::Root; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
WE_Singlesite::Root - a simple implementation for a site |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$root = new WE_Singlesite::Root -rootdir => $root_directory_for_database; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
A simple instantiation for C. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 ADDITIONAL MEMBERS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item RootDir |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The root directory for all databases. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 OVERRIDEABLE METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
To change the default classes for the subdatabases, override the |
44
|
|
|
|
|
|
|
following methods to return another class string: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item ObjDBClass |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
By default L |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item UserDBClass |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
By default L |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item ContentDBClass |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
By default L |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item OnlineUserDBClass |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
By default L |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item NameDBClass |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
By default L |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=back |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
To change the default file names for the subdatabases, override the |
71
|
|
|
|
|
|
|
following methods to return another filename (just the basename): |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item ObjDBFile |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
By default F |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item UserDBFile |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
By default F |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item ContentDBFile |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
By default F |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item OnlineUserDBFile |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
By default F |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item NameDBFile |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
By default F |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
To change other aspects of the subdatabases, change the following |
98
|
|
|
|
|
|
|
methods (B: The semantics of the following two may |
99
|
|
|
|
|
|
|
change!!!): |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item SerializerClass |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
By default Data::Dumper |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item DBClass |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
By default DB_File |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
13
|
|
|
13
|
|
86935
|
use base qw(WE::DB); |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
17225
|
|
120
|
|
|
|
|
|
|
# Unfortunately old projects rely on this "use": |
121
|
13
|
|
|
13
|
|
12863
|
use WE::Obj; |
|
13
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
99
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/RootDir/); |
124
|
|
|
|
|
|
|
|
125
|
13
|
|
|
13
|
|
733
|
use strict; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
404
|
|
126
|
13
|
|
|
13
|
|
65
|
use vars qw($VERSION); |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
29358
|
|
127
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.24 $ =~ /(\d+)\.(\d+)/); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub new { |
130
|
0
|
|
|
0
|
1
|
|
my($class, %args) = @_; |
131
|
0
|
|
|
|
|
|
my $self = {}; |
132
|
0
|
|
|
|
|
|
bless $self, $class; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $db_dir = delete $args{-rootdir}; |
135
|
0
|
0
|
|
|
|
|
die "No -rootdir given" if !defined $db_dir; |
136
|
0
|
|
|
|
|
|
$self->RootDir($db_dir); |
137
|
0
|
0
|
|
|
|
|
my $readonly = defined $args{-readonly} ? delete $args{-readonly} : 0; |
138
|
0
|
|
0
|
|
|
|
my $autocreate = delete $args{-autocreate} || 0; |
139
|
0
|
0
|
0
|
|
|
|
if (!-d $db_dir && $autocreate) { |
140
|
0
|
|
|
|
|
|
require File::Path; |
141
|
0
|
|
|
|
|
|
File::Path::mkpath($db_dir); |
142
|
|
|
|
|
|
|
} |
143
|
0
|
0
|
0
|
|
|
|
if (!$readonly && !-w $db_dir) { |
144
|
0
|
|
|
|
|
|
die "The -rootdir $db_dir is not writable (needed for lockfiles etc.)"; |
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
my $connect = $args{-connect}; |
147
|
0
|
0
|
|
|
|
|
my $writeonly = defined $args{-writeonly} ? delete $args{-writeonly} : 0; |
148
|
0
|
0
|
|
|
|
|
my $locking = defined $args{-locking} ? delete $args{-locking} : 1; |
149
|
0
|
0
|
|
|
|
|
my $serializer = defined $args{-serializer} ? delete $args{-serializer} : $self->SerializerClass; |
150
|
0
|
0
|
|
|
|
|
my $failsafe = defined $args{-failsafe} ? delete $args{-failsafe} : 0; |
151
|
0
|
0
|
|
|
|
|
my $db = defined $args{-db} ? delete $args{-db} : $self->DBClass; |
152
|
0
|
0
|
|
|
|
|
my $cache = defined $args{-cache} ? delete $args{-cache} : 0; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
if ($self->ObjDBClass) { |
155
|
0
|
|
|
|
|
|
$self->use_databases($self->ObjDBClass); |
156
|
0
|
|
|
|
|
|
eval { |
157
|
0
|
|
|
|
|
|
$self->ObjDB |
158
|
|
|
|
|
|
|
($self->ObjDBClass->new($self, "$db_dir/" . $self->ObjDBFile, |
159
|
|
|
|
|
|
|
-connect => $connect, |
160
|
|
|
|
|
|
|
-readonly => $readonly, |
161
|
|
|
|
|
|
|
-writeonly => $writeonly, |
162
|
|
|
|
|
|
|
-locking => $locking, |
163
|
|
|
|
|
|
|
-serializer => $serializer, |
164
|
|
|
|
|
|
|
-db => $db, |
165
|
|
|
|
|
|
|
-cache => $cache, |
166
|
|
|
|
|
|
|
)); |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
WE::Obj->use_classes(':all'); |
169
|
|
|
|
|
|
|
}; |
170
|
0
|
0
|
|
|
|
|
if ($@) { |
171
|
0
|
0
|
|
|
|
|
$failsafe ? warn $@ : die $@; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
if ($self->UserDBClass) { |
176
|
0
|
|
|
|
|
|
$self->use_databases($self->UserDBClass); |
177
|
0
|
|
|
|
|
|
eval { |
178
|
0
|
|
|
|
|
|
$self->UserDB |
179
|
|
|
|
|
|
|
($self->UserDBClass->new($self, "$db_dir/" . $self->UserDBFile, |
180
|
|
|
|
|
|
|
-connect => $connect, |
181
|
|
|
|
|
|
|
-readonly => $readonly, |
182
|
|
|
|
|
|
|
-writeonly => $writeonly, |
183
|
|
|
|
|
|
|
)); |
184
|
|
|
|
|
|
|
}; |
185
|
0
|
0
|
|
|
|
|
if ($@) { |
186
|
0
|
0
|
|
|
|
|
$failsafe ? warn $@ : die $@; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
0
|
|
|
|
|
if ($self->ContentDBClass) { |
191
|
0
|
|
|
|
|
|
$self->use_databases($self->ContentDBClass); |
192
|
0
|
|
|
|
|
|
eval { |
193
|
0
|
|
|
|
|
|
$self->ContentDB |
194
|
|
|
|
|
|
|
($self->ContentDBClass->new($self, "$db_dir/" . $self->ContentDBFile, |
195
|
|
|
|
|
|
|
-connect => $connect, |
196
|
|
|
|
|
|
|
-readonly => $readonly, |
197
|
|
|
|
|
|
|
-writeonly => $writeonly, |
198
|
|
|
|
|
|
|
)); |
199
|
|
|
|
|
|
|
}; |
200
|
0
|
0
|
|
|
|
|
if ($@) { |
201
|
0
|
0
|
|
|
|
|
$failsafe ? warn $@ : die $@; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
if ($self->OnlineUserDBClass) { |
206
|
0
|
|
|
|
|
|
$self->use_databases($self->OnlineUserDBClass); |
207
|
0
|
|
|
|
|
|
eval { |
208
|
0
|
|
|
|
|
|
$self->OnlineUserDB |
209
|
|
|
|
|
|
|
($self->OnlineUserDBClass->new($self, "$db_dir/" . $self->OnlineUserDBFile, |
210
|
|
|
|
|
|
|
-connect => $connect, |
211
|
|
|
|
|
|
|
-readonly => $readonly, |
212
|
|
|
|
|
|
|
-writeonly => $writeonly, |
213
|
|
|
|
|
|
|
)); |
214
|
|
|
|
|
|
|
}; |
215
|
0
|
0
|
|
|
|
|
if ($@) { |
216
|
0
|
0
|
|
|
|
|
$failsafe ? warn $@ : die $@; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
if ($self->NameDBClass) { |
221
|
0
|
|
|
|
|
|
$self->use_databases($self->NameDBClass); |
222
|
0
|
|
|
|
|
|
eval { |
223
|
0
|
|
|
|
|
|
$self->NameDB |
224
|
|
|
|
|
|
|
($self->NameDBClass->new($self, "$db_dir/" . $self->NameDBFile, |
225
|
|
|
|
|
|
|
-connect => $connect, |
226
|
|
|
|
|
|
|
-readonly => $readonly, |
227
|
|
|
|
|
|
|
-writeonly => $writeonly, |
228
|
|
|
|
|
|
|
)); |
229
|
|
|
|
|
|
|
}; |
230
|
0
|
0
|
|
|
|
|
if ($@) { |
231
|
0
|
0
|
|
|
|
|
$failsafe ? warn $@ : die $@; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
$self; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
0
|
1
|
|
sub ObjDBClass { "WE::DB::Obj" } |
239
|
0
|
|
|
0
|
1
|
|
sub UserDBClass { "WE::DB::User" } |
240
|
0
|
|
|
0
|
1
|
|
sub ContentDBClass { "WE::DB::Content" } |
241
|
0
|
|
|
0
|
1
|
|
sub OnlineUserDBClass { "WE::DB::OnlineUser" } |
242
|
0
|
|
|
0
|
1
|
|
sub NameDBClass { "WE::DB::Name" } |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
0
|
1
|
|
sub ObjDBFile { "objdb.db" } |
245
|
0
|
|
|
0
|
1
|
|
sub UserDBFile { "userdb.db" } |
246
|
0
|
|
|
0
|
1
|
|
sub ContentDBFile { "content" } |
247
|
0
|
|
|
0
|
1
|
|
sub OnlineUserDBFile { "onlinedb.db" } |
248
|
0
|
|
|
0
|
1
|
|
sub NameDBFile { "name.db" } |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
0
|
1
|
|
sub SerializerClass { "Data::Dumper" } |
251
|
0
|
|
|
0
|
1
|
|
sub DBClass { "DB_File" } |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub disconnect { |
254
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
255
|
0
|
|
|
|
|
|
$self->ObjDB->disconnect; |
256
|
0
|
|
|
|
|
|
$self->UserDB->disconnect; |
257
|
|
|
|
|
|
|
# $self->ContentDB->disconnect; |
258
|
0
|
|
|
|
|
|
$self->OnlineUserDB->disconnect; |
259
|
0
|
|
|
|
|
|
$self->NameDB->disconnect; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub init { |
263
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
264
|
0
|
|
|
|
|
|
$self->SUPER::init(@_); |
265
|
0
|
|
|
|
|
|
my $u = $self->UserDB; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub export_db { |
269
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
270
|
0
|
0
|
|
|
|
|
$args{-as} = 'perl' if !exists $args{-as}; |
271
|
0
|
0
|
|
|
|
|
$args{-db} = [qw(ObjDB UserDB OnlineUserDB NameDB)] if !exists $args{-db}; |
272
|
0
|
0
|
|
|
|
|
if ($args{-as} eq 'perl') { |
273
|
0
|
|
|
|
|
|
my @obj; |
274
|
0
|
|
|
|
|
|
my @varnames = @{$args{-db}}; |
|
0
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
foreach my $db (@{$args{-db}}) { |
|
0
|
|
|
|
|
|
|
276
|
0
|
0
|
|
|
|
|
my $db_obj = eval '$self->'.$db; die $@ if $@; # for 5.005 |
|
0
|
|
|
|
|
|
|
277
|
0
|
0
|
0
|
|
|
|
if ($db_obj->can('Connected') && !$db_obj->Connected) { |
278
|
0
|
|
|
|
|
|
die "The export_db method requires a permanent connection to the database $db"; |
279
|
|
|
|
|
|
|
} |
280
|
0
|
|
|
|
|
|
push @obj, $db_obj->{DB}; |
281
|
|
|
|
|
|
|
} |
282
|
0
|
|
|
|
|
|
require Data::Dumper; |
283
|
0
|
|
|
|
|
|
my $dd = Data::Dumper->new([@obj], [@varnames]); |
284
|
0
|
|
|
|
|
|
$dd->Indent(0); # for Windows |
285
|
0
|
|
|
|
|
|
return $dd->Dump; |
286
|
|
|
|
|
|
|
} else { |
287
|
0
|
|
|
|
|
|
die "Export type $args{-as} is not implemented"; |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub import_db { |
292
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
293
|
0
|
0
|
|
|
|
|
$args{-as} = 'perl' if !exists $args{-as}; |
294
|
0
|
0
|
|
|
|
|
die "No -string option given" if !defined $args{-string}; |
295
|
0
|
|
|
|
|
|
require Safe; |
296
|
0
|
|
|
|
|
|
my $pkg = __PACKAGE__ . '::Safe'; |
297
|
0
|
|
|
|
|
|
my $cpt = Safe->new($pkg); |
298
|
0
|
|
|
|
|
|
$cpt->reval($args{-string}); |
299
|
0
|
|
|
|
|
|
foreach my $db (qw(ObjDB UserDB OnlineUserDB NameDB)) { |
300
|
0
|
0
|
|
|
|
|
my $db_obj = eval '$self->'.$db; die $@ if $@; # for 5.005 |
|
0
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
my $o = eval "\$${pkg}::$db"; |
302
|
0
|
0
|
|
|
|
|
if (defined $o) { |
303
|
0
|
|
|
|
|
|
%{$db_obj->{DB}} = %$o; |
|
0
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
sub get_permissions { |
309
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
310
|
0
|
|
|
|
|
|
require WE::Util::Permissions; |
311
|
0
|
|
|
|
|
|
my $new_location = $self->RootDir . "/../etc/permissions"; |
312
|
0
|
|
|
|
|
|
my $permfile = $self->RootDir . "/permissions"; |
313
|
0
|
0
|
|
|
|
|
if (-e $permfile) { |
|
|
0
|
|
|
|
|
|
314
|
0
|
|
|
|
|
|
warn "Detected permissions file at old location. Please consider to move the file to $new_location"; |
315
|
|
|
|
|
|
|
} elsif (-e $new_location) { |
316
|
0
|
|
|
|
|
|
$permfile = $new_location; |
317
|
|
|
|
|
|
|
} else { |
318
|
0
|
|
|
|
|
|
warn "Cannot find permissions file in $new_location"; |
319
|
|
|
|
|
|
|
} |
320
|
0
|
|
|
|
|
|
my $perm = WE::Util::Permissions->new(-file => $permfile); |
321
|
0
|
|
|
|
|
|
$self->{Permissions} = $perm; |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=item is_allowed($action, $object_id) |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
Return a true value if the current user is allowed to do C<$action> on |
327
|
|
|
|
|
|
|
object C<$object_id>. |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Currently are these actions defined: |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=over 4 |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=item release |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
The user is allowed to release a document ("freigeben"). |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=item publish |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
The user is allowed to publish a site. |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=item change-folder |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
The user is allowed to do folder manipulation, that is, he is allowed |
344
|
|
|
|
|
|
|
to add or delete folders. |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=item change-doc |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
The user is allowed to do document manipulation, that is, he is |
349
|
|
|
|
|
|
|
allowed to add, edit or delete documents. |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=back |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
If there is no current user, then always a false value is returned. |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=cut |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub is_allowed { |
358
|
0
|
|
|
0
|
1
|
|
my($self, $action, $obj_id) = @_; |
359
|
0
|
|
|
|
|
|
my $user = $self->CurrentUser; |
360
|
0
|
0
|
|
|
|
|
return 0 if !$user; |
361
|
0
|
|
|
|
|
|
my $permissions = $self->{Permissions}; |
362
|
0
|
0
|
|
|
|
|
if (!$permissions) { |
363
|
0
|
|
|
|
|
|
$permissions = $self->get_permissions; |
364
|
|
|
|
|
|
|
} |
365
|
0
|
|
|
|
|
|
my $path; |
366
|
0
|
0
|
|
|
|
|
if (defined $obj_id) { |
367
|
0
|
|
|
|
|
|
$path = $self->ObjDB->pathname($obj_id); |
368
|
|
|
|
|
|
|
} |
369
|
0
|
|
|
|
|
|
my $group = $self->CurrentGroups; |
370
|
0
|
0
|
0
|
|
|
|
$permissions->is_allowed |
|
|
0
|
|
|
|
|
|
371
|
|
|
|
|
|
|
(-user => $user, |
372
|
|
|
|
|
|
|
($group && ref $group && @$group > 0 ? (-group => $group) : ()), |
373
|
|
|
|
|
|
|
(defined $path ? (-page => $path) : ()), |
374
|
|
|
|
|
|
|
-process => $action, |
375
|
|
|
|
|
|
|
); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub is_releasable_page { |
379
|
0
|
|
|
0
|
1
|
|
my($self, $obj) = @_; |
380
|
0
|
|
|
|
|
|
my $objdb = $self->ObjDB; |
381
|
0
|
|
|
|
|
|
$objdb->objectify_params($obj); |
382
|
0
|
|
0
|
|
|
|
my $release_state = $obj->Release_State || ""; |
383
|
0
|
0
|
|
|
|
|
return 0 if $release_state eq 'inactive'; |
384
|
0
|
|
|
|
|
|
return 1; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=item release_page($obj, %args) |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
Release the page with object $obj. Pass the object, not the id. If the |
390
|
|
|
|
|
|
|
value of the C<-useversioning> argument is true, then do a check-in of |
391
|
|
|
|
|
|
|
the released objects (see also C in C). |
392
|
|
|
|
|
|
|
The arguments C, C and C are used, if |
393
|
|
|
|
|
|
|
defined, to set the respective object members. |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
=cut |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
sub release_page { |
398
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
399
|
0
|
|
|
|
|
|
my $newobj = shift; |
400
|
0
|
|
|
|
|
|
my %args = @_; |
401
|
0
|
0
|
|
|
|
|
if (!defined $newobj) { |
402
|
0
|
|
|
|
|
|
die "Object is missing in release_page"; |
403
|
|
|
|
|
|
|
} |
404
|
0
|
|
|
|
|
|
my $objdb = $self->ObjDB; |
405
|
0
|
|
|
|
|
|
my $useversioning = delete $args{-useversioning}; |
406
|
0
|
|
|
|
|
|
my $pid = $newobj->Id; |
407
|
|
|
|
|
|
|
|
408
|
0
|
|
|
|
|
|
my $versionedobj; |
409
|
0
|
0
|
|
|
|
|
if ($useversioning) { |
410
|
0
|
|
|
|
|
|
$versionedobj = $objdb->ci($pid); |
411
|
0
|
|
|
|
|
|
$versionedobj->{Release_State} = "released"; |
412
|
|
|
|
|
|
|
# XXX have to re-get the object because ci changed it! |
413
|
0
|
|
|
|
|
|
$newobj = $objdb->get_object($pid); |
414
|
|
|
|
|
|
|
} |
415
|
0
|
|
|
|
|
|
$newobj->{Release_State} = "released"; |
416
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
foreach my $copykey (qw(Title VisibleToMenu Rights)) { |
418
|
0
|
0
|
|
|
|
|
if (defined $args{$copykey}) { |
419
|
0
|
0
|
|
|
|
|
$versionedobj->{$copykey} = $args{$copykey} if $versionedobj; |
420
|
0
|
|
|
|
|
|
$newobj->{$copykey} = $args{$copykey}; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
} |
423
|
0
|
0
|
|
|
|
|
$objdb->replace_object($versionedobj) if $versionedobj; |
424
|
0
|
|
|
|
|
|
$objdb->replace_object($newobj); |
425
|
|
|
|
|
|
|
|
426
|
0
|
|
|
|
|
|
$newobj; |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
1; |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
__END__ |