How to build a staff task dashboard with roles and permissions
The problem
A manager needs to assign tasks, staff need to see only their own, and everything must export to CSV.
Data model
- users: id, name, role (admin, manager, staff)
- tasks: id, title, assignee_id, status, due_date
Rules
def can_view(user, task):
if user.role in ("admin", "manager"):
return True
return task.assignee_id == user.idEnforce this check on the server for every request. Hiding a button in the page is not security.
CSV export
import csv, io
buf = io.StringIO()
w = csv.writer(buf)
w.writerow(["id","title","status","due"])
for t in tasks:
w.writerow([t.id, t.title, t.status, t.due_date])Add filters (status, assignee, date) as query parameters and use the same permission check before building the export.
