feat(myshares): new version of myshares sections, supporting grants Users + Tokens
This commit is contained in:
@@ -312,5 +312,54 @@ pub struct SharedWithMeItemDto {
|
||||
pub resource: ResourceContentDto,
|
||||
}
|
||||
|
||||
/// Derive the closest-matching role label from a set of permissions.
|
||||
/// Maps the permission set to `"admin"`, `"editor"`, or `"viewer"`.
|
||||
pub fn role_from_permissions(perms: &[Permission]) -> &'static str {
|
||||
if perms.contains(&Permission::Delete) && perms.contains(&Permission::Share) {
|
||||
"admin"
|
||||
} else if perms.contains(&Permission::Create) || perms.contains(&Permission::Update) {
|
||||
"editor"
|
||||
} else {
|
||||
"viewer"
|
||||
}
|
||||
}
|
||||
|
||||
/// Response for `GET /api/grants/incoming/resources`.
|
||||
pub type SharedWithMeDto = CursorListResponse<SharedWithMeItemDto>;
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// My-Shares DTOs (GET /api/grants/outgoing/resources)
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/// One (subject, permissions) entry within an outgoing resource item.
|
||||
#[derive(Debug, Clone, Serialize, ToSchema)]
|
||||
pub struct OutgoingResourceGrantDto {
|
||||
pub grant_id: Uuid,
|
||||
/// `"user"` | `"token"`
|
||||
pub subject_type: String,
|
||||
pub subject_id: Uuid,
|
||||
/// Human-readable label (username for users, share name for tokens).
|
||||
pub subject_display: String,
|
||||
/// Derived role label: `"viewer"` | `"editor"` | `"admin"`.
|
||||
pub role: String,
|
||||
pub granted_at: chrono::DateTime<chrono::Utc>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expires_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||
/// Whether the token has a password set. Always `false` for user subjects.
|
||||
pub has_password: bool,
|
||||
}
|
||||
|
||||
/// One item in the my-shares list.
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct OutgoingResourceItemDto {
|
||||
pub resource_type: ResourceTypeDto,
|
||||
/// Earliest grant date across all subjects on this resource.
|
||||
pub first_shared_at: chrono::DateTime<chrono::Utc>,
|
||||
/// Full resource details. Shape is determined by `resource_type`.
|
||||
pub resource: ResourceContentDto,
|
||||
/// One entry per (subject, permissions) pair.
|
||||
pub grants: Vec<OutgoingResourceGrantDto>,
|
||||
}
|
||||
|
||||
/// Response for `GET /api/grants/outgoing/resources`.
|
||||
pub type MySharesDto = CursorListResponse<OutgoingResourceItemDto>;
|
||||
|
||||
@@ -12,7 +12,8 @@ use uuid::Uuid;
|
||||
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::domain::services::authorization::{
|
||||
Grant, GrantCursor, IncomingGrantSummary, Permission, Resource, ResourceKind, Subject,
|
||||
Grant, GrantCursor, IncomingGrantSummary, OutgoingResourceSummary, Permission, Resource,
|
||||
ResourceKind, Subject,
|
||||
};
|
||||
|
||||
pub trait AuthorizationEngine: Send + Sync + 'static {
|
||||
@@ -97,6 +98,21 @@ pub trait AuthorizationEngine: Send + Sync + 'static {
|
||||
/// `GET /api/grants/outgoing` ("things I've shared with others").
|
||||
async fn list_outgoing_grants(&self, granted_by: Uuid) -> Result<Vec<Grant>, DomainError>;
|
||||
|
||||
/// Cursor-paginated list of resources that `granted_by` has shared with
|
||||
/// others. Multiple permission rows for the same (subject, resource) pair
|
||||
/// are collapsed into one `OutgoingGrantEntry`; multiple subjects on the
|
||||
/// same resource are grouped into one `OutgoingResourceSummary`.
|
||||
///
|
||||
/// Returns `(summaries, next_cursor)`.
|
||||
async fn list_outgoing_resources_paged(
|
||||
&self,
|
||||
granted_by: Uuid,
|
||||
limit: u32,
|
||||
cursor: Option<GrantCursor>,
|
||||
sort_by: &str,
|
||||
reverse: bool,
|
||||
) -> Result<(Vec<OutgoingResourceSummary>, Option<GrantCursor>), DomainError>;
|
||||
|
||||
/// Create a grant. Idempotent — duplicates are absorbed by the UNIQUE
|
||||
/// constraint; if the row already exists its `expires_at` is updated.
|
||||
async fn grant(
|
||||
|
||||
Reference in New Issue
Block a user