X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=blobdiff_plain;f=PVE%2FAPI2%2FGroup.pm;h=1d6ba98bf605da4a3004bb9aae850358d1af7bd3;hp=eaee48d5d69882ea000f5ed420ddc97c06610b87;hb=bcf4eb3d4960aa2b3d1e63c482fc35b83bab2c0a;hpb=8de1fb5ae30b7365bee1779fc2db930395b3c164 diff --git a/PVE/API2/Group.pm b/PVE/API2/Group.pm index eaee48d..1d6ba98 100644 --- a/PVE/API2/Group.pm +++ b/PVE/API2/Group.pm @@ -6,16 +6,26 @@ use PVE::Cluster qw (cfs_read_file cfs_write_file); use PVE::AccessControl; use PVE::SafeSyslog; use PVE::RESTHandler; +use PVE::JSONSchema qw(get_standard_option register_standard_option); use base qw(PVE::RESTHandler); +register_standard_option('group-id', { + type => 'string', + format => 'pve-groupid', + title => 'Group ID' , + completion => \&PVE::AccessControl::complete_group, +}); + +register_standard_option('group-comment', { type => 'string', optional => 1 }); + __PACKAGE__->register_method ({ name => 'index', path => '', method => 'GET', description => "Group index.", permissions => { - description => "The returned list is restricted to groups where you have 'User.Allocate' or 'Sys.Audit' permissions on '/access', or 'User.Allocate' on /access/groups/.", + description => "The returned list is restricted to groups where you have 'User.Modify', 'Sys.Audit' or 'Group.Allocate' permissions on /access/groups/.", user => 'all', }, parameters => { @@ -27,7 +37,8 @@ __PACKAGE__->register_method ({ items => { type => "object", properties => { - groupid => { type => 'string' }, + groupid => get_standard_option('group-id'), + comment => get_standard_option('group-comment'), }, }, links => [ { rel => 'child', href => "{groupid}" } ], @@ -41,12 +52,10 @@ __PACKAGE__->register_method ({ my $usercfg = cfs_read_file("user.cfg"); my $authuser = $rpcenv->get_user(); - my $privs = [ 'User.Allocate', 'Sys.Audit' ]; - my $allow = $rpcenv->check_any($authuser, "/access", $privs, 1); - my $allowed_groups = $rpcenv->filter_groups($authuser, $privs, 1); - + my $privs = [ 'User.Modify', 'Sys.Audit', 'Group.Allocate']; + foreach my $group (keys %{$usercfg->{groups}}) { - next if !($allow || $allowed_groups->{$group}); + next if !$rpcenv->check_any($authuser, "/access/groups/$group", $privs, 1); my $data = $usercfg->{groups}->{$group}; my $entry = { groupid => $group }; $entry->{comment} = $data->{comment} if defined($data->{comment}); @@ -62,14 +71,14 @@ __PACKAGE__->register_method ({ path => '', method => 'POST', permissions => { - check => ['perm', '/access', ['Sys.Modify']], + check => ['perm', '/access/groups', ['Group.Allocate']], }, description => "Create new group.", parameters => { additionalProperties => 0, properties => { - groupid => { type => 'string', format => 'pve-groupid' }, - comment => { type => 'string', optional => 1 }, + groupid => get_standard_option('group-id'), + comment => get_standard_option('group-comment'), }, }, returns => { type => 'null' }, @@ -103,14 +112,14 @@ __PACKAGE__->register_method ({ path => '{groupid}', method => 'PUT', permissions => { - check => ['perm', '/access', ['Sys.Modify']], + check => ['perm', '/access/groups', ['Group.Allocate']], }, description => "Update group data.", parameters => { additionalProperties => 0, properties => { - groupid => { type => 'string', format => 'pve-groupid' }, - comment => { type => 'string', optional => 1 }, + groupid => get_standard_option('group-id'), + comment => get_standard_option('group-comment'), }, }, returns => { type => 'null' }, @@ -142,25 +151,23 @@ __PACKAGE__->register_method ({ path => '{groupid}', method => 'GET', permissions => { - check => ['perm', '/access', ['Sys.Audit']], - }, + check => ['perm', '/access/groups', ['Sys.Audit', 'Group.Allocate'], any => 1], + }, description => "Get group configuration.", parameters => { additionalProperties => 0, properties => { - groupid => { type => 'string', format => 'pve-groupid' }, + groupid => get_standard_option('group-id'), }, }, returns => { type => "object", additionalProperties => 0, properties => { - comment => { type => 'string', optional => 1 }, + comment => get_standard_option('group-comment'), members => { type => 'array', - items => { - type => "string", - }, + items => get_standard_option('userid-completed') }, }, }, @@ -191,13 +198,13 @@ __PACKAGE__->register_method ({ path => '{groupid}', method => 'DELETE', permissions => { - check => ['perm', '/access', ['Sys.Modify']], + check => ['perm', '/access/groups', ['Group.Allocate']], }, description => "Delete group.", parameters => { additionalProperties => 0, properties => { - groupid => { type => 'string' , format => 'pve-groupid' }, + groupid => get_standard_option('group-id'), } }, returns => { type => 'null' },