| 1 | #!/bin/false | ||
| 2 | # PODNAME: BZ::Client::User | ||
| 3 | # ABSTRACT: Creates and edits user accounts in Bugzilla | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings 'all'; | ||
| 7 | |||
| 8 | package BZ::Client::User; | ||
| 9 | $BZ::Client::User::VERSION = '4.91'; | ||
| 10 | |||
| 11 | use parent qw( BZ::Client::API ); | ||
| 12 | |||
| 13 | # See https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/User.html | ||
| 14 | |||
| 15 | ## functions | ||
| 16 | |||
| 17 | sub offer_account_by_email { | ||
| 18 | my($class, $client, $params) = @_; | ||
| 19 | unless (ref $params) { | ||
| 20 | $params = { email => $params } | ||
| 21 | } | ||
| 22 | $client->log('debug', $class . '::offer_account_by_email: Inviting'); | ||
| 23 | return $class->api_call($client, 'User.offer_account_by_email', $params, { empty_response_ok => 1}); | ||
| 24 | } | ||
| 25 | |||
| 26 | sub get { | ||
| 27 | my($class, $client, $params) = @_; | ||
| 28 | $client->log('debug', $class . '::get: Asking.'); | ||
| 29 | if ($params->{'include_disabled'}) { | ||
| 30 | $params->{'include_disabled'} = BZ::Client::XMLRPC::boolean::TRUE() | ||
| 31 | } | ||
| 32 | else { | ||
| 33 | $params->{'include_disabled'} = BZ::Client::XMLRPC::boolean::FALSE() | ||
| 34 | } | ||
| 35 | my $users = $class->_returns_array($client, 'User.get', $params, 'users'); | ||
| 36 | my @result; | ||
| 37 | for my $user (@$users) { | ||
| 38 | push(@result, $class->new(%{$user})); | ||
| 39 | } | ||
| 40 | $client->log('debug', $class . '::get: Got ' . scalar(@result)); | ||
| 41 | return wantarray ? @result : \@result | ||
| 42 | } | ||
| 43 | |||
| 44 | ## methods | ||
| 45 | |||
| 46 | sub create { | ||
| 47 | my($class, $client, $params) = @_; | ||
| 48 | return $class->_create($client, 'User.create', $params); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub update { | ||
| 52 | my($class, $client, $params) = @_; | ||
| 53 | $client->log('debug', $class . '::update: Updating.'); | ||
| 54 | if (defined $params->{'email_enabled'}) { | ||
| 55 | if ($params->{'email_enabled'}) { | ||
| 56 | $params->{'email_enabled'} = BZ::Client::XMLRPC::boolean::TRUE() | ||
| 57 | } | ||
| 58 | else { | ||
| 59 | $params->{'email_enabled'} = BZ::Client::XMLRPC::boolean::FALSE() | ||
| 60 | } | ||
| 61 | } | ||
| 62 | my $users = $class->_returns_array($client, 'User.update', $params, 'users'); | ||
| 63 | my @result; | ||
| 64 | for my $user (@$users) { | ||
| 65 | push(@result, $class->new(%{$user})); | ||
| 66 | } | ||
| 67 | $client->log('debug', $class . '::update: Got ' . scalar(@result)); | ||
| 68 | return wantarray ? @result : \@result | ||
| 69 | } | ||
| 70 | |||
| 71 | # Internal helper for accessors | ||
| 72 | sub _accessor { | ||
| 73 | my ($self, $field, $val) = @_; | ||
| 74 | if (@_ > 2) { | ||
| 75 | $self->{$field} = $val; | ||
| 76 | } else { | ||
| 77 | return $self->{$field}; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | # Accessors for common user fields | ||
| 82 | sub id { | ||
| 83 | my $self = shift; | ||
| 84 | return $self->_accessor('id', @_ ? $_[0] : ()); | ||
| 85 | } | ||
| 86 | |||
| 87 | sub name { | ||
| 88 | my $self = shift; | ||
| 89 | return $self->_accessor('name', @_ ? $_[0] : ()); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub email { | ||
| 93 | my $self = shift; | ||
| 94 | return $self->_accessor('email', @_ ? $_[0] : ()); | ||
| 95 | } | ||
| 96 | |||
| 97 | sub real_name { | ||
| 98 | my $self = shift; | ||
| 99 | return $self->_accessor('real_name', @_ ? $_[0] : ()); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub login { | ||
| 103 | my $self = shift; | ||
| 104 | return $self->_accessor('login', @_ ? $_[0] : ()); | ||
| 105 | } | ||
| 106 | |||
| 107 | sub can_login { | ||
| 108 | my $self = shift; | ||
| 109 | return $self->_accessor('can_login', @_ ? $_[0] : ()); | ||
| 110 | } | ||
| 111 | |||
| 112 | sub email_enabled { | ||
| 113 | my $self = shift; | ||
| 114 | return $self->_accessor('email_enabled', @_ ? $_[0] : ()); | ||
| 115 | } | ||
| 116 | |||
| 117 | sub groups { | ||
| 118 | my $self = shift; | ||
| 119 | return $self->_accessor('groups', @_ ? $_[0] : ()); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub saved_searches { | ||
| 123 | my $self = shift; | ||
| 124 | return $self->_accessor('saved_searches', @_ ? $_[0] : ()); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub last_visit { | ||
| 128 | my $self = shift; | ||
| 129 | return $self->_accessor('last_visit', @_ ? $_[0] : ()); | ||
| 130 | } | ||
| 131 | |||
| 132 | 1; | ||
| 133 | |||
| 134 | __END__ |