mirror of
https://github.com/itflow-org/itflow
synced 2026-09-21 22:21:15 +00:00
Credentials API - Add archive, unarchive and delete endpoints
This commit is contained in:
44
api/v1/credentials/archive.php
Normal file
44
api/v1/credentials/archive.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../validate_api_key.php';
|
||||||
|
require_once '../require_post_method.php';
|
||||||
|
|
||||||
|
// Parse ID
|
||||||
|
$credential_id = intval($_POST['credential_id']);
|
||||||
|
|
||||||
|
// Default
|
||||||
|
$update_count = false;
|
||||||
|
|
||||||
|
if (!empty($credential_id)) {
|
||||||
|
|
||||||
|
// Fetch credential info
|
||||||
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "
|
||||||
|
SELECT credential_name, credential_client_id
|
||||||
|
FROM credentials
|
||||||
|
WHERE credential_id = $credential_id AND credential_client_id = $client_id AND credential_archived_at IS NULL
|
||||||
|
LIMIT 1
|
||||||
|
"));
|
||||||
|
|
||||||
|
if ($row) {
|
||||||
|
|
||||||
|
$credential_name = escapeSql($row['credential_name']);
|
||||||
|
|
||||||
|
// Archive credential
|
||||||
|
$update_sql = mysqli_query($mysqli, "
|
||||||
|
UPDATE credentials SET
|
||||||
|
credential_favorite = 0,
|
||||||
|
credential_archived_at = NOW()
|
||||||
|
WHERE credential_id = $credential_id AND credential_client_id = $client_id
|
||||||
|
");
|
||||||
|
|
||||||
|
if ($update_sql) {
|
||||||
|
$update_count = mysqli_affected_rows($mysqli);
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
logAudit("Credential", "Archive", "$credential_name archived via API ($api_key_name)", $client_id, $credential_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output
|
||||||
|
require_once '../update_output.php';
|
||||||
30
api/v1/credentials/delete.php
Normal file
30
api/v1/credentials/delete.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../validate_api_key.php';
|
||||||
|
|
||||||
|
require_once '../require_post_method.php';
|
||||||
|
|
||||||
|
|
||||||
|
// Parse ID
|
||||||
|
$credential_id = intval($_POST['credential_id']);
|
||||||
|
|
||||||
|
// Default
|
||||||
|
$delete_count = false;
|
||||||
|
|
||||||
|
if (!empty($credential_id)) {
|
||||||
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT credential_name FROM credentials WHERE credential_id = $credential_id AND credential_client_id = $client_id AND credential_archived_at IS NOT NULL LIMIT 1"));
|
||||||
|
$credential_name = escapeSql($row['credential_name'] ?? '');
|
||||||
|
|
||||||
|
$delete_sql = mysqli_query($mysqli, "DELETE FROM credentials WHERE credential_id = $credential_id AND credential_client_id = $client_id AND credential_archived_at IS NOT NULL LIMIT 1");
|
||||||
|
|
||||||
|
// Check delete & get affected rows
|
||||||
|
if ($delete_sql && !empty($credential_name)) {
|
||||||
|
$delete_count = mysqli_affected_rows($mysqli);
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
logAudit("Credential", "Delete", "$credential_name via API ($api_key_name)", $client_id, $credential_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output
|
||||||
|
require_once '../delete_output.php';
|
||||||
42
api/v1/credentials/unarchive.php
Normal file
42
api/v1/credentials/unarchive.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../validate_api_key.php';
|
||||||
|
require_once '../require_post_method.php';
|
||||||
|
|
||||||
|
// Parse ID
|
||||||
|
$credential_id = intval($_POST['credential_id']);
|
||||||
|
|
||||||
|
// Default
|
||||||
|
$update_count = false;
|
||||||
|
|
||||||
|
if (!empty($credential_id)) {
|
||||||
|
|
||||||
|
// Fetch credential info
|
||||||
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "
|
||||||
|
SELECT credential_name, credential_client_id
|
||||||
|
FROM credentials
|
||||||
|
WHERE credential_id = $credential_id AND credential_client_id = $client_id AND credential_archived_at IS NOT NULL
|
||||||
|
LIMIT 1
|
||||||
|
"));
|
||||||
|
|
||||||
|
if ($row) {
|
||||||
|
|
||||||
|
$credential_name = escapeSql($row['credential_name']);
|
||||||
|
|
||||||
|
// Unarchive credential
|
||||||
|
$update_sql = mysqli_query($mysqli, "
|
||||||
|
UPDATE credentials SET credential_archived_at = NULL
|
||||||
|
WHERE credential_id = $credential_id AND credential_client_id = $client_id
|
||||||
|
");
|
||||||
|
|
||||||
|
if ($update_sql) {
|
||||||
|
$update_count = mysqli_affected_rows($mysqli);
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
logAudit("Credential", "Unarchive", "$credential_name unarchived via API ($api_key_name)", $client_id, $credential_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output
|
||||||
|
require_once '../update_output.php';
|
||||||
Reference in New Issue
Block a user