From f74791ef3f8c943bebb1039202bdd7fbfaf952cc Mon Sep 17 00:00:00 2001 From: Steve Finkelstein Date: Mon, 1 Aug 2022 11:45:39 -0400 Subject: [PATCH 1/2] Add timeperiod validation for proposal entries Signed-off-by: Steve Finkelstein --- src/validations/timeperiod/examples.json | 14 ++++++++++++ src/validations/timeperiod/index.ts | 27 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/validations/timeperiod/examples.json create mode 100644 src/validations/timeperiod/index.ts diff --git a/src/validations/timeperiod/examples.json b/src/validations/timeperiod/examples.json new file mode 100644 index 000000000..02381e38e --- /dev/null +++ b/src/validations/timeperiod/examples.json @@ -0,0 +1,14 @@ +[ + { + "name": "Example of a prop entry time constrained validation", + "validation": { + "name": "timeperiod", + "params": { + "propEntryStart": 1659108444521, + "propEntryEnd": 1659194844521 + } + }, + "network": "1", + "userAddress": "" + } +] diff --git a/src/validations/timeperiod/index.ts b/src/validations/timeperiod/index.ts new file mode 100644 index 000000000..193ab54c7 --- /dev/null +++ b/src/validations/timeperiod/index.ts @@ -0,0 +1,27 @@ +export default async function validate( + author: string, + space, + proposal, + options +): Promise { + const onlyMembers = options.onlyMembers || space.filters?.onlyMembers; + const members = (space.members || []).map((address) => address.toLowerCase()); + const {propEntryStart = 0, propEntryEnd = 0} = options; + + if (!propEntryStart || !propEntryEnd || (propEntryStart >= propEntryEnd)) return false; + + if (members.includes(author.toLowerCase())) return true; + + if (onlyMembers) return false; + + const now = new Date().getTime(); + const startTime = new Date(propEntryStart).getTime(); + const endTime = new Date(propEntryEnd).getTime(); + + // Only allow proposals being submitted in this time window. + if (now >= startTime && now <= endTime) { + return true; + } + + return false; +} From acfbb4174175e33c50d86bc6d1caa59c9ee76a6e Mon Sep 17 00:00:00 2001 From: Steve Finkelstein Date: Wed, 3 Aug 2022 18:20:20 -0400 Subject: [PATCH 2/2] Add timeperiod space validation to index export Signed-off-by: Steve Finkelstein --- src/validations/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/validations/index.ts b/src/validations/index.ts index ba48e05da..440609eae 100644 --- a/src/validations/index.ts +++ b/src/validations/index.ts @@ -1,9 +1,11 @@ import basic from './basic'; import aaveSpaceValidation from './aave'; import nounsSpaceValidation from './nouns'; +import timeperiodSpaceValidation from './timeperiod'; export default { basic, aave: aaveSpaceValidation, - nouns: nounsSpaceValidation + nouns: nounsSpaceValidation, + timeperiod: timeperiodSpaceValidation };