users, roles, groups
- The database contains three tables: user, role, and group.
- These tables form a chain:
- A user (parent table) can have one or more roles (child table).
- Each role points to the user and to a specific group (the role table has multiple foreign keys)
- Each group defines an access_code that represents a permission scope.
- When User A logs in:
- The system looks up all roles assigned to User A.
- User A has roles in three groups: Group B, Group C, and Group D.
- Each of these groups provides its own access_code:
- Group B → code B
- Group C → code C
- Group D → code D
- The login process collects these access codes.
- The three codes are stored as items in the session array:
- `$_SESSION['xs'] = [A, B, C]`
- Conceptually:
- A user inherits permissions from all groups linked by role.
- The session becomes the active permission set for that user.
- The system only needs the codes in `xs` to determine what the user can access.
make relationships
ALTER TABLE role
ADD CONSTRAINT fk_role_user
FOREIGN KEY (user_id)
REFERENCES user(id)
ON DELETE CASCADE
ON UPDATE CASCADE;