Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions crates/nvisy-postgres/src/model/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use crate::types::Handle;
pub struct Account {
/// Unique account identifier.
pub id: Uuid,
/// Administrative privileges across the entire system.
pub is_admin: bool,
/// Account identity verification status (email confirmation, etc.).
pub is_verified: bool,
/// Temporarily disables account access while preserving data.
Expand Down Expand Up @@ -54,8 +52,8 @@ pub struct Account {

impl Account {
/// An account row with a fresh unique handle and matching email, for tests.
/// Not admin/verified/suspended; timestamps are now. Useful to downstream
/// crates that need an `Account` without a database.
/// Not verified/suspended; timestamps are now. Useful to downstream crates
/// that need an `Account` without a database.
#[cfg(any(feature = "test_util", test))]
#[must_use]
pub fn test() -> Self {
Expand All @@ -64,7 +62,6 @@ impl Account {
let now: Timestamp = jiff::Timestamp::now().into();
Self {
id: Uuid::now_v7(),
is_admin: false,
is_verified: false,
is_suspended: false,
username,
Expand Down Expand Up @@ -142,8 +139,6 @@ pub struct UpdateAccount {
pub timezone: Option<String>,
/// Preferred locale code.
pub locale: Option<String>,
/// Administrative privileges.
pub is_admin: Option<bool>,
/// Account identity verification status.
pub is_verified: Option<bool>,
/// Account suspension status.
Expand Down
4 changes: 4 additions & 0 deletions crates/nvisy-postgres/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod event_outbox;
mod pipeline_reference;
mod workspace;
mod workspace_activity;
mod workspace_assignment;
mod workspace_connection;
mod workspace_connection_schedule;
mod workspace_connection_sync;
Expand Down Expand Up @@ -45,6 +46,9 @@ pub use pipeline_reference::PipelinePolicy;
// Workspace models
pub use workspace::{NewWorkspace, UpdateWorkspace, Workspace};
pub use workspace_activity::{NewWorkspaceActivity, WorkspaceActivity};
pub use workspace_assignment::{
NewWorkspaceAssignment, UpdateWorkspaceAssignment, WorkspaceAssignment,
};
pub use workspace_connection::{
NewWorkspaceConnection, UpdateWorkspaceConnection, WorkspaceConnection,
};
Expand Down
81 changes: 81 additions & 0 deletions crates/nvisy-postgres/src/model/workspace_assignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! Workspace assignment model for PostgreSQL database operations.

use diesel::prelude::*;
use jiff_diesel::Timestamp;
use uuid::Uuid;

use crate::schema::workspace_assignments;
use crate::types::AssignmentStatus;

/// An assignment: one reviewer's assignment of one file for redaction review.
///
/// A file may be assigned to several reviewers at once (like GitHub assignees);
/// each reviewer's assignment is its own row with its own [`AssignmentStatus`].
#[derive(Debug, Clone, PartialEq, Queryable, Selectable)]
#[diesel(table_name = workspace_assignments)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct WorkspaceAssignment {
/// Unique assignment identifier.
pub id: Uuid,
/// Workspace this assignment belongs to (denormalized for fast per-workspace
/// queries).
pub workspace_id: Uuid,
/// File under review.
pub file_id: Uuid,
/// Reviewer the file is assigned to.
pub assignee_account_id: Uuid,
/// Account that created the assignment, for the audit trail. `None` if that
/// account was since removed.
pub assigned_account_id: Option<Uuid>,
/// The reviewer's current review status for this file.
pub status: AssignmentStatus,
/// When the assignment was created.
pub created_at: Timestamp,
/// When the assignment was last updated.
pub updated_at: Timestamp,
}

/// Data for creating a new workspace assignment.
#[derive(Debug, Default, Clone, Insertable)]
#[diesel(table_name = workspace_assignments)]
#[diesel(check_for_backend(diesel::pg::Pg))]
#[must_use]
pub struct NewWorkspaceAssignment {
/// Workspace ID (required).
pub workspace_id: Uuid,
/// File ID (required).
pub file_id: Uuid,
/// Reviewer the file is assigned to (required).
pub assignee_account_id: Uuid,
/// Account that created the assignment (the assigner).
pub assigned_account_id: Option<Uuid>,
/// Initial status.
pub status: Option<AssignmentStatus>,
}

impl NewWorkspaceAssignment {
/// A minimal assignment of `file_id` to `assignee_account_id`, for tests.
/// The status takes its database default (`assigned`).
#[cfg(any(feature = "test_util", test))]
pub fn test(workspace_id: Uuid, file_id: Uuid, assignee_account_id: Uuid) -> Self {
Self {
workspace_id,
file_id,
assignee_account_id,
..Default::default()
}
}
}

/// Data for updating a workspace assignment.
///
/// Only the review status is mutable: reassignment is remove-then-add, not a
/// field change.
#[derive(Debug, Clone, Default, AsChangeset)]
#[diesel(table_name = workspace_assignments)]
#[diesel(check_for_backend(diesel::pg::Pg))]
#[must_use]
pub struct UpdateWorkspaceAssignment {
/// The reviewer's review status for this file.
pub status: Option<AssignmentStatus>,
}
4 changes: 4 additions & 0 deletions crates/nvisy-postgres/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod pipeline_reference;
mod search;
mod workspace;
mod workspace_activity;
mod workspace_assignment;
mod workspace_connection;
mod workspace_connection_schedule;
mod workspace_connection_sync;
Expand Down Expand Up @@ -53,6 +54,9 @@ pub use event_outbox::EventOutboxRepository;
pub use pipeline_reference::PipelineReferenceRepository;
pub use workspace::WorkspaceRepository;
pub use workspace_activity::{ActivityFilter, WorkspaceActivityRepository};
pub use workspace_assignment::{
AssignmentListRow, CreateAssignmentOutcome, WorkspaceAssignmentRepository,
};
pub use workspace_connection::{ScheduledConnection, WorkspaceConnectionRepository};
pub use workspace_connection_schedule::WorkspaceConnectionScheduleRepository;
pub use workspace_connection_sync::WorkspaceConnectionSyncRepository;
Expand Down
Loading