Skip to content

Commit 748d5f1

Browse files
authored
Merge pull request #225 from hashed-io/proxy_financial/bulkupload
Proxy financial/bulkupload
2 parents f35a367 + 1a2485f commit 748d5f1

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ impl<T: Config> Pallet<T> {
487487
user_info.name = mod_name.into_inner()[0].clone();
488488
}
489489
if let Some(mod_role) = role {
490+
// If user has assigned projects cannot update role
491+
ensure!(<ProjectsByUser<T>>::get(user.clone()).is_empty(), Error::<T>::UserHasAssignedProjectsCannotUpdateRole);
492+
490493
user_info.role = mod_role;
491494
}
492495
Ok(())
@@ -507,10 +510,9 @@ impl<T: Config> Pallet<T> {
507510
Self::do_sudo_remove_administrator(user.clone())?;
508511
},
509512
_ => {
510-
// Can not delete a user if the user is assigned to a project
511-
//TOREVIEW: Check if this validations is working as expected
513+
// Can not delete a user if the user has assigned projects
512514
let projects_by_user = <ProjectsByUser<T>>::get(user.clone());
513-
ensure!(projects_by_user.is_empty(), Error::<T>::UserHasAssignedProjects);
515+
ensure!(projects_by_user.is_empty(), Error::<T>::UserHasAssignedProjectsCannotDelete);
514516

515517
// Remove user from UsersInfo storage map
516518
<UsersInfo<T>>::remove(user.clone());
@@ -904,6 +906,8 @@ impl<T: Config> Pallet<T> {
904906
// Get drawdown transactions
905907
let drawdown_transactions = TransactionsByDrawdown::<T>::try_get(project_id, drawdown_id).map_err(|_| Error::<T>::DrawdownNotFound)?;
906908

909+
// Get timestamp
910+
let timestamp = Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
907911
// Update each transaction status to approved
908912
for transaction_id in drawdown_transactions {
909913
// Get transaction data
@@ -916,6 +920,7 @@ impl<T: Config> Pallet<T> {
916920
<TransactionsInfo<T>>::try_mutate::<_,_,DispatchError,_>(transaction_id, |transaction_data| {
917921
let transaction_data = transaction_data.as_mut().ok_or(Error::<T>::TransactionNotFound)?;
918922
transaction_data.status = TransactionStatus::Approved;
923+
transaction_data.closed_date = timestamp;
919924
Ok(())
920925
})?;
921926
}
@@ -924,6 +929,7 @@ impl<T: Config> Pallet<T> {
924929
<DrawdownsInfo<T>>::try_mutate::<_,_,DispatchError,_>(drawdown_id, |drawdown_data| {
925930
let drawdown_data = drawdown_data.as_mut().ok_or(Error::<T>::DrawdownNotFound)?;
926931
drawdown_data.status = DrawdownStatus::Approved;
932+
drawdown_data.close_date = timestamp;
927933
Ok(())
928934
})?;
929935

@@ -952,8 +958,10 @@ impl<T: Config> Pallet<T> {
952958
// Ensure drawdown is in submitted status
953959
ensure!(drawdown_data.status == DrawdownStatus::Submitted, Error::<T>::DrawdownIsNotInSubmittedStatus);
954960

955-
// Ensure drawdown has transactions
956-
ensure!(<TransactionsByDrawdown<T>>::contains_key(project_id, drawdown_id), Error::<T>::DrawdownHasNoTransactions);
961+
// Ensure drawdown has transactions if drawdown type == EB5
962+
if drawdown_data.drawdown_type == DrawdownType::EB5 {
963+
ensure!(<TransactionsByDrawdown<T>>::contains_key(project_id, drawdown_id), Error::<T>::DrawdownHasNoTransactions);
964+
}
957965

958966
// Get drawdown transactions
959967
let drawdown_transactions = TransactionsByDrawdown::<T>::try_get(project_id, drawdown_id).map_err(|_| Error::<T>::DrawdownNotFound)?;
@@ -1068,7 +1076,7 @@ impl<T: Config> Pallet<T> {
10681076
)?;
10691077
},
10701078
CUDAction::Delete => {
1071-
// Delete transaction needs (expenditure_id, transaction_id)
1079+
// Delete transaction needs (transaction_id)
10721080
Self::do_delete_transaction(
10731081
transaction.4.ok_or(Error::<T>::TransactionIdNotFound)?,
10741082
)?;
@@ -1103,6 +1111,9 @@ impl<T: Config> Pallet<T> {
11031111
// Create transaction id
11041112
let transaction_id = (drawdown_id, amount, expenditure_id, timestamp, project_id).using_encoded(blake2_256);
11051113

1114+
// Ensure expenditure id exists
1115+
ensure!(ExpendituresInfo::<T>::contains_key(expenditure_id), Error::<T>::ExpenditureNotFound);
1116+
11061117
// Create transaction data
11071118
let transaction_data = TransactionData::<T> {
11081119
project_id,
@@ -1227,6 +1238,10 @@ impl<T: Config> Pallet<T> {
12271238
// Ensure amount is valid
12281239
Self::is_amount_valid(total_amount)?;
12291240

1241+
//Ensure only Construction loan & developer equity drawdowns can be bulk uploaded
1242+
let drawdown_data = DrawdownsInfo::<T>::get(drawdown_id).ok_or(Error::<T>::DrawdownNotFound)?;
1243+
ensure!(drawdown_data.drawdown_type == DrawdownType::ConstructionLoan || drawdown_data.drawdown_type == DrawdownType::DeveloperEquity, Error::<T>::DrawdownTypeNotSupportedForBulkUpload);
1244+
12301245
// Ensure documents is not empty
12311246
ensure!(!documents.is_empty(), Error::<T>::DocumentsIsEmpty);
12321247

pallets/proxy-financial/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ pub mod pallet {
445445
ProjectsIsEmpty,
446446
/// Inflation rate was not provided
447447
InflationRateRequired,
448+
/// Bulkupload drawdowns are only allowed for Construction Loan & Developer Equity
449+
DrawdownTypeNotSupportedForBulkUpload,
450+
/// Cannot edit user role if the user is assigned to a project
451+
UserHasAssignedProjectsCannotUpdateRole,
452+
/// Cannot delete user if the user is assigned to a project
453+
UserHasAssignedProjectsCannotDelete,
448454

449455
}
450456

0 commit comments

Comments
 (0)