Commit 42ff981d authored by Stephane Glondu's avatar Stephane Glondu

Centralize automatic deletion constants

parent 8bc97ca0
......@@ -277,3 +277,6 @@ let default_creation_date = datetime_of_string "\"2018-06-06 00:00:00.000000\""
let default_validation_date = datetime_of_string "\"2015-10-01 00:00:00.000000\""
let default_tally_date = datetime_of_string "\"2018-06-06 00:00:00.000000\""
let default_archive_date = datetime_of_string "\"2018-06-06 00:00:00.000000\""
let days_to_archive = 14
let days_to_delete = 365
......@@ -114,3 +114,6 @@ val default_creation_date : datetime
val default_validation_date : datetime
val default_tally_date : datetime
val default_archive_date : datetime
val days_to_archive : int
val days_to_delete : int
......@@ -2065,24 +2065,24 @@ let get_all_draft_election_dates () =
let process_election_for_data_policy (uuid, state) =
let now = now () in
let one_year_ago = datetime_add now (day (-365)) in
let one_week_ago = datetime_add now (day (-7)) in
let delete_t = datetime_add now (day (-days_to_delete)) in
let archive_t = datetime_add now (day (-days_to_archive)) in
match state with
| `Draft se ->
let t = option_get se.se_creation_date default_creation_date in
if datetime_compare t one_year_ago < 0 then destroy_election uuid se
if datetime_compare t delete_t < 0 then destroy_election uuid se
else return_unit
| `Validated ((`Open | `Closed | `EncryptedTally _), dates) ->
let t = option_get dates.e_finalization default_validation_date in
if datetime_compare t one_year_ago < 0 then delete_election uuid
if datetime_compare t delete_t < 0 then delete_election uuid
else return_unit
| `Validated (`Archived, dates) ->
let t = option_get dates.e_archive default_archive_date in
if datetime_compare t one_year_ago < 0 then delete_election uuid
if datetime_compare t delete_t < 0 then delete_election uuid
else return_unit
| `Validated (`Tallied _, dates) ->
let t = option_get dates.e_tally default_tally_date in
if datetime_compare t one_week_ago < 0 then archive_election uuid
if datetime_compare t archive_t < 0 then archive_election uuid
else return_unit
let _ =
......
......@@ -1868,7 +1868,7 @@ let election_admin election metadata state get_tokens_decrypt () =
let%lwt archive_date = match state with
| `Tallied _ ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
let t = datetime_add (option_get t default_tally_date) (day 14) in
let t = datetime_add (option_get t default_tally_date) (day days_to_archive) in
return @@
div [
pcdata "This election will be automatically archived after ";
......@@ -1894,13 +1894,16 @@ let election_admin election metadata state get_tokens_decrypt () =
let%lwt deletion_date = match state with
| `Open | `Closed | `EncryptedTally _ ->
let%lwt t = Web_persist.get_election_date `Validation uuid in
return @@ datetime_add (option_get t default_validation_date) (day 365)
let dt = day days_to_delete in
return @@ datetime_add (option_get t default_validation_date) dt
| `Tallied _ ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
return @@ datetime_add (option_get t default_tally_date) (day 379)
let dt = day (days_to_archive + days_to_delete) in
return @@ datetime_add (option_get t default_tally_date) dt
| `Archived ->
let%lwt t = Web_persist.get_election_date `Archive uuid in
return @@ datetime_add (option_get t default_archive_date) (day 365)
let dt = day days_to_delete in
return @@ datetime_add (option_get t default_archive_date) dt
in
let div_delete =
div [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment