Skip to content

Commit 567fc5c

Browse files
committed
Allow the administrator to edit any field for a selected project
1 parent 21ed8ca commit 567fc5c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<T: Config> Pallet<T> {
125125
let project_id = (title.clone()).using_encoded(blake2_256);
126126

127127
//ensure completion_date is in the future
128-
ensure!(completion_date > timestamp, Error::<T>::CompletionDateMustBeLater);
128+
ensure!(completion_date > creation_date, Error::<T>::CompletionDateMustBeLater);
129129

130130
//Create project data
131131
let project_data = ProjectData::<T> {
@@ -172,10 +172,11 @@ impl<T: Config> Pallet<T> {
172172
pub fn do_edit_project(
173173
admin: T::AccountId,
174174
project_id: [u8;32],
175-
title: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
175+
title: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
176176
description: Option<BoundedVec<FieldDescription, T::MaxBoundedVecs>>,
177177
image: Option<BoundedVec<CID, T::MaxBoundedVecs>>,
178-
address: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
178+
address: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
179+
creation_date: Option<u64>,
179180
completion_date: Option<u64>,
180181
) -> DispatchResult {
181182
//ensure admin permissions
@@ -210,9 +211,12 @@ impl<T: Config> Pallet<T> {
210211
let mod_address = address.into_inner();
211212
project.address = mod_address[0].clone();
212213
}
214+
if let Some(creation_date) = creation_date {
215+
project.creation_date = creation_date;
216+
}
213217
if let Some(completion_date) = completion_date {
214218
//ensure new completion_date date is in the future
215-
ensure!(completion_date > current_timestamp, Error::<T>::CompletionDateMustBeLater);
219+
//ensure!(completion_date > current_timestamp, Error::<T>::CompletionDateMustBeLater);
216220
project.completion_date = completion_date;
217221
}
218222
//TOREVIEW: Check if this is working
@@ -221,6 +225,9 @@ impl<T: Config> Pallet<T> {
221225
Ok(())
222226
})?;
223227

228+
//Ensure completion_date is later than creation_date
229+
Self::is_project_completion_date_later(project_id)?;
230+
224231
// Event
225232
Self::deposit_event(Event::ProjectEdited(project_id));
226233
Ok(())
@@ -981,6 +988,17 @@ impl<T: Config> Pallet<T> {
981988
Ok(())
982989
}
983990

991+
fn is_project_completion_date_later(
992+
project_id: [u8;32],
993+
) -> DispatchResult {
994+
// Get project data & ensure project exists
995+
let project_data = ProjectsInfo::<T>::get(project_id).ok_or(Error::<T>::ProjectNotFound)?;
996+
997+
// Ensure completion date is later than start date
998+
ensure!(project_data.completion_date > project_data.creation_date, Error::<T>::CompletionDateMustBeLater);
999+
Ok(())
1000+
}
1001+
9841002
fn add_project_role(
9851003
project_id: [u8;32],
9861004
user: T::AccountId,

pallets/proxy-financial/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub mod pallet {
289289
ProjectIdAlreadyInUse,
290290
/// Timestamp error
291291
TimestampError,
292-
/// Completition date must be later than creation date
292+
/// Completion date must be later than creation date
293293
CompletionDateMustBeLater,
294294
/// User is already registered
295295
UserAlreadyRegistered,

0 commit comments

Comments
 (0)