| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Cmd::User; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
|
3
|
|
|
|
|
|
|
$Tapper::Cmd::User::VERSION = '5.0.11'; |
|
4
|
1
|
|
|
1
|
|
5490389
|
use Moose; |
|
|
1
|
|
|
|
|
510265
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
8183
|
use Tapper::Model 'model'; |
|
|
1
|
|
|
|
|
4262
|
|
|
|
1
|
|
|
|
|
65
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use YAML::Syck; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
56
|
|
|
8
|
1
|
|
|
1
|
|
18
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use parent 'Tapper::Cmd'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
1
|
|
|
1
|
1
|
19182
|
my ($self, $data) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
4
|
my $contacts = $data->{contacts}; |
|
19
|
1
|
|
|
|
|
17
|
delete $data->{contacts}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
33
|
|
|
6
|
$data->{login} ||= $ENV{USER}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
4
|
if (not $data->{name}) { |
|
24
|
|
|
|
|
|
|
# Try to guess the real name. Since UNIX has no idea of a real name, this is extremly error prone. |
|
25
|
0
|
|
|
|
|
0
|
my @userdata = getpwnam($data->{login}); |
|
26
|
0
|
|
|
|
|
0
|
$data->{name} = $userdata[6]; |
|
27
|
0
|
|
|
|
|
0
|
$data->{name} =~ s/,//g; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
6
|
my $owner = model('TestrunDB')->resultset('Owner')->new($data); |
|
32
|
1
|
|
|
|
|
584
|
$owner->insert; |
|
33
|
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
21611
|
foreach my $contact (@{$contacts || []}) { |
|
|
1
|
|
|
|
|
7
|
|
|
35
|
1
|
|
|
|
|
46
|
$contact->{owner_id} = $owner->id; |
|
36
|
1
|
|
|
|
|
53
|
my $contact_result = model('TestrunDB')->resultset('Contact')->new($contact); |
|
37
|
1
|
|
|
|
|
560
|
$contact_result->insert; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
14870
|
return $owner->id; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub list |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
3
|
|
|
3
|
1
|
644
|
my ($self, $search) = @_; |
|
47
|
3
|
|
|
|
|
7
|
my @users; |
|
48
|
3
|
|
|
|
|
14
|
my $owner_rs = model('TestrunDB')->resultset('Owner')->search($search); |
|
49
|
3
|
|
|
|
|
1656
|
while (my $owner_result = $owner_rs->next) { |
|
50
|
8
|
|
|
|
|
12370
|
my $user = { id => $owner_result->id, name => $owner_result->name, login => $owner_result->login }; |
|
51
|
8
|
|
|
|
|
647
|
$user->{contacts} = [ map { { address => $_->address, protocol => $_->protocol } } $owner_result->contacts->all ]; |
|
|
6
|
|
|
|
|
18967
|
|
|
52
|
8
|
|
|
|
|
10136
|
push @users, $user; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
3
|
|
|
|
|
455
|
return @users; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub del |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
1
|
|
|
1
|
1
|
2382
|
my ($self, $id) = @_; |
|
63
|
1
|
|
|
|
|
2
|
my $owner; |
|
64
|
1
|
50
|
|
|
|
9
|
if ($id =~ /^\d+$/) { |
|
65
|
1
|
|
|
|
|
6
|
$owner = model('TestrunDB')->resultset('Owner')->find($id); |
|
66
|
|
|
|
|
|
|
} else { |
|
67
|
0
|
|
|
|
|
0
|
$owner = model('TestrunDB')->resultset('Owner')->find({login => $id}); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
1
|
50
|
|
|
|
3049
|
die qq(User "$id" not found) if not $owner;; |
|
70
|
1
|
|
|
|
|
34
|
$owner->delete(); |
|
71
|
1
|
|
|
|
|
25242
|
return 0; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub contact_add |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
1
|
|
|
1
|
1
|
2403
|
my ($self, $user, $data) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
|
33
|
|
|
5
|
$user //= $ENV{USER}; |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
50
|
|
|
|
9
|
if ( $user !~ m/^\d+$/ ) { |
|
82
|
1
|
|
|
|
|
6
|
my $owner_result = model('TestrunDB')->resultset('Owner')->find({login => $user}); |
|
83
|
1
|
50
|
|
|
|
5228
|
die "User $user does not exist in database\n" if not $owner_result; |
|
84
|
1
|
|
|
|
|
54
|
$user = $owner_result->id; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
1
|
|
33
|
|
|
47
|
$data->{owner_id} ||= $user; |
|
87
|
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
6
|
my $contact = model('TestrunDB')->resultset('Contact')->new($data); |
|
89
|
1
|
|
|
|
|
540
|
$contact->insert; |
|
90
|
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
16201
|
return $contact->id; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; # End of Tapper::Cmd::Testrun |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding UTF-8 |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Tapper::Cmd::User |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This project offers backend functions for all projects that manipulate |
|
110
|
|
|
|
|
|
|
users in the database. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
use Tapper::Cmd::User; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $user = Tapper::Cmd::User->new(); |
|
115
|
|
|
|
|
|
|
my $details = {login => "anton", |
|
116
|
|
|
|
|
|
|
name => 'Anton Gorodetzky', |
|
117
|
|
|
|
|
|
|
contacts => [{ |
|
118
|
|
|
|
|
|
|
protocol => 'Mail', |
|
119
|
|
|
|
|
|
|
address => 'anton@nightwatch.ru', |
|
120
|
|
|
|
|
|
|
}] |
|
121
|
|
|
|
|
|
|
}; |
|
122
|
|
|
|
|
|
|
my $id = $user->add($details); |
|
123
|
|
|
|
|
|
|
$details->{name} = "Anton Gorodetsky"; |
|
124
|
|
|
|
|
|
|
my $error = $user->update($id, $details); |
|
125
|
|
|
|
|
|
|
$error = $user->delete($id); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$details = {login => "anton", name => 'Anton Gorodetzky'}; |
|
128
|
|
|
|
|
|
|
$id = $user->add_in_testrun($details); |
|
129
|
|
|
|
|
|
|
$details->{name} = "Anton Gorodetsky"; |
|
130
|
|
|
|
|
|
|
my $error = $user->update_in_testrun($id, $details); |
|
131
|
|
|
|
|
|
|
$error = $user->delete_in_testrun($id); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Tapper::Cmd::User - Backend functions for manipluation of user subscriptions in the database |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 add |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Add a new user to testrundb. Expects all details as a hash reference. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
@param hash ref - user data |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
@return success - user id |
|
146
|
|
|
|
|
|
|
@return error - undef |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
@throws Perl die |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 list |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Get a list of users with all information we have about them. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
@param hash ref - search as understand by DBIx::Class |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
@return list of user information (hash refs) |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
@throws die |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 del |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Delete a user subscription with given id. Its named del instead of |
|
163
|
|
|
|
|
|
|
delete to prevent confusion with the buildin delete function. The first |
|
164
|
|
|
|
|
|
|
parameter can be either the users database id (not the UNIX id!) or the |
|
165
|
|
|
|
|
|
|
login name. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
@param int|string - user id|user login name |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
@return success - 0 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
@throws die |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 contact_add |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Add a contact to an existing owner in testrundb. Expects all details as a hash |
|
176
|
|
|
|
|
|
|
reference. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
@param int|string - owner as id or login |
|
179
|
|
|
|
|
|
|
@param hash ref - contact data |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
@return success - owner id |
|
182
|
|
|
|
|
|
|
@return error - undef |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
@throws Perl die |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHOR |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
AMD OSRC Tapper Team, C<< <tapper at amd64.org> >> |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright 2012 AMD OSRC Tapper Team, all rights reserved. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is released under the following license: freebsd |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHORS |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over 4 |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This is free software, licensed under: |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |