Skip to content

Commit

Permalink
Merge pull request #443 from divyank-rs/feat/deleteTicketAdmin
Browse files Browse the repository at this point in the history
[FEAT] added a route for admin to be able to delete sphinx tickets
  • Loading branch information
Evanfeenstra authored Oct 6, 2022
2 parents 8c7c1da + 2e09af3 commit d793673
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/controllers/api/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ export async function deletePersonProfile(req, res) {
}
}

export async function deleteTicketByAdmin(req, res) {
if (!req.owner) return failure(res, 'no owner')

try {
const {
host,
pubkey,
created
} = req.body

const person = await people.deleteTicketByAdmin(
host || config.tribes_host,
pubkey,
created,
req.owner.publicKey
)

success(res, person)
} catch (e) {
failure(res, e)
}
}

export async function uploadPublicPic(req, res) {
if (!req.owner) return failure(res, 'no owner')

Expand Down
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function set(app) {

app.post('/profile', personal.createPeopleProfile)
app.delete('/profile', personal.deletePersonProfile)
app.post('/delete_ticket',personal.deleteTicketByAdmin)
app.post('/public_pic', personal.uploadPublicPic)
app.get('/refresh_jwt', personal.refreshJWT)
app.post('/claim_on_liquid', personal.claimOnLiquid)
Expand Down
18 changes: 18 additions & 0 deletions src/utils/people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ export async function deletePerson(host, id, owner_pubkey) {
}
}

export async function deleteTicketByAdmin(host, pubkey, created,owner_pubkey) {
try {
const token = await genSignedTimestamp(owner_pubkey)
let protocol = 'https'
if (config.tribes_insecure) protocol = 'http'
const r = await fetch(`${protocol}://${host}/ticket/${pubkey}/${created}?token=${token}`, {
method: 'DELETE'
})
if (!r.ok) {
throw 'failed to delete ticket by admin' + r.status
}
}
catch (e) {
sphinxLogger.error(`unauthorized to delete ticket by admin`,logging.Tribes)
throw e
}
}

export async function claimOnLiquid({
host,
asset,
Expand Down

0 comments on commit d793673

Please sign in to comment.