Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Weblate
2026-03-15 11:59:37 +00:00
2 changed files with 31 additions and 29 deletions

View File

@@ -748,13 +748,13 @@ class API extends CI_Controller {
die();
}
$api_user_id = $this->api_model->key_userid($obj['key']);
if(!isset($obj['logbook_public_slug'])) {
if(!isset($obj['logbook_id'])) {
http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => "missing fields"]);
return;
}
if($obj['logbook_public_slug'] != "") {
$logbook_slug = $obj['logbook_public_slug'];
if($obj['logbook_id'] != "") {
$logbook_id = $obj['logbook_id'];
if(isset($obj['band'])) {
$band = $obj['band'];
} else {
@@ -766,38 +766,23 @@ class API extends CI_Controller {
$cnfm = null;
}
$this->load->model('logbooks_model');
if(!$this->logbooks_model->public_slug_belongs_to_user($logbook_slug, $api_user_id)) {
if(!$this->logbooks_model->logbook_id_belongs_to_user($logbook_id, $api_user_id)) {
http_response_code(403);
echo json_encode(['status' => 'failed', 'reason' => "logbook does not belong to this api key"]);
echo json_encode(['status' => 'failed', 'reason' => "logbook does not belong to this API key or logbook ID not found"]);
die();
}
if($this->logbooks_model->public_slug_exists($logbook_slug)) {
$logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($logbook_slug);
if($logbook_id != false)
{
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id);
if (!$logbooks_locations_array) {
http_response_code(404);
echo json_encode(['status' => 'failed', 'reason' => "Empty Logbook"]);
die();
}
} else {
if ($this->logbooks_model->exists_logbook_id($logbook_id) != false) {
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id);
if ($logbooks_locations_array[0] == -1) {
http_response_code(404);
echo json_encode(['status' => 'failed', 'reason' => $logbook_slug." has no associated station locations"]);
echo json_encode(['status' => 'failed', 'reason' => "logbook with ID ".$logbook_id." has no associated station locations"]);
die();
} else {
$arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm);
http_response_code(201);
echo json_encode($arr);
}
$this->load->model('logbook_model');
$arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm);
http_response_code(201);
echo json_encode($arr);
} else {
http_response_code(404);
echo json_encode(['status' => 'failed', 'reason' => "logbook not found"]);
die();
}
}
}

View File

@@ -178,7 +178,6 @@ class Logbooks_model extends CI_Model {
function public_slug_exists_logbook_id($slug) {
$this->db->where('public_slug', $this->security->xss_clean($slug));
$query = $this->db->get('station_logbooks');
if ($query->num_rows() > 0){
foreach ($query->result() as $row) {
return $row->logbook_id;
@@ -188,6 +187,17 @@ class Logbooks_model extends CI_Model {
}
}
function exists_logbook_id($logbook_id) {
$this->db->where('logbook_id', $this->security->xss_clean($logbook_id));
$query = $this->db->get('station_logbooks');
if ($query->num_rows() > 0){
return true;
} else {
return false;
}
}
function public_slug_belongs_to_user($slug, $user_id) {
$this->db->where('public_slug', $this->security->xss_clean($slug));
$this->db->where('user_id', $user_id);
@@ -195,6 +205,13 @@ class Logbooks_model extends CI_Model {
return $query->num_rows() > 0;
}
function logbook_id_belongs_to_user($logbook_id, $user_id) {
$this->db->where('logbook_id', $this->security->xss_clean($logbook_id));
$this->db->where('user_id', $user_id);
$query = $this->db->get('station_logbooks');
return $query->num_rows() > 0;
}
function is_public_slug_available($slug) {
// Clean public_slug
$clean_slug = $this->security->xss_clean($slug);