Note that there are some explanatory texts on larger screens.

plurals
  1. POIs There A Better Way Of Doing This? MySQL
    primarykey
    data
    text
    <p>I am in the middle of moving a permission system from PHP to MySQL stored procedures so I can put the site across different devices.</p> <p>My permission system works like this: An action is something a user can do. (Etc Upload Photo) A user can have individual permissions, permissions can be set by roles or just global permissions. A deny permission takes over an allow permission. A permission set for a user will overwrite all other permissions.</p> <p>My Tables Look Like This</p> <p><strong>For Every Action</strong></p> <pre><code>ACL_Actions: ActionID | Default_DOA </code></pre> <p><strong>For Every Role</strong></p> <pre><code>ACL_Roles: RoleID | Name_Of_Role </code></pre> <p><strong>To Set The Permission Of An Action For Users In A Role</strong></p> <pre><code>ACL_Role_Actions: ID | RoleID | ActionID | Role_DOA </code></pre> <p><strong>To Put Users In A Role</strong></p> <pre><code>ACL_Role_Users: ID | RoleID | UserID </code></pre> <p><strong>For Every User</strong></p> <pre><code>ACL_Users: UserID | Details </code></pre> <p><strong>Allows A User Defined Permission For An Action</strong></p> <pre><code>ACL_User_Actions: ID | ActionID | UserID | User_DOA </code></pre> <p>These are just parts of a the tables, and DOA stands for DenyOrAllow.</p> <p>DOA Fields are bits. <code>0 = Deny, 1 = Allow</code></p> <p>Now onto my question. Is this stored procedure the best way I can do this? I am trying to load a users permissions for the actions.</p> <pre><code>BEGIN DECLARE current_doa INT; DECLARE action_id INT; DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT ActionID, User_DOA FROM ACL_User_Actions WHERE UserID = euser_id; DECLARE cur2 CURSOR FOR SELECT ActioNID, Role_DOA FROM ACL_Role_Actions WHERE RoleID IN (SELECT RoleID FROM ACL_Role_Users WHERE UserID = euser_id); DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; DROP TEMPORARY TABLE IF EXISTS user_roles; CREATE TEMPORARY TABLE user_roles SELECT ACL_Actions.ActionID as ActionID, ACL_Actions.Default_DOA as DOA From ACL_Actions; OPEN cur1; read_loop: LOOP FETCH cur1 INTO action_id, current_doa; IF done THEN LEAVE read_loop; END IF; IF current_doa = 0 THEN UPDATE user_roles SET DOA = current_doa WHERE ActionID = action_id; END IF; END LOOP; CLOSE cur1; SET done = 0; OPEN cur2; read_loop: LOOP FETCH cur2 INTO action_id, current_doa; IF done THEN LEAVE read_loop; END IF; UPDATE user_roles SET DOA = current_doa WHERE ActionID = action_id; END LOOP; CLOSE cur2; SELECT * FROM user_roles; END </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload