From 3a4ed5278165bac5af2ed24ce0b149aff6ae88b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 21 Jan 2020 13:54:07 +0100 Subject: [PATCH] API: add group and token info to user index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit otherwise we need 1+N API calls to retrieve the full user+token picture Signed-off-by: Fabian Grünbichler --- PVE/API2/User.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/PVE/API2/User.pm b/PVE/API2/User.pm index 7cde9fd..37bc6c0 100644 --- a/PVE/API2/User.pm +++ b/PVE/API2/User.pm @@ -120,6 +120,12 @@ __PACKAGE__->register_method ({ type => 'boolean', description => "Optional filter for enable property.", optional => 1, + }, + full => { + type => 'boolean', + description => "Include group and token information.", + optional => 1, + default => 0, } }, }, @@ -136,6 +142,14 @@ __PACKAGE__->register_method ({ email => get_standard_option('user-email'), comment => get_standard_option('user-comment'), keys => get_standard_option('user-keys'), + groups => get_standard_option('group-list'), + tokens => { + type => 'array', + optional => 1, + items => $token_info_extend->({ + tokenid => get_standard_option('token-subid'), + }), + } }, }, links => [ { rel => 'child', href => "{userid}" } ], @@ -155,18 +169,21 @@ __PACKAGE__->register_method ({ my $allowed_users = $rpcenv->group_member_join([keys %$groups]); foreach my $user (keys %{$usercfg->{users}}) { - if (!($canUserMod || $user eq $authuser)) { next if !$allowed_users->{$user}; } - my $entry = &$extract_user_data($usercfg->{users}->{$user}); + my $entry = &$extract_user_data($usercfg->{users}->{$user}, $param->{full}); if (defined($param->{enabled})) { next if $entry->{enable} && !$param->{enabled}; next if !$entry->{enable} && $param->{enabled}; } + $entry->{groups} = join(',', @{$entry->{groups}}) if $entry->{groups}; + $entry->{tokens} = [ map { { tokenid => $_, %{$entry->{tokens}->{$_}} } } sort keys %{$entry->{tokens}} ] + if defined($entry->{tokens}); + $entry->{userid} = $user; push @$res, $entry; }