Overview
TechCore Mini ERP implements a role-based access control system where each user is assigned to a role. Roles define the permissions and access levels that determine what actions users can perform within the system.Role Entity
Roles are stored in therol table with the following properties:
Unique identifier for the role (auto-incremented)
Name of the role (max 100 characters)
Indicates whether the role is active/enabled (defaults to
true)Database Schema
Indexes
The roles table includes:- IDX_rol_habilitado: Index on the
habilitadofield to efficiently filter active roles
Role-User Relationship
Each role can be assigned to multiple users, establishing a one-to-many relationship:One-to-Many
A single role can be assigned to multiple users in the system.
Required Assignment
Every user must have a role assigned via the
idrol foreign key constraint.Role Management
Creating Roles
When creating a new role:- Define a clear, descriptive
NombreRol(e.g., “Administrator”, “Sales Manager”, “Warehouse Staff”) - Set
Habilitadototrue(or leave as default) to activate the role - Ensure the role name reflects the permissions it will grant
Enabling/Disabling Roles
Roles can be enabled or disabled without deleting them:- Enabled (
Habilitado = 1): Users assigned to this role can access the system - Disabled (
Habilitado = 0): Users assigned to this role may have restricted access
Deleting Roles
Roles cannot be deleted if they have associated users due to the foreign key constraint from the
users table. You must either:- Reassign all users to different roles first, or
- Disable the role using
Habilitado = 0
Model Reference
The C# model for Role (TechCore.Models.Rol) includes:
Access Control Implementation
Role-Based Authorization
The role system enables implementing authorization checks throughout the application:Common Role Configurations
Administrator
Administrator
Full access to all system features including:
- User management
- Role configuration
- System settings
- All business operations (sales, purchases, inventory)
- Reports and analytics
Sales Manager
Sales Manager
Access to sales-related features:
- Create and manage sales orders
- View customer information
- Access sales reports
- Manage credit sales and payment plans
Purchase Manager
Purchase Manager
Access to purchasing operations:
- Create and manage purchase orders
- Manage supplier information
- View inventory levels
- Access purchase reports
Warehouse Staff
Warehouse Staff
Limited access to inventory functions:
- View product information
- Update stock levels
- View stock alerts
- Limited reporting capabilities
View Only
View Only
Read-only access:
- View reports
- View customer and product information
- No create, update, or delete permissions
Security Considerations
Principle of Least Privilege
Assign users only the minimum permissions required to perform their job functions
Separation of Duties
Avoid giving single roles excessive permissions that could lead to conflicts of interest
Querying Roles
Get All Active Roles
Get Users by Role
Count Users per Role
Best Practices
Role Naming
Use clear, business-oriented names that reflect job functions rather than technical permissions
Default Roles
Create a default role for new users with minimal permissions
Role Documentation
Maintain documentation of what each role can access and perform
Testing
Test role permissions thoroughly before deploying to production