Skip to content
Snippets Groups Projects
Commit 8b2548ac authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

wip replace cert allowed check

parent 08beaa33
No related branches found
No related tags found
No related merge requests found
......@@ -242,8 +242,6 @@ pub mod pallet {
pub enum Error<T, I = ()> {
/// An identity cannot certify itself
CannotCertifySelf,
/// Certification non autorisée
CertNotAllowed,
/// This identity has already issued the maximum number of certifications
IssuedTooManyCert,
/// Issuer not found
......@@ -325,10 +323,7 @@ pub mod pallet {
ensure!(issuer_owner_key == who, DispatchError::BadOrigin);
// Verify compatibility with other pallets state
ensure!(
T::IsCertAllowed::is_cert_allowed(issuer, receiver),
Error::<T, I>::CertNotAllowed
);
T::IsCertAllowed::check_cert_allowed(issuer, receiver)?;
// Verify rule MinReceivedCertToBeAbleToIssueCert
let issuer_idty_cert_meta = <StorageIdtyCertMeta<T, I>>::get(issuer);
......
......@@ -14,13 +14,15 @@
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use frame_support::pallet_prelude::*;
pub trait IsCertAllowed<IdtyIndex> {
fn is_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> bool;
fn check_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> Result<(), DispatchError>;
}
impl<IdtyIndex> IsCertAllowed<IdtyIndex> for () {
fn is_cert_allowed(_issuer: IdtyIndex, _receiver: IdtyIndex) -> bool {
true
fn check_cert_allowed(_issuer: IdtyIndex, _receiver: IdtyIndex) -> Result<(), DispatchError> {
Ok(())
}
}
......
......@@ -107,6 +107,10 @@ pub mod pallet {
NotAllowedToChangeIdtyAddress,
/// Not allowed to remove identity
NotAllowedToRemoveIdty,
/// Issuer can not emit cert because it is not validated
IssuerCanNotEmitCert,
/// Can not issue cert to unconfirmed identity
CertToUnconfirmedIdty,
}
}
......@@ -195,24 +199,19 @@ where
impl<T: Config<I>, I: 'static> pallet_certification::traits::IsCertAllowed<IdtyIndex>
for Pallet<T, I>
{
fn is_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> bool {
fn check_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> Result<(), DispatchError> {
if let Some(issuer_data) = pallet_identity::Pallet::<T>::identity(issuer) {
if issuer_data.status != IdtyStatus::Validated {
return false;
return Err(Error::<T, I>::IssuerCanNotEmitCert.into());
}
if let Some(receiver_data) = pallet_identity::Pallet::<T>::identity(receiver) {
match receiver_data.status {
IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => true,
IdtyStatus::Created => false,
}
} else {
// Receiver not found
false
}
} else {
// Issuer not found
false
IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => (),
IdtyStatus::Created => return Err(Error::<T, I>::CertToUnconfirmedIdty.into()),
}
};
};
Ok(())
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment