Makes minor fixes to the rights management
parent
d2154fa63c
commit
8da45a06d0
|
@ -70,9 +70,9 @@ class User {
|
||||||
// add user right
|
// add user right
|
||||||
public function addUserRight($user_id, $right_id) {
|
public function addUserRight($user_id, $right_id) {
|
||||||
$sql = 'INSERT INTO users_rights
|
$sql = 'INSERT INTO users_rights
|
||||||
(user_id, right_id, enabled)
|
(user_id, right_id)
|
||||||
VALUES
|
VALUES
|
||||||
(:user_id, :right_id, 1)';
|
(:user_id, :right_id)';
|
||||||
$query = $this->db->prepare($sql);
|
$query = $this->db->prepare($sql);
|
||||||
$query->execute([
|
$query->execute([
|
||||||
':user_id' => $user_id,
|
':user_id' => $user_id,
|
||||||
|
@ -98,8 +98,9 @@ class User {
|
||||||
public function getAllRights() {
|
public function getAllRights() {
|
||||||
$sql = 'SELECT
|
$sql = 'SELECT
|
||||||
id AS right_id,
|
id AS right_id,
|
||||||
item AS right_name
|
name AS right_name
|
||||||
FROM rights';
|
FROM rights
|
||||||
|
ORDER BY id ASC';
|
||||||
$query = $this->db->prepare($sql);
|
$query = $this->db->prepare($sql);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ class User {
|
||||||
u.id AS user_id,
|
u.id AS user_id,
|
||||||
u.username,
|
u.username,
|
||||||
r.id AS right_id,
|
r.id AS right_id,
|
||||||
r.item AS right_name
|
r.name AS right_name
|
||||||
FROM
|
FROM
|
||||||
users u
|
users u
|
||||||
LEFT JOIN users_rights ur
|
LEFT JOIN users_rights ur
|
||||||
|
@ -121,9 +122,7 @@ class User {
|
||||||
LEFT JOIN rights r
|
LEFT JOIN rights r
|
||||||
ON ur.right_id = r.id
|
ON ur.right_id = r.id
|
||||||
WHERE
|
WHERE
|
||||||
u.id = :user_id
|
u.id = :user_id';
|
||||||
AND
|
|
||||||
ur.enabled = 1';
|
|
||||||
|
|
||||||
$query = $this->db->prepare($sql);
|
$query = $this->db->prepare($sql);
|
||||||
$query->execute([
|
$query->execute([
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8 text-start bg-light">
|
<div class="col-md-8 text-start bg-light">
|
||||||
<?php foreach ($allRights as $right) {
|
<?php foreach ($allRights as $right) {
|
||||||
// Check if the current right exists in $userRights and is enabled
|
// Check if the current right exists in $userRights
|
||||||
$isChecked = false;
|
$isChecked = false;
|
||||||
foreach ($userRights as $userRight) {
|
foreach ($userRights as $userRight) {
|
||||||
if ($userRight['right_id'] === $right['right_id']) {
|
if ($userRight['right_id'] === $right['right_id']) {
|
||||||
|
|
|
@ -16,7 +16,6 @@ CREATE TABLE users_meta (
|
||||||
CREATE TABLE users_rights (
|
CREATE TABLE users_rights (
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
right_id INTEGER,
|
right_id INTEGER,
|
||||||
enabled INTEGER NOT NULL CHECK (enabled IN (0, 1)),
|
|
||||||
PRIMARY KEY (user_id, right_id),
|
PRIMARY KEY (user_id, right_id),
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||||
FOREIGN KEY (right_id) REFERENCES rights(id)
|
FOREIGN KEY (right_id) REFERENCES rights(id)
|
||||||
|
|
Loading…
Reference in New Issue