Skip to content

Commit

Permalink
Enhance ticket creation api and UI to support ticket number of usage
Browse files Browse the repository at this point in the history
Ticket uses left was already supported on core but no way to defined it,
neither from UI neither from API

Changed API to accept new optional field  and update UI form to
be able to set it from UI

related #924
  • Loading branch information
kakawait committed Mar 3, 2024
1 parent 24f1b03 commit 0289cdd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion warpgate-admin/src/api/tickets_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum GetTicketsResponse {
struct CreateTicketRequest {
username: String,
target_name: String,
expiry: Option<DateTime<Utc>>
expiry: Option<DateTime<Utc>>,
number_of_usage: Option<i32>
}

#[derive(Object)]
Expand Down Expand Up @@ -87,6 +88,7 @@ impl Api {
target: Set(body.target_name.clone()),
created: Set(chrono::Utc::now()),
expiry: Set(body.expiry),
uses_left: Set(body.number_of_usage),
..Default::default()
};

Expand Down
6 changes: 6 additions & 0 deletions warpgate-web/src/admin/CreateTicket.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let users: User[]|undefined
let selectedTarget: Target|undefined
let selectedUser: User|undefined
let selectedExpiry: string|undefined
let selectedNumberOfUsage: number|undefined
let result: TicketAndSecret|undefined
async function load () {
Expand All @@ -39,6 +40,7 @@ async function create () {
username: selectedUser.username,
targetName: selectedTarget.name,
expiry: selectedExpiry ? new Date(selectedExpiry) : undefined,
numberOfUsage: selectedNumberOfUsage
},
})
} catch (err) {
Expand Down Expand Up @@ -110,6 +112,10 @@ async function create () {
<input type="datetime-local" bind:value={selectedExpiry} class="form-control"/>
</FormGroup>

<FormGroup floating label="Number of usage (optional)">
<input type="number" bind:value={selectedNumberOfUsage} class="form-control"/>
</FormGroup>

<AsyncButton
outline
click={create}
Expand Down
7 changes: 6 additions & 1 deletion warpgate-web/src/admin/Tickets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { link } from 'svelte-spa-router'
import { Alert } from 'sveltestrap'
import RelativeDate from './RelativeDate.svelte'
import Fa from 'svelte-fa'
import { faCalendarXmark, faCalendarCheck } from '@fortawesome/free-solid-svg-icons'
import { faCalendarXmark, faCalendarCheck, faSquareXmark, faSquareCheck } from '@fortawesome/free-solid-svg-icons'
let error: Error|undefined
let tickets: Ticket[]|undefined
Expand Down Expand Up @@ -55,6 +55,11 @@ async function deleteTicket (ticket: Ticket) {
<Fa icon={ticket.expiry > new Date() ? faCalendarCheck : faCalendarXmark} fw /> Until {ticket.expiry?.toLocaleString()}
</small>
{/if}
{#if ticket.usesLeft != null}
<small class="text-muted ms-4">
<Fa icon={ticket.usesLeft > 0 ? faSquareCheck : faSquareXmark} fw /> Uses left {ticket.usesLeft}
</small>
{/if}
<small class="text-muted me-4 ms-auto">
<RelativeDate date={ticket.created} />
</small>
Expand Down
4 changes: 4 additions & 0 deletions warpgate-web/src/admin/lib/openapi-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,10 @@
"expiry": {
"type": "string",
"format": "date-time"
},
"number_of_usage": {
"type": "integer",
"format": "int32"
}
}
},
Expand Down

0 comments on commit 0289cdd

Please sign in to comment.