Skip to content

Commit

Permalink
Merge pull request #447 from dfpc-coe/video-leases
Browse files Browse the repository at this point in the history
Video Lease Management
  • Loading branch information
ingalls authored Dec 13, 2024
2 parents 5d38a68 + d0104ef commit 292d0f7
Show file tree
Hide file tree
Showing 15 changed files with 3,028 additions and 2,603 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

# Custom
*.p12
*.cert
*.key
*.crt
*.dump
.env-*
.docker-*
api/assets/*

# Logs
Expand Down
50 changes: 35 additions & 15 deletions api/routes/video-lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default async function router(schema: Schema, config: Config) {
group: 'VideoLease',
description: 'List all video leases',
query: Type.Object({
impersonate: Type.Optional(Type.Union([
Type.Boolean({ description: 'List all of the given resource, regardless of ACL' }),
Type.String({ description: 'Filter the given resource by a given username' }),
])),
limit: Default.Limit,
page: Default.Page,
order: Default.Order,
Expand All @@ -32,21 +36,37 @@ export default async function router(schema: Schema, config: Config) {
})
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req);

const list = await config.models.VideoLease.list({
limit: req.query.limit,
page: req.query.page,
order: req.query.order,
sort: req.query.sort,
where: sql`
name ~* ${req.query.filter}
AND username = ${user.email}
AND ephemeral = ${req.query.ephemeral}
`
});

res.json(list);
if (req.query.impersonate) {
await Auth.as_user(config, req, { admin: true });

const impersonate: string | null = req.query.impersonate === true ? null : req.query.impersonate;

res.json(await config.models.VideoLease.list({
limit: req.query.limit,
page: req.query.page,
order: req.query.order,
sort: req.query.sort,
where: sql`
name ~* ${req.query.filter}
AND ephemeral = ${req.query.ephemeral}
AND (${impersonate}::TEXT IS NULL OR username = ${impersonate}::TEXT)
`
}));
} else {
const user = await Auth.as_user(config, req);

res.json(await config.models.VideoLease.list({
limit: req.query.limit,
page: req.query.page,
order: req.query.order,
sort: req.query.sort,
where: sql`
name ~* ${req.query.filter}
AND username = ${user.email}
AND ephemeral = ${req.query.ephemeral}
`
}));
}
} catch (err) {
Err.respond(err, res);
}
Expand Down
Loading

0 comments on commit 292d0f7

Please sign in to comment.