Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: provide more information as part of the error
Fintan Halpenny committed 3 months ago
commit 88d6effabe00b059b5eac707ad1ab49c60e7af31
parent 70ac659f099a27338f77515c7228fafee8816f0d
1 file changed +21 -4
modified crates/radicle/src/cob/identity.rs
@@ -129,8 +129,24 @@ pub enum ApplyError {
    Git(#[from] git::raw::Error),
    #[error("identity document error: {0}")]
    Doc(#[from] DocError),
-
    #[error("non-delegate not authorized to perform this action")]
-
    NonDelegateUnauthorized,
+
    #[error("{author} is not a delegate, and only delegates are allowed to {action}")]
+
    NonDelegateUnauthorized { author: Did, action: String },
+
}
+

+
impl ApplyError {
+
    fn non_delegate_unauthorized(author: Did, action: &Action) -> Self {
+
        let action = match action {
+
            Action::Revision { .. } => "create a revision",
+
            Action::RevisionEdit { .. } => "edit a revision",
+
            Action::RevisionAccept { .. } => "accept a revision",
+
            Action::RevisionReject { .. } => "reject a revision",
+
            Action::RevisionRedact { .. } => "redact a revision",
+
        };
+
        Self::NonDelegateUnauthorized {
+
            author,
+
            action: action.to_string(),
+
        }
+
    }
}

/// Error updating or creating proposals.
@@ -446,8 +462,9 @@ impl Identity {
    ) -> Result<(), ApplyError> {
        let current = self.current().clone();

-
        if !current.is_delegate(&author.into()) {
-
            return Err(ApplyError::NonDelegateUnauthorized);
+
        let did = author.into();
+
        if !current.is_delegate(&did) {
+
            return Err(ApplyError::non_delegate_unauthorized(did, &action));
        }
        match action {
            Action::RevisionAccept {