WE_Sample/Root.pm

filter: Statementstmt 38.1% 16 / 42 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 28.0% 23 / 82 CC 14 SCAR 36.1
CC
14
Cov
24%
is_allowed
72.0
get_released_children
20.0
get_released_object
20.0
CRAP 37.0
« WE_Frontend/Plugin/Teaser.pm ↑ Summary WE_Frontend/Plugin/Navigation.pm »
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<WE::DB>. 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 ▶use base qw(WE_Singlesite::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 12 ▶use WE::Obj;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 WE::Obj->use_classes(':all');
42  
43 1 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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 12 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 $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 0 ▶sub is_allowed {
Subroutine is_allowed: not called CC=8 SCAR=42.8
Pod documented
86 0 my($self, $action, $obj_id) = @_;
87 0 my $user = $self->CurrentUser;
88 0 ▶ return 0 if !$user;
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
89 0 ▶ if ($action =~ /^(release|publish|change-folder)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($action =~ /^(release|publish|change-folder)$/) { } 0 0 0
elsif ($action eq 'change-doc') { } 0 0 0
elsif ($action eq 'everything') { } 0 0 0
90 0 ▶ return $self->UserDB->is_in_group($user,"chiefeditors") ||
Condition0%0/3
$self->UserDB->is_in_group($user, 'chiefeditors') || $self->UserDB->is_in_group($user, 'admins')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->UserDB->is_in_group($user, 'chiefeditors') || $self->UserDB->is_in_group($user, 'admins')
$self->UserDB->is_in_group($user, 'chiefeditors') $self->UserDB->is_in_group($user, 'admins')
Truth table0%0/3
A || B
A= $self->UserDB->is_in_group($user, 'chiefeditors')B= $self->UserDB->is_in_group($user, 'admins')
ABresult
1X1
011
000
91 $self->UserDB->is_in_group($user,"admins");
92 } elsif ($action eq 'change-doc') {
93 0 ▶ return $self->UserDB->is_in_group($user,"editors") ||
Condition0%0/6
$self->UserDB->is_in_group($user, 'editors') || $self->UserDB->is_in_group($user, 'chiefeditors') || $self->UserDB->is_in_group($user, 'admins')
l!l&&r!l&&!r
000
$self->UserDB->is_in_group($user, "editors") or $self->UserDB->is_in_group($user, "chiefeditors")
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->UserDB->is_in_group($user, 'editors') || $self->UserDB->is_in_group($user, 'chiefeditors') || $self->UserDB->is_in_group($user, 'admins')
$self->UserDB->is_in_group($user, "editors") $self->UserDB->is_in_group($user, "chiefeditors") $self->UserDB->is_in_group($user, 'admins')
Truth table0%0/4
A or B || C
A= $self->UserDB->is_in_group($user, "editors")B= $self->UserDB->is_in_group($user, "chiefeditors")C= $self->UserDB->is_in_group($user, 'admins')
ABCresult
1XX1
01X1
0011
0000
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 0 ▶sub get_released_children {
Subroutine get_released_children: not called CC=4 SCAR=30.0
Pod documented
111 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 ▶ if ($o->is_folder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->is_folder) { } 0 0 0
116 0 push @res, $o;
117 } else {
118 0 my $r = $self->get_released_object($o->Id);
119 0 ▶ push @res, $r if defined $r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
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<undef>.
129  
130 =cut
131  
132 0 ▶sub get_released_object {
Subroutine get_released_object: not called CC=4 SCAR=30.0
Pod documented
133 0 my($self, $obj_id) = @_;
134 0 my $obj = $self->ObjDB->get_object($obj_id);
135 0 ▶ die "Can't get object with id $obj_id" if !$obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
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 ▶ if ($v->Release_State eq 'released') {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->Release_State eq "released") 0 0 0
139 0 return $v;
140 }
141 }
142 0 undef;
143 }
144  
145 1 1;
146  
147 __END__
« WE_Frontend/Plugin/Teaser.pm ↑ Summary WE_Frontend/Plugin/Navigation.pm »