Models: SafeUser/SafePrintJob, PrintJobLog redesign, job_id→id, datetime timestamps, model-based request.state.user#2
Merged
afonsoingles merged 6 commits intoMar 16, 2026
Conversation
Co-authored-by: afonsoingles <110609949+afonsoingles@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add models and schemas for database integration
feat: Pydantic v2 models/schemas for all DB entities
Mar 15, 2026
Co-authored-by: afonsoingles <110609949+afonsoingles@users.noreply.github.com>
Copilot
AI
changed the title
feat: Pydantic v2 models/schemas for all DB entities
feat: structured UserPermissions model with backward compatibility migration
Mar 15, 2026
…model-based request.state.user Co-authored-by: afonsoingles <110609949+afonsoingles@users.noreply.github.com>
Copilot
AI
changed the title
feat: structured UserPermissions model with backward compatibility migration
Structured models: SafeUser/SafePrintJob, PrintJobLog redesign, job_id→id, model-based request.state.user
Mar 15, 2026
Co-authored-by: afonsoingles <110609949+afonsoingles@users.noreply.github.com>
Copilot
AI
changed the title
Structured models: SafeUser/SafePrintJob, PrintJobLog redesign, job_id→id, model-based request.state.user
Models: SafeUser/SafePrintJob, PrintJobLog redesign, job_id→id, datetime timestamps, model-based request.state.user
Mar 15, 2026
afonsoingles
requested changes
Mar 16, 2026
| id: str | ||
| timestamp: float | ||
| actor: str # "system" or a user id | ||
| type: str # e.g. "job_created", "job_accepted", "job_rejected" |
Owner
There was a problem hiding this comment.
Suggested change
| type: str # e.g. "job_created", "job_accepted", "job_rejected" | |
| type: str |
| self.db.mongo.users.insert_one(user) | ||
|
|
||
| self.db.redis.set(f"users.user:{id}", json.dumps(user), ex=10800) | ||
| now_ts = datetime.datetime.now(datetime.timezone.utc) |
Owner
There was a problem hiding this comment.
Suggested change
| now_ts = datetime.datetime.now(datetime.timezone.utc) | |
| now_ts = datetime.datetime.now(datetime.timezone.utc).timestamp() |
Contributor
Author
There was a problem hiding this comment.
Reverted in c23fea5. Pydantic v2 still coerces the float to a UTC-aware datetime when building the model.
afonsoingles
requested changes
Mar 16, 2026
afonsoingles
left a comment
Owner
There was a problem hiding this comment.
@copilot check suggestions!
…) in create_user Co-authored-by: afonsoingles <110609949+afonsoingles@users.noreply.github.com>
afonsoingles
approved these changes
Mar 16, 2026
Contributor
Author
afonsoingles
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces loose
floattimestamps and plain-dict user/job representations with properly typed Pydantic v2 models throughout the stack.Models
models/user.pySafeUser— base model, all fields exceptpassword; holds the backward-compat_coerce_permissionsvalidatorUser(SafeUser)— addsOptional[str] passwordmodels/print_job.pyPrintJobLogredesigned:id,timestamp,actor("system"or user id),type(e.g."job_created"),description(optional)PrintJob.job_id→PrintJob.idSafePrintJob— excludescups_job_idandfile(R2 path); available viaPrintJob.to_safe()floattimestamp fields (created_at,updated_at,timestamp) →datetimeBackward-compat
model_validator(mode="before")on every renamed/redesigned model transparently coerces old MongoDB documents on read — no migration required. Pydantic v2 natively coerces stored Unix epoch floats to UTC-awaredatetime.Tools & decorator
get_user_by_id/get_user_by_emailreturnSafeUser/Userinstances instead of dictsrequest.state.useris now a model instance — attribute access everywhere:tools/printer.py—_create_logemits the newPrintJobLogschema; user-facing methods returnSafePrintJobdicts viato_safe()tools/users.py—.timestamp()calls removed;datetime.now(utc)passed directly to models📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.