In PrestaShop, the relationship between users, profiles, permissions, and profile_permissions can be understood through their data model and how they interact with each other. Here’s a detailed explanation of each component and their relationships:
1. Users (Employees)
In PrestaShop, users who access the back office are referred to as employees. Each employee is associated with a specific profile.
ps_employee Table
id_employee: Primary key, unique identifier for each employee.id_profile: Foreign key linking to theps_profiletable.- Other fields include
firstname,lastname,email,passwd, etc.
2. Profiles
Profiles define roles with specific sets of permissions. Each profile can be associated with multiple employees.
ps_profile Table
id_profile: Primary key, unique identifier for each profile.name: Name of the profile (e.g., Administrator, Manager, Employee).
3. Permissions (Access)
Permissions are associated with profiles to define what actions can be performed on various back office tabs (sections).
ps_access Table
id_profile: Foreign key linking to theps_profiletable.id_authorization_role: Foreign key linking to theps_authorization_roletable.
ps_authorization_role Table
id_authorization_role: Primary key, unique identifier for each authorization role.slug: A unique identifier for each role and action combination, formatted asROLE_MODULE_CONTROLLER_ACTION.
4. Profile Permissions (Access Management)
This table links profiles with permissions, defining the specific actions (view, add, edit, delete) that a profile can perform on different tabs.
ps_access Table (Permissions Details)
id_profile: Foreign key linking to theps_profiletable.id_authorization_role: Foreign key linking to theps_authorization_roletable.- Each profile’s permission for each action is stored in a separate row.
Data Model Relationships
- One-to-Many Relationship between
ps_profileandps_employee: Each profile can be assigned to many employees, but each employee has only one profile. - Many-to-Many Relationship between
ps_profileandps_authorization_rolethroughps_access: Each profile can have multiple permissions, and each permission can be assigned to multiple profiles.
Example Data Model in SQL
sqlCopy code-- Employees (Users) Table
CREATE TABLE ps_employee (
id_employee INT PRIMARY KEY,
id_profile INT,
firstname VARCHAR(50),
lastname VARCHAR(50),
email VARCHAR(100),
passwd VARCHAR(255),
FOREIGN KEY (id_profile) REFERENCES ps_profile(id_profile)
);
-- Profiles Table
CREATE TABLE ps_profile (
id_profile INT PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL
);
-- Authorization Roles Table
CREATE TABLE ps_authorization_role (
id_authorization_role INT PRIMARY KEY,
slug VARCHAR(255) UNIQUE NOT NULL
);
-- Access Table (Permissions Details)
CREATE TABLE ps_access (
id_profile INT,
id_authorization_role INT,
PRIMARY KEY (id_profile, id_authorization_role),
FOREIGN KEY (id_profile) REFERENCES ps_profile(id_profile),
FOREIGN KEY (id_authorization_role) REFERENCES ps_authorization_role(id_authorization_role)
);
How It Works
- Assigning Profiles to Employees: When creating or managing employees, you assign them a profile by setting the
id_profilefield in theps_employeetable. - Defining Permissions for Profiles: Permissions are managed by linking
ps_profiletops_authorization_rolethrough theps_accesstable. This table records which profiles have which permissions. - Checking Permissions: When an employee tries to perform an action, PrestaShop checks the
ps_accesstable to see if the profile associated with the employee has the necessary permission.
Example Workflow
- Creating a New Profile:
- Insert a new row in the
ps_profiletable with the profile name.
- Insert a new row in the
- Assigning Permissions to a Profile:
- Insert rows in the
ps_accesstable linking the profile’sid_profileto the appropriateid_authorization_roleentries for the desired actions.
- Insert rows in the
- Assigning a Profile to an Employee:
- Update the
id_profilefield of the employee in theps_employeetable to the new profile’sid_profile.
- Update the
By understanding these relationships and how they interact, you can effectively manage user roles and permissions in PrestaShop, ensuring that employees have the appropriate access to perform their tasks.