die $exc;
}
-sub filter_entities_by_privs {
- my ($rpcenv, $entities) = @_;
- my $authuser = $rpcenv->get_user();
-
- my $can_see_mapping_privs = ['Mapping.Modify', 'Mapping.Use', 'Mapping.Audit'];
-
- my $filtered = [grep {
- $rpcenv->check_any(
- $authuser,
- "/mapping/notification/$_->{name}",
- $can_see_mapping_privs,
- 1
- );
- } @$entities];
-
- return $filtered;
-}
-
__PACKAGE__->register_method ({
name => 'index',
path => '',
method => 'GET',
description => 'Returns a list of all entities that can be used as notification targets.',
permissions => {
- description => "Only lists entries where you have 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/<name>'."
- . " The special 'mail-to-root' target is available to all users.",
- user => 'all',
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Use']],
+ ],
},
protected => 1,
parameters => {
},
code => sub {
my $config = PVE::Notify::read_config();
- my $rpcenv = PVE::RPCEnvironment::get();
my $targets = eval {
my $result = [];
raise_api_error($@) if $@;
- return filter_entities_by_privs($rpcenv, $targets);
+ return $targets;
}
});
method => 'POST',
description => 'Send a test notification to a provided target.',
permissions => {
- description => "The user requires 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/<name>'."
- . " The special 'mail-to-root' target can be accessed by all users.",
- user => 'all',
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Use']],
+ ],
},
parameters => {
additionalProperties => 0,
code => sub {
my ($param) = @_;
my $name = extract_param($param, 'name');
- my $rpcenv = PVE::RPCEnvironment::get();
- my $authuser = $rpcenv->get_user();
-
- my $privs = ['Mapping.Modify', 'Mapping.Use', 'Mapping.Audit'];
-
- $rpcenv->check_any(
- $authuser,
- "/mapping/notification/$name",
- $privs,
- );
eval {
my $config = PVE::Notify::read_config();
method => 'GET',
description => 'Returns a list of all sendmail endpoints',
permissions => {
- description => "Only lists entries where you have 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/<name>'.",
- user => 'all',
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
+ ],
},
protected => 1,
parameters => {
},
code => sub {
my $config = PVE::Notify::read_config();
- my $rpcenv = PVE::RPCEnvironment::get();
my $entities = eval {
$config->get_sendmail_endpoints();
};
raise_api_error($@) if $@;
- return filter_entities_by_privs($rpcenv, $entities);
+ return $entities;
}
});
description => 'Return a specific sendmail endpoint',
permissions => {
check => ['or',
- ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
- ['perm', '/mapping/notification/{name}', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
],
},
protected => 1,
method => 'POST',
description => 'Create a new sendmail endpoint',
permissions => {
- check => ['perm', '/mapping/notification', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'PUT',
description => 'Update existing sendmail endpoint',
permissions => {
- check => ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'DELETE',
description => 'Remove sendmail endpoint',
permissions => {
- check => ['perm', '/mapping/notification', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
description => 'Returns a list of all gotify endpoints',
protected => 1,
permissions => {
- description => "Only lists entries where you have 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/<name>'.",
- user => 'all',
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Audit']],
},
parameters => {
additionalProperties => 0,
};
raise_api_error($@) if $@;
- return filter_entities_by_privs($rpcenv, $entities);
+ return $entities;
}
});
protected => 1,
permissions => {
check => ['or',
- ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
- ['perm', '/mapping/notification/{name}', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
],
},
parameters => {
method => 'POST',
description => 'Create a new gotify endpoint',
permissions => {
- check => ['perm', '/mapping/notification', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'PUT',
description => 'Update existing gotify endpoint',
permissions => {
- check => ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'DELETE',
description => 'Remove gotify endpoint',
permissions => {
- check => ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'GET',
description => 'Returns a list of all smtp endpoints',
permissions => {
- description => "Only lists entries where you have 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/targets/<name>'.",
- user => 'all',
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
+ ],
},
protected => 1,
parameters => {
},
code => sub {
my $config = PVE::Notify::read_config();
- my $rpcenv = PVE::RPCEnvironment::get();
my $entities = eval {
$config->get_smtp_endpoints();
};
raise_api_error($@) if $@;
- return filter_entities_by_privs($rpcenv, "targets", $entities);
+ return $entities;
}
});
description => 'Return a specific smtp endpoint',
permissions => {
check => ['or',
- ['perm', '/mapping/notification/targets/{name}', ['Mapping.Modify']],
- ['perm', '/mapping/notification/targets/{name}', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
],
},
protected => 1,
method => 'POST',
description => 'Create a new smtp endpoint',
permissions => {
- check => ['perm', '/mapping/notification/targets', ['Mapping.Modify']],
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ],
},
parameters => {
additionalProperties => 0,
method => 'PUT',
description => 'Update existing smtp endpoint',
permissions => {
- check => ['perm', '/mapping/notification/targets/{name}', ['Mapping.Modify']],
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ],
},
parameters => {
additionalProperties => 0,
method => 'DELETE',
description => 'Remove smtp endpoint',
permissions => {
- check => ['perm', '/mapping/notification/targets/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
description => 'Returns a list of all matchers',
protected => 1,
permissions => {
- description => "Only lists entries where you have 'Mapping.Modify', 'Mapping.Use' or"
- . " 'Mapping.Audit' permissions on '/mapping/notification/<name>'.",
- user => 'all',
+ check => ['or',
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Use']],
+ ],
},
parameters => {
additionalProperties => 0,
},
code => sub {
my $config = PVE::Notify::read_config();
- my $rpcenv = PVE::RPCEnvironment::get();
my $entities = eval {
$config->get_matchers();
};
raise_api_error($@) if $@;
- return filter_entities_by_privs($rpcenv, $entities);
+ return $entities;
}
});
protected => 1,
permissions => {
check => ['or',
- ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
- ['perm', '/mapping/notification/{name}', ['Mapping.Audit']],
+ ['perm', '/mapping/notifications', ['Mapping.Modify']],
+ ['perm', '/mapping/notifications', ['Mapping.Audit']],
],
},
parameters => {
description => 'Create a new matcher',
protected => 1,
permissions => {
- check => ['perm', '/mapping/notification', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'PUT',
description => 'Update existing matcher',
permissions => {
- check => ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
method => 'DELETE',
description => 'Remove matcher',
permissions => {
- check => ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+ check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,