Mar 04 2026: Implement customer's view functionalities - Phase 1
This commit is contained in:
+27
-1
@@ -18,4 +18,30 @@ def supervisor_required(f):
|
||||
flash('Supervisor access required.', 'danger')
|
||||
return redirect(url_for('dashboard.index'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
return decorated_function
|
||||
|
||||
def project_manager_required(f):
|
||||
"""Grants access to admin, supervisor, and project_manager roles."""
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if not current_user.is_authenticated or current_user.role not in [
|
||||
'admin', 'supervisor', 'project_manager'
|
||||
]:
|
||||
flash('Project Manager access required.', 'danger')
|
||||
return redirect(url_for('dashboard.index'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
def customer_required(f):
|
||||
"""Restricts access to customer-role users only.
|
||||
|
||||
Internal staff (admin, supervisor, inspector, project_manager) should
|
||||
never be routed through customer-scoped views — use their own routes.
|
||||
"""
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if not current_user.is_authenticated or current_user.role != 'customer':
|
||||
flash('Customer portal access required.', 'danger')
|
||||
return redirect(url_for('dashboard.index'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
+5
-1
@@ -49,7 +49,11 @@ class UserForm(FlaskForm):
|
||||
password = PasswordField('Password', validators=[Optional(), Length(min=6, max=100)])
|
||||
confirm_password = PasswordField('Confirm Password', validators=[Optional(), EqualTo('password')])
|
||||
role = SelectField('Role', choices=[
|
||||
('admin', 'Administrator'), ('supervisor', 'Supervisor'), ('inspector', 'Inspector')
|
||||
('admin', 'Administrator'),
|
||||
('supervisor', 'Supervisor'),
|
||||
('inspector', 'Inspector'),
|
||||
('project_manager', 'Project Manager'),
|
||||
('customer', 'Customer'),
|
||||
], validators=[DataRequired()])
|
||||
|
||||
def __init__(self, user=None, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user