Skip to content

Commit

Permalink
Hide restore behind developer mode
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Cassidy <[email protected]>
  • Loading branch information
stevecassidy committed Sep 23, 2023
1 parent a78683f commit 0f9005f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
26 changes: 13 additions & 13 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,21 @@ api.post('/users/:id/admin', requireAuthenticationAPI, async (req, res) => {
}
});

api.post(
'/restore',
upload.single('backup'),
requireAuthenticationAPI,
async (req: any, res) => {
if (userIsClusterAdmin(req.user)) {
await restoreFromBackup(req.file.path);
res.json({status: 'success'});
} else {
res.status(401).end();
if (DEVELOPER_MODE) {
api.post(
'/restore',
upload.single('backup'),
requireAuthenticationAPI,
async (req: any, res) => {
if (userIsClusterAdmin(req.user)) {
await restoreFromBackup(req.file.path);
res.json({status: 'success'});
} else {
res.status(401).end();
}
}
}
);
);

if (DEVELOPER_MODE) {
api.post(
'/notebooks/:notebook_id/delete',
requireAuthenticationAPI,
Expand Down
16 changes: 9 additions & 7 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ app.get('/', async (req, res) => {
cluster_admin: userIsClusterAdmin(req.user),
provider: provider,
public_key: signing_key.public_key,
developer: DEVELOPER_MODE,
});
}
} else {
Expand Down Expand Up @@ -295,13 +296,14 @@ app.get('/users', requireClusterAdmin, async (req, res) => {
}
});

app.get('/restore/', requireClusterAdmin, async (req, res) => {
if (req.user) {
res.render('restore');
} else {
res.status(401).end();
}
});
if (DEVELOPER_MODE)
app.get('/restore/', requireClusterAdmin, async (req, res) => {
if (req.user) {
res.render('restore');
} else {
res.status(401).end();
}
});

app.get('/up/', (req, res) => {
res.status(200).json({up: 'true'});
Expand Down
5 changes: 4 additions & 1 deletion views/home.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@
<div class="card-body">
<a href="/users/">User Management</a>
</div>
{{#if developer}}
<div class="card-body">
<a href="/restore/">Restore from backup</a>
</div>
</div>
{{/if}}

</div>
{{/if}}
</div>
Expand Down

0 comments on commit 0f9005f

Please sign in to comment.