mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 18:27:16 +00:00
* feat[clubstations]: New DB structure
* feat[clubstations]: Add clubstationstable in user managment
* feat[clubstations]: Show last operator
* feat[clubstations]: Better solution for last operator. tnx for the hint @int2001
* feat[clubstations]: New Club Model and Controller
* feat[clubstations]: Add "Add User" and "Edit User" functionality
* docs[clubstations]: move comment
* feat[clubstations]: Add "Delete Member" functionality
* feat[clubstations]: some enhancements and javascript
* fix[clubstations]: Wrong message class for flashmessages
* feat[clubstations]: Added Switch in the Header menu (not functional yet)
* feat[clubstations]: clubswitch modal
* fix[clubstations]: Load encryption library if not already loaded
* fix[clubstations]: Prevent direct login attempts to clubstations and enhance impersonation authorization
* fix[clubstations]: Typo
* feat[clubstations]: Only show the operator dialog if there is something fishy
* fix[user]: little UI bug
* feat[impersonate]: Add source uid to session data
* fix[impersonate]: logic adjustment
* feat[clubstations]: Add manage button in header menu for club officers
* fix[clubstations]: typo in permission level check
* fix[clubstations]: Full rights for the admin
* feat[impersonate]: Custom sessiondata
* feat[impersonate]: Implement stop impersonation feature with modal confirmation; "the way back"
* fix(modal): Fix bug where modal was hidden when mouse leaved the browser content
* docs(config): Adjust config description for special callsigns and clubstations
* feat(club): Add club access check helper
* typo
* fix[impersonation]: Better text
* feat(club): Selectize for a efficient user search
* feat(clubstations): Restrict clubstations based on users permission level part 1/x
* adjustments for dev merge
* Adjusted club right for the advanced logbook
* feat[user]: Refactoring of the Action Buttons in the user table
* fix[club_permissions]: normal button instead small one for club permissions
* remove unnecessary line break in modal body
* feat[clubstations]: Add Club Mode badge to the header
* fix[clubstations]: fix maintenance mode
* allow switch back on http
* feat(simplefle): display operator input based on club_access
* small UI adjustments
* small UI adjustments
* moved api page to a index.php file and added support for clubstations
* removed unused stuff
* typo
* radios and api keys
* missed one binding
* fix qso view, even officers do just see their own radios in QSO logging
* omit the need for a relogin to see the changes as an admin
* Omit the need for relogin after club changes in general. It's a question of UX. It's better to accept a little higher DB load (if clubstations are enabled) then the need of an user to relogin. There is some room for improvement by changing user_model->get_by_id() and adding a join there. This can be done later if we see that the load is too high
* If the user is not the creator of the API key, it's likely a clubstation. In this case the callsign of the clubstation can not be the same as the callsign of the user (operator call provided by the user). If this is the case, we need to use the callsign of the creator of the API key
* remove debug messages
* better UI in header
* found a typo
* full access in clubstations for admins (if accessed via admin usertable)
* adjusted text
* adjusted text
* adjust text
* reduce required chars
* bugfix: missing the correct authentication in case the admin was not member of the club. he wasn't able to switch back
* reduce debug messages
* fixed UI bug related to tooltips
* load js in controller
* upps..
* some UI adjustments
* corrected permissions
* if user gets delete we need to remove data in club_permissions and also api keys which were created by this user
* Notify members about new memberships or changes in permission level
* add spinner to save button
* make login/logout process more bulletproof
* remove the relogin cookie after the attempt
* better strategy
* bug where switch back failed if user is no admin
* make api keys more secure
* mask not owned api keys
* removed annoying link
* if a user gets removed from a club we also should delete the corresponding api keys and cat radios
* adjusted wiki link
* Auto creation of logbook and location when new user is created
* store and display locator in uppercase
* same for callsign
* fixed a bug in user/club creation
* Revert "Auto creation of logbook and location when new user is created"
We found another solution to which will be addressed in a second PR
This reverts commit f05f4b7bf0.
* Optimized SQL for stats at userlist
* Source query for lastop "out", because mysql<9.0 can't handle Windowed functions
* adjust migration
* add new columns to users table to get created_at and modified_at
* added a partial down function
* add operator dropdown for clubstations
* fix mig version
* Add some backend restrictions in case a user wants to try something funny with the club
---------
Co-authored-by: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com>
Co-authored-by: int2001 <joerg@dj7nt.de>
206 lines
5.9 KiB
PHP
206 lines
5.9 KiB
PHP
<?php
|
|
|
|
class Club_model extends CI_Model {
|
|
|
|
/**
|
|
* Authorization for Club Features
|
|
*
|
|
* @param int $level
|
|
* @param int $club_id
|
|
* @param int $user_id (optional)
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function club_authorize($level, $club_id, $user_id = NULL) {
|
|
|
|
if ($level == 0 || !is_numeric($level)) {
|
|
log_message('error', 'Club Authorization Level not set!');
|
|
return false;
|
|
}
|
|
|
|
if ($club_id == 0 || !is_numeric($club_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid Club ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
// admin is always allowed
|
|
$this->load->model('user_model');
|
|
if ($user_id != NULL) {
|
|
if ($this->user_model->get_by_id($user_id)->row()->user_type == 99) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if ($user_id == NULL || !is_numeric($user_id)) {
|
|
$user_id = $this->session->userdata('user_id');
|
|
} else {
|
|
$user_id = xss_clean($user_id);
|
|
}
|
|
|
|
// Now we can check the database for permissions
|
|
$binding = [];
|
|
$sql = 'SELECT * FROM `club_permissions` WHERE user_id = ? AND club_id = ? AND p_level >= ?';
|
|
$binding[] = $user_id;
|
|
$binding[] = $club_id;
|
|
$binding[] = $level;
|
|
|
|
$query = $this->db->query($sql, $binding);
|
|
|
|
if ($query->num_rows() > 0) {
|
|
return true;
|
|
} else {
|
|
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get Permissionlevel for User in Club
|
|
*
|
|
* @param int $club_id
|
|
* @param int $user_id
|
|
*
|
|
* @return int
|
|
*/
|
|
function get_permission($club_id, $user_id) {
|
|
|
|
if ($club_id == 0 || !is_numeric($club_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid Club ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
if ($user_id == 0 || !is_numeric($user_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid User ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
$binding = [];
|
|
$sql = 'SELECT p_level FROM `club_permissions` WHERE user_id = ? AND club_id = ?';
|
|
$binding[] = $user_id;
|
|
$binding[] = $club_id;
|
|
|
|
$query = $this->db->query($sql, $binding);
|
|
|
|
if ($query->num_rows() > 0) {
|
|
return $query->row()->p_level;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get Club Members
|
|
*
|
|
* @param int $club_id
|
|
*
|
|
* @return array
|
|
*/
|
|
function get_club_members($club_id) {
|
|
|
|
$sql = 'SELECT users.user_id, users.user_type, users.user_callsign, users.user_name, users.user_firstname, users.user_lastname, users.user_email, club_permissions.p_level
|
|
FROM club_permissions
|
|
JOIN users ON club_permissions.user_id = users.user_id
|
|
WHERE club_permissions.club_id = ?;';
|
|
|
|
$members = $this->db->query($sql, [$club_id])->result();
|
|
|
|
return $members;
|
|
}
|
|
|
|
/**
|
|
* Get available Clubstations per User
|
|
*
|
|
* @param int $user_id
|
|
*
|
|
* @return array
|
|
*/
|
|
function get_clubstations($user_id) {
|
|
|
|
$sql = 'SELECT users.user_id, users.user_callsign, club_permissions.p_level
|
|
FROM club_permissions
|
|
JOIN users ON club_permissions.club_id = users.user_id
|
|
WHERE club_permissions.user_id = ?;';
|
|
|
|
$clubs = $this->db->query($sql, [$user_id])->result();
|
|
|
|
return $clubs;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Add Club Member
|
|
*
|
|
* @param int $club_id
|
|
* @param int $user_id
|
|
* @param int $p_level
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function alter_member($club_id, $user_id, $p_level) {
|
|
|
|
if ($club_id == 0 || !is_numeric($club_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid Club ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
if ($user_id == 0 || !is_numeric($user_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid User ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
if ($p_level == 0 || !is_numeric($p_level)) {
|
|
$this->session->set_flashdata('error', __("Invalid Permission Level!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
$binding = [];
|
|
$sql = "INSERT INTO club_permissions (club_id, user_id, p_level)
|
|
VALUES (?, ?, ?)
|
|
ON DUPLICATE KEY UPDATE p_level = VALUES(p_level)";
|
|
$binding[] = $club_id;
|
|
$binding[] = $user_id;
|
|
$binding[] = $p_level;
|
|
|
|
if ($this->db->query($sql, $binding)) {
|
|
return true;
|
|
} else {
|
|
$this->session->set_flashdata('error', __("Error adding Club Member!"));
|
|
redirect('club/permissions/' . $club_id);
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Delete Club Member
|
|
*
|
|
* @param int $club_id
|
|
* @param int $user_id
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function delete_member($club_id, $user_id) {
|
|
|
|
if ($club_id == 0 || !is_numeric($club_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid Club ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
if ($user_id == 0 || !is_numeric($user_id)) {
|
|
$this->session->set_flashdata('error', __("Invalid User ID!"));
|
|
redirect('dashboard');
|
|
}
|
|
|
|
try {
|
|
$this->db->query('DELETE FROM club_permissions WHERE club_id = ? AND user_id = ?', [$club_id, $user_id]);
|
|
$this->db->query('DELETE FROM api WHERE user_id = ? AND created_by = ?', [$club_id, $user_id]);
|
|
$this->db->query('DELETE FROM cat WHERE user_id = ? AND operator = ?', [$club_id, $user_id]);
|
|
return true;
|
|
} catch (Exception $e) {
|
|
log_message('error', 'Error deleting Club Member: ' . $e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
}
|