-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogoutTrap.pm
More file actions
178 lines (124 loc) · 3.92 KB
/
Copy pathLogoutTrap.pm
File metadata and controls
178 lines (124 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package MBooks::Operation::LogoutTrap;
=head1 NAME
MBooks::Operation::LogoutTrap (op)
=head1 DESCRIPTION
It is an "early operation" always executed to check if the collection
or action is private and whether there should be a redirect if the
user is logged out.
=head1 SYNOPSIS
See coding example in base class Operation
=head1 METHODS
=over 8
=cut
use strict;
use base qw(Operation);
use Auth::Auth;
use Utils;
use Debug::DUtils;
use MBooks::Operation::Status;
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
$self->_initialize(@_);
return $self;
}
# ---------------------------------------------------------------------
=item _initialize
Initialize MBooks::Operation::Login. Must call parent initialize.
=cut
# ---------------------------------------------------------------------
sub _initialize
{
my $self = shift;
my $attr_ref = shift;
my $C = $$attr_ref{'C'};
my $act = $$attr_ref{'act'};
$self->SUPER::_initialize($C, $act);
}
# ---------------------------------------------------------------------
=item execute_operation
Check to see if user is logged in
if they are, just return
if they are not
check to see if action is listed
if so do a redirect and exit;
Actions covered are in $action2redir_params hashref
Currently these are:listis listsrch listcs
=cut
# ---------------------------------------------------------------------
sub execute_operation
{
my $self = shift;
my $C = shift;
DEBUG('op', qq{execute operation="LogoutTrap"});
# Parameter validation et. al.
$self->SUPER::execute_operation($C);
my $LIST_MY_COLLS_PARAMS = 'a=listcs;colltype=my-collections';
# check for action names and also format of url
my $action2redir_params
= {
'ACTION_LIST_ITEMS' => "$LIST_MY_COLLS_PARAMS",
'ACTION_LIST_SEARCH_RESULTS' => "$LIST_MY_COLLS_PARAMS",
};
my $auth = $C->get_object('Auth');
if ($auth->is_logged_in())
{
return $ST_OK;
}
my $act = $self->get_action();
my $action_name = $act->get_name();
if (! defined($action2redir_params->{$action_name}))
{
return $ST_OK;
}
# Handle actions which operate on a collection that is either public or private
# determine if the collection is private
my $co = $act->get_transient_facade_member_data($C, 'collection_object');
my $cgi = $C->get_object('CGI');
my $coll_id = $cgi->param('c');
silent_ASSERT($coll_id, qq{Missing 'c' parameter in LogoutTrap});
if ($co->get_shared_status($coll_id) =~ m,public|draft,)
{
return $ST_OK;
}
ASSERT($co->get_shared_status($coll_id) eq 'private',
qq{collection $coll_id must be either public or private});
# XXX leave this in for now. We need to deal with difference between
# logging out and not being logged in for temporary users.
# if its a temp collection and owned by user we don't do anything
my $session_user_id = $C->get_object('Session')->get_session_id();
my $user_id = $auth->get_user_name($C);
if (
($session_user_id eq $user_id)
&&
$co->coll_owned_by_user($coll_id, $user_id)
)
{
# collection is owned by not logged in user and is a temp coll
# so do nothing
return $ST_OK;
}
else
{
# its a private collection so redirect
redirect_and_exit($C, $action2redir_params->{$action_name});
}
}
#----------------------------------------------------------------------
sub redirect_and_exit {
my $C = shift;
my $redir_params = shift;
my $cgi = $C->get_object('CGI');
my $temp_cgi = new CGI($redir_params);
$temp_cgi->param('debug', scalar $cgi->param('debug'));
my $redirect_url = $temp_cgi->self_url();
MBooks::View::P_redirect_HTTP($C, $redirect_url);
exit 0;
}
1;
__END__
=head1 AUTHOR
Tom Burton-West, University of Michigan, tburtonw@umich.edu
=cut