Activity logs
Activity logs for audits and revisions
Model Structure
The ActivityLog
table records user activities performed on various entities like projects, tasks, microtasks, files, group chats, and user accounts.
Key Columns:
id
: Unique log entry ID (primary key).user_id
: ID of the user performing the action (required).object_user_id
: Optional target user affected by the action.project_id
: Optional related project ID.task_id
: Optional related task ID.microtask_id
: Optional related microtask ID.file_id
: Optional related file ID.groupchat_id
: Optional related group chat ID.timestamp
: When the action occurred.changes
: Optional free-text field describing detailed changes or context.
Relationships:
Linked with entities (
User
,Project
,Task
,Microtask
,File
,GroupChat
) via foreign keys and ORM relationships.
How Logs Are Saved (Based on Previous Code)
General Flow:
Action Occurs — For example, creating or editing a microtask or adding a file.
Create ActivityLog instance with relevant fields:
user_id
: The current user performing the action (retrieved from session or request).task_id
,microtask_id
,file_id
, or other relevant foreign key depending on the action context.timestamp
: Set to the current time (datetime.now()
).action
: A string matching one of the predefined log actions (e.g.,"microtask_created"
,"task_added_file"
).changes
: A descriptive string explaining the action or data involved (e.g.,"name changed from 'old' to 'new'"
, or a file URL reference).
Add the log object to the database session (
request.dbsession.add(log)
).Commit the session later to persist the log.
Example from Microtask Creation (simplified):
log = ActivityLog(
user_id=current_user_id,
microtask_id=new_microtask.id,
timestamp=datetime.now(),
action='microtask_created',
changes=f"Microtask '{new_microtask.name}' created."
)
request.dbsession.add(log)
Last updated