-
Notifications
You must be signed in to change notification settings - Fork 11
/
HasUser.pm
121 lines (76 loc) · 2.47 KB
/
HasUser.pm
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
package Workflow::Condition::HasUser;
use warnings;
use strict;
use v5.14.0;
use parent qw( Workflow::Condition );
$Workflow::Condition::HasUser::VERSION = '1.57';
my $DEFAULT_USER_KEY = 'current_user';
sub _init {
my ( $self, $params ) = @_;
my $key_name = $params->{user_key} || $DEFAULT_USER_KEY;
$self->param( user_key => $key_name );
}
sub evaluate {
my ( $self, $wf ) = @_;
$self->log->debug( "Trying to execute condition ", ref $self );
my $user_key = $self->param('user_key');
my $current_user = $wf->context->param($user_key);
$self->log->debug( "Current user in the context is '$current_user' retrieved ",
"using parameter key '$user_key'" );
return Workflow::Condition::IsTrue->new() if($current_user);
return Workflow::Condition::IsFalse->new();
}
1;
__END__
=pod
=head1 NAME
Workflow::Condition::HasUser - Condition to determine if a user is available
=head1 VERSION
This documentation describes version 1.57 of this package
=head1 SYNOPSIS
# First setup the condition
<conditions>
<condition name="HasUser"
class="Workflow::Condition::HasUser">
<param name="user_key" value="CurrentUser" />
</condition>
...
# Next, attach it to an action
<state name="INITIAL">
<action name="create issue"
resulting_state="CREATED">
<condition name="CurrentUser" />
</action>
...
# Whenever you fetch available actions from state 'INITIAL' you must
# have the key 'CurrentUser' defined in the workflow context
=head1 DESCRIPTION
Simple -- possibly too simple -- condition to determine if a user
exists in a particular context key. Actually, it really only
determines if B<something> exists in a key, but we needed a simple
condition to ship with the module.
=head2 Parameters
You can configure the condition with the following parameters:
=over 4
=item *
B<user_key>, optional
Key in workflow context to check for data. If not specified we use
'current_user'.
=back
=head2 METHODS
=head3 evaluate ( $wf )
Method to evaluate whether a user has been set for a workflow.
Takes a workflow object as parameter
Throws L<Workflow::Exception> if evaluation fails
=head1 SEE ALSO
=over
=item * L<Workflow::Condition>
=back
=head1 COPYRIGHT
Copyright (c) 2004-2021 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Please see the F<LICENSE>
=head1 AUTHORS
Please see L<Workflow>
=cut