Skip to content

Commit

Permalink
Remove fields for non admin notifiers (arkime#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
awick authored Oct 28, 2019
1 parent 711f1f3 commit 9e45ac7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion tests/api-notifiers.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 31;
use Test::More tests => 33;
use Cwd;
use URI::Escape;
use MolochTest;
Expand Down Expand Up @@ -86,6 +86,11 @@ my $notAdminToken = getTokenCookie('notadmin');
ok(exists $notifiers->{test1a}, "notifier update");
is($notifiers->{test1a}->{fields}[0]->{slackWebhookUrl}->{value}, "test1aurl", "notifier field value update");

# non admin no fields
$notifiers = viewerGetToken("/notifiers?molochRegressionUser=notadmin", $notAdminToken);
ok(exists $notifiers->{test1a}, "notifier update");
ok(!exists $notifiers->{test1a}->{fields}, "fields shouldn't exist for non admin");

# cleanup
$json = viewerDeleteToken("/notifiers/test1a", $token);
ok($json->{success}, "notifier delete success");
Expand Down
28 changes: 23 additions & 5 deletions viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,25 +1290,43 @@ function issueAlert (notifierName, alertMessage, continueProcess) {
}

app.get('/notifierTypes', checkCookieToken, function (req, res) {
if (internals.notifiers) {
return res.send(internals.notifiers);
if (!internals.notifiers) {
buildNotifiers();
}

buildNotifiers();

return res.send(internals.notifiers);
});

// get created notifiers
app.get('/notifiers', checkCookieToken, function (req, res) {
function cloneNotifiers(notifiers) {
var clone = {};

for (var key in notifiers) {
if (notifiers.hasOwnProperty(key)) {
var notifier = notifiers[key];
clone[key] = {
name: notifier.name,
type : notifier.type
};
}
}

return clone;
}

Db.getUser('_moloch_shared', (err, sharedUser) => {
if (!sharedUser || !sharedUser.found) {
return res.send({});
} else {
sharedUser = sharedUser._source;
}

return res.send(sharedUser.notifiers);
if (req.user.createEnabled) {
return res.send(sharedUser.notifiers);
}

return res.send(cloneNotifiers(sharedUser.notifiers));
});
});

Expand Down

0 comments on commit 9e45ac7

Please sign in to comment.