Skip to content

Commit

Permalink
feat: AuthorizaztionGuard に try_into_read 関数を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Dec 14, 2024
1 parent d27a1e4 commit 34347b6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/domain/src/types/authorization_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<T: AuthorizationGuardDefinitions<T>> AuthorizationGuard<T, Update> {
}

impl<T: AuthorizationGuardDefinitions<T>> AuthorizationGuard<T, Read> {
/// `actor` が `guard_target` を取得することを試みます
/// `actor` が `guard_target` の参照を取得することを試みます
pub fn try_read(&self, actor: &User) -> Result<&T, DomainError> {
if self.guard_target.can_read(actor) {
Ok(&self.guard_target)
Expand All @@ -121,6 +121,15 @@ impl<T: AuthorizationGuardDefinitions<T>> AuthorizationGuard<T, Read> {
}
}

/// `actor` が `guard_target` を取得することを試みます。
pub fn try_into_read(self, actor: &User) -> Result<T, DomainError> {
if self.guard_target.can_read(actor) {
Ok(self.guard_target)
} else {
Err(DomainError::Forbidden)
}
}

/// [`AuthorizationGuard`] の Action を [`Update`] に変換します。
pub fn into_update(self) -> AuthorizationGuard<T, Update> {
AuthorizationGuard {
Expand Down

0 comments on commit 34347b6

Please sign in to comment.