line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Root.pm,v 1.7 2005/02/03 00:06:29 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_Sample::Root; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
WE_Sample::Root - a sample implementation for a site |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$root = new WE_Sample::Root -rootdir => $root_directory_for_database; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
A sample instantiation for C. This is mainly used for the |
30
|
|
|
|
|
|
|
WE_Framework test suite. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
12
|
|
|
12
|
|
59826
|
use base qw(WE_Singlesite::Root); |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
8083
|
|
39
|
12
|
|
|
12
|
|
91
|
use WE::Obj; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
59
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
WE::Obj->use_classes(':all'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
WE::DB->use_databases(qw/Obj User Content OnlineUser Name/); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#WE::DB->use_databases(qw/Obj ComplexUser Content OnlineUser Name/); |
46
|
|
|
|
|
|
|
#sub UserDBClass { "WE::DB::ComplexUser" } |
47
|
|
|
|
|
|
|
|
48
|
12
|
|
|
12
|
|
741
|
use strict; |
|
12
|
|
|
|
|
39
|
|
|
12
|
|
|
|
|
399
|
|
49
|
12
|
|
|
12
|
|
63
|
use vars qw($VERSION); |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
6832
|
|
50
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item is_allowed($action, $object_id) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Return a true value if the current user is allowed to do C<$action> on |
55
|
|
|
|
|
|
|
object C<$object_id>. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Currently are these actions defined: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over 4 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item release |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The user is allowed to release a document ("freigeben"). |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item publish |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
The user is allowed to publish a site. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item change-folder |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The user is allowed to do folder manipulation, that is, he is allowed |
72
|
|
|
|
|
|
|
to add or delete folders. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item change-doc |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The user is allowed to do document manipulation, that is, he is |
77
|
|
|
|
|
|
|
allowed to add, edit or delete documents. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
If there is no current user, then always a false value is returned. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub is_allowed { |
86
|
0
|
|
|
0
|
|
|
my($self, $action, $obj_id) = @_; |
87
|
0
|
|
|
|
|
|
my $user = $self->CurrentUser; |
88
|
0
|
0
|
|
|
|
|
return 0 if !$user; |
89
|
0
|
0
|
|
|
|
|
if ($action =~ /^(release|publish|change-folder)$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
90
|
0
|
|
0
|
|
|
|
return $self->UserDB->is_in_group($user,"chiefeditors") || |
91
|
|
|
|
|
|
|
$self->UserDB->is_in_group($user,"admins"); |
92
|
|
|
|
|
|
|
} elsif ($action eq 'change-doc') { |
93
|
0
|
|
0
|
|
|
|
return $self->UserDB->is_in_group($user,"editors") || |
94
|
|
|
|
|
|
|
$self->UserDB->is_in_group($user,"chiefeditors") || |
95
|
|
|
|
|
|
|
$self->UserDB->is_in_group($user,"admins"); |
96
|
|
|
|
|
|
|
} elsif ($action eq 'everything') { |
97
|
0
|
|
|
|
|
|
return $self->UserDB->is_in_group($user,"admins"); |
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
|
|
|
|
|
die "Unknown action $action"; |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item get_released_children($folder_id) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Return all folders and released children as an array of objects. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_released_children { |
111
|
0
|
|
|
0
|
|
|
my($self, $folder_id) = @_; |
112
|
0
|
|
|
|
|
|
my @children = $self->ObjDB->children($folder_id); |
113
|
0
|
|
|
|
|
|
my @res; |
114
|
0
|
|
|
|
|
|
for my $o (@children) { |
115
|
0
|
0
|
|
|
|
|
if ($o->is_folder) { |
116
|
0
|
|
|
|
|
|
push @res, $o; |
117
|
|
|
|
|
|
|
} else { |
118
|
0
|
|
|
|
|
|
my $r = $self->get_released_object($o->Id); |
119
|
0
|
0
|
|
|
|
|
push @res, $r if defined $r; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
@res; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item get_released_object($object_id) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Return the last released version for C<$object_id>. If there is no |
128
|
|
|
|
|
|
|
released version yet, return C. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub get_released_object { |
133
|
0
|
|
|
0
|
|
|
my($self, $obj_id) = @_; |
134
|
0
|
|
|
|
|
|
my $obj = $self->ObjDB->get_object($obj_id); |
135
|
0
|
0
|
|
|
|
|
die "Can't get object with id $obj_id" if !$obj; |
136
|
0
|
|
|
|
|
|
foreach my $v_id (reverse $self->ObjDB->version_ids($obj_id)) { |
137
|
0
|
|
|
|
|
|
my $v = $self->ObjDB->get_object($v_id); |
138
|
0
|
0
|
|
|
|
|
if ($v->Release_State eq 'released') { |
139
|
0
|
|
|
|
|
|
return $v; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
|
undef; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |