Skip to content

Commit 082671d

Browse files
committed
Check Clublevel for station-creation
1 parent d22238b commit 082671d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

application/controllers/Api.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,23 @@ function auth($key = '') {
119119

120120
function create_station($key = '') {
121121
$this->load->model('api_model');
122+
122123
if ($this->api_model->access($key) == "No Key Found" || $this->api_model->access($key) == "Key Disabled") {
123124
$this->output->set_status_header(401)->set_content_type('application/json')->set_output(json_encode(['status' => 'error', 'message' => 'Auth Error, invalid key']));
124125
return;
125126
}
127+
128+
$this->load->model('club_model');
129+
$userid = $this->api_model->key_userid($key);
130+
$created_by = $this->api_model->key_created_by($key);
131+
$club_perm = $this->club_model->get_permission_noui($userid,$created_by);
132+
if ($userid != $created_by) { // We're dealing with a Club Member/Member ADIF or Clubofficer
133+
if ((($club_perm ?? 0) == 3) || (($club_perm ?? 0) == 6)) { // Member or ADIF-Member? DENY
134+
$this->output->set_status_header(401)->set_content_type('application/json')->set_output(json_encode(['status' => 'error', 'message' => 'Auth Error, not enough grants for this operation']));
135+
return;
136+
}
137+
}
138+
126139
try {
127140
$raw = file_get_contents("php://input");
128141
if ($raw === false) {
@@ -149,8 +162,7 @@ function create_station($key = '') {
149162
$this->output->set_status_header(500)->set_content_type('application/json')->set_output(json_encode(['status' => 'error', 'message' => 'Processing error: ' . $e->getMessage()]));
150163
}
151164
$this->load->model('stationsetup_model');
152-
$user_id = $this->api_model->key_userid($key);
153-
$imported = $this->stationsetup_model->import_locations_parse($locations,$user_id);
165+
$imported = $this->stationsetup_model->import_locations_parse($locations,$userid);
154166
if (($imported[0] ?? '0') == 'limit') {
155167
$this->output->set_status_header(201)->set_content_type('application/json')->set_output(json_encode(['status' => 'success', 'message' => ($imported[1] ?? '0')." locations imported. Maximum limit of 1000 locations reached."]));
156168
} else {

0 commit comments

Comments
 (0)