Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
ACL Query
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / General Chat

2022-08-13 14:23:59
looking to move user and group settings from those tables to a new permissions table.
Trying to do this a simple as possible, ill probably put in a little class

the idea is to have role_id in user table & group_role_id in group table

these have default permissions from permission table (canviewtorrents, editforum etc)

then i have group_permissions table to link group or user to permission id
we check if user role_id & group group_role_id is not default so users in same group can have different settings

i use single array but should be multi permission,group,user etc but that would mean too many edits lol i was also thinking about adding another table called roles with full access, limited access etc but opted to just add name to permission to keep it simple but making that start to start moving user settings
i had it has one join query but that limited scope a little bit

Any thoughts on improvements

ALTER TABLE groups
ADD `group_role_id` int(10) NOT NULL DEFAULT 1;

ALTER TABLE users
ADD `role_id` int(10) NOT NULL DEFAULT 1;

CREATE TABLE IF NOT EXISTS `group_permissions` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `permission_id` int(10) NOT NULL DEFAULT 0,
 `role_id` int(10) NOT NULL DEFAULT 0,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;

INSERT INTO `group_permissions` (`id`, `permission_id`, `role_id`) VALUES
(1,0,1);

CREATE TABLE IF NOT EXISTS `permissions` (
 `permission_id` int(10) NOT NULL AUTO_INCREMENT,
 `permission_name` varchar(40) NOT NULL DEFAULT 'no name',
 `view_torrents` enum('yes','no') NOT NULL DEFAULT 'yes',
 `edit_torrents` enum('yes','no') NOT NULL DEFAULT 'no',
 `delete_torrents` enum('yes','no') NOT NULL DEFAULT 'no',
 `view_users` enum('yes','no') NOT NULL DEFAULT 'yes',
 `edit_users` enum('yes','no') NOT NULL DEFAULT 'no',
 `delete_users` enum('yes','no') NOT NULL DEFAULT 'no',
 `view_news` enum('yes','no') NOT NULL DEFAULT 'yes',
 `edit_news` enum('yes','no') NOT NULL DEFAULT 'no',
 `delete_news` enum('yes','no') NOT NULL DEFAULT 'no',
 `can_upload` enum('yes','no') NOT NULL DEFAULT 'no',
 `can_download` enum('yes','no') NOT NULL DEFAULT 'yes',
 `view_forum` enum('yes','no') NOT NULL DEFAULT 'yes',
 `edit_forum` enum('yes','no') NOT NULL DEFAULT 'yes',
 `delete_forum` enum('yes','no') NOT NULL DEFAULT 'no',
 PRIMARY KEY (`permission_id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;

INSERT INTO `permissions` (`permission_id`, `permission_name`, `view_torrents`, `edit_torrents`, `delete_torrents`, `view_users`, `edit_users`, `delete_users`, `view_news`, `edit_news`, `delete_news`, `can_upload`, `can_download`, `view_forum`, `edit_forum`, `delete_forum`) VALUES
('0','default','yes', 'no','no','yes','no','no','yes','no','no','yes','yes','yes','no','yes'),
(1,'staff', 'yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes');


then the query stuff
          // Lets Build Permission Array
         $data = array();

         // Get User & Group
         $user = DB::run(
           "SELECT * FROM `users`
           LEFT OUTER JOIN `groups`
           ON users.class=groups.group_id
           WHERE id = $_COOKIE[id]
           AND users.enabled='yes'
           AND users.status ='confirmed'"
         )->fetch();
         foreach ($user as $key => $value) {
           $data[$key] = $value;
         }
         echo '<pre>'.print_r($user, true).'</pre>';

         // User Role Or Group Role
         $user_or_group_role = $user['role_id'] != 0 ? $user['role_id'] : $user['group_role_id'];
         echo '<pre>'.print_r($user_or_group_role, true).'</pre>';

         // Now Get Role (default id 1 for default group role)
         $role = DB::run(
           "SELECT `permission_id`
            FROM `group_permissions` WHERE `role_id`=?",
            [$user_or_group_role]
         )->fetchColumn();
         echo '<pre>'.print_r($role, true).'</pre>';

         // Now Get Permission
         $permission = DB::run(
           "SELECT *
            FROM `permissions` WHERE `permission_id`=?",
            [$role]
         )->fetch(PDO::FETCH_ASSOC);
         foreach ($permission as $key => $value) {
           $data[$key] = $value;
         }
         echo '<pre>'.print_r($permission, true).'</pre>';

         // Full Single Array (less editing for now but should be multi)
         echo '<pre>'.print_r($data, true).'</pre>';
2022-08-13 15:01:38
There is alot of different ways to go about this, no idea what the best approach would be, but i always felt the permission system in TT was too weak, i can remember when people would use things such as:


if (get_user_class() >= 3) {
}


Which works well until you add a new user class and then all of a sudden the logic won't work as expected because the new group_id is greater than the admins group_id so any static code like this should certainly be a no go.

Like i described in the shoutbox the other day some of the main issues i felt was hard to resolve was say you have a uploader class 4 which donated and you can't display them as a vip/donator because they are assigned to the uploader class and not a vip class.

A very simple approach may be to just have two permission sets:

1.) Group permissions
2.) User permissions

They are both the same permissions that exist in groups with the following conditions:

1.) Group permission sets the default policy.
2.) User permission will override the group policy either way so you could do something like:


if ($myGroup->can_upload === 'no' && $myUser->can_upload === 'no') {
   // Group & User not allowed to upload.
   $allowed = false;
} elseif ($myGroup->can_upload === 'yes' && $myUser->can_upload === 'no') {
  // Group allowed to upload but user not so prevent uploading.
  $allowed = false;
} else {
  // other results should match:
  // group can upload and user can upload
  // group can't upload but user can.
  $allowed = true;
}


What do you think?
2022-08-13 17:32:29
i placed user class in a define so didnt have to change code when adding groups but am leaning towards isAdmin, isUser etc

was thinking about reducing groups
user, mod, admin

these would default permissions
standard access, mod access, admin access

moving uploader, donator to user table wouldnt be much issue then you could display badges on users name like on the colour_user_name mod you could then link to donators table from column instead of group same with vip and uploaders

i like it simple but easy to build on - adding a setting in future would just be adding to permission table with a default
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728