pub struct UserRoleAssignment {
pub id: Uuid,
pub user_id: Uuid,
pub role: UserRole,
pub organization_id: Option<Uuid>,
pub is_primary: bool,
pub valid_until: Option<DateTime<Utc>>,
pub delegated_from_user_id: Option<Uuid>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Represents an assignment of a role to a user within an optional organization scope.
§Story 3.5 — Temporary role delegation (FR8 INV-8)
Two optional fields turn a permanent native assignment into a time-bounded delegated assignment:
valid_until = None⇒ permanent / native role (legacy behaviour).valid_until = Some(t)⇒ delegated assignment that auto-expires att.delegated_from_user_id = Some(delegator)⇒ trail of who delegated the role; used bycrate::application::use_cases::RoleDelegationUseCasesto enforce the non-transitive invariant (a user cannot re-delegate a role that was itself delegated to them).
Fields§
§id: Uuid§user_id: Uuid§role: UserRole§organization_id: Option<Uuid>§is_primary: bool§valid_until: Option<DateTime<Utc>>Story 3.5: end of validity. None = permanent native role.
delegated_from_user_id: Option<Uuid>Story 3.5: source of the delegation. None = native role.
Some(uid) = uid granted this role for a bounded duration.
created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl UserRoleAssignment
impl UserRoleAssignment
Sourcepub fn new(
user_id: Uuid,
role: UserRole,
organization_id: Option<Uuid>,
is_primary: bool,
) -> Self
pub fn new( user_id: Uuid, role: UserRole, organization_id: Option<Uuid>, is_primary: bool, ) -> Self
Creates a new permanent (native) role assignment.
valid_until and delegated_from_user_id default to None. Use
UserRoleAssignment::new_delegated for a time-bounded delegation.
Sourcepub fn new_delegated(
user_id: Uuid,
role: UserRole,
organization_id: Option<Uuid>,
valid_until: DateTime<Utc>,
delegated_from_user_id: Uuid,
) -> Self
pub fn new_delegated( user_id: Uuid, role: UserRole, organization_id: Option<Uuid>, valid_until: DateTime<Utc>, delegated_from_user_id: Uuid, ) -> Self
Creates a new delegated role assignment (Story 3.5).
A delegated assignment is never the primary role of the target user —
keeping the user’s native primary intact for users.role consistency.
pub fn set_primary(&mut self, primary: bool)
Sourcepub fn is_delegated(&self) -> bool
pub fn is_delegated(&self) -> bool
True if this assignment is a delegated (non-native) role.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
True if the assignment carries a valid_until and it is in the past.
A permanent native role (valid_until = None) is never expired.
Sourcepub fn is_expired_at(&self, t: DateTime<Utc>) -> bool
pub fn is_expired_at(&self, t: DateTime<Utc>) -> bool
Testable variant of is_expired taking an explicit reference time.
Sourcepub fn is_currently_active(&self) -> bool
pub fn is_currently_active(&self) -> bool
True if the assignment authorises actions right now.
Native (permanent) assignments are always active. Delegated assignments are active iff their window has not elapsed.
Trait Implementations§
Source§impl Clone for UserRoleAssignment
impl Clone for UserRoleAssignment
Source§fn clone(&self) -> UserRoleAssignment
fn clone(&self) -> UserRoleAssignment
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UserRoleAssignment
impl Debug for UserRoleAssignment
Source§impl<'de> Deserialize<'de> for UserRoleAssignment
impl<'de> Deserialize<'de> for UserRoleAssignment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for UserRoleAssignment
Source§impl From<UserRoleAssignment> for UserRoleAssignmentResponse
impl From<UserRoleAssignment> for UserRoleAssignmentResponse
Source§fn from(a: UserRoleAssignment) -> Self
fn from(a: UserRoleAssignment) -> Self
Source§impl From<UserRoleAssignment> for RoleDelegationResponse
impl From<UserRoleAssignment> for RoleDelegationResponse
Source§fn from(a: UserRoleAssignment) -> Self
fn from(a: UserRoleAssignment) -> Self
Source§impl PartialEq for UserRoleAssignment
impl PartialEq for UserRoleAssignment
Source§fn eq(&self, other: &UserRoleAssignment) -> bool
fn eq(&self, other: &UserRoleAssignment) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for UserRoleAssignment
impl Serialize for UserRoleAssignment
impl StructuralPartialEq for UserRoleAssignment
Auto Trait Implementations§
impl Freeze for UserRoleAssignment
impl RefUnwindSafe for UserRoleAssignment
impl Send for UserRoleAssignment
impl Sync for UserRoleAssignment
impl Unpin for UserRoleAssignment
impl UnsafeUnpin for UserRoleAssignment
impl UnwindSafe for UserRoleAssignment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more