[Draft] Implement Early deletion by Submitter #37 #38

Merged
ben merged 15 commits from ben/Jobboerse:main into main 2023-01-28 18:00:00 +01:00
11 changed files with 539 additions and 341 deletions
Showing only changes of commit a1c6b3b03b - Show all commits

update/upgrade dependencies

- and fix build afterwards
- fix generate_thirdparty.sh script
Bennet Bleßmann 2023-01-28 15:23:53 +01:00 committed by Bennet Bleßmann
Signed by: ben
GPG key ID: 3BE1A1A3CBC3CF99

791
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,33 +13,33 @@ readme = "README.md"
[workspace.dependencies] [workspace.dependencies]
actix-files = "0.6.2" actix-files = "0.6.2"
actix-web = "4.2.1" actix-web = "4.3.0"
actix-session = { version = "0.7.2", features = ["cookie-session"] } actix-session = { version = "0.7.2", features = ["cookie-session"] }
actix-multipart = "0.4.0" actix-multipart = "0.5.0"
better_toml_datetime = { path = "packages/better_toml_datetime" } better_toml_datetime = { path = "packages/better_toml_datetime" }
cargo-bundle-licenses = { version = "1.0.1", default-features = false } cargo-bundle-licenses = { version = "1.0.1", default-features = false }
chrono = { version = "0.4.22", default-features = false, features = ["std","clock"] } chrono = { version = "0.4.23", default-features = false, features = ["std","clock"] }
chrono-tz = "0.6.3" chrono-tz = "0.8.1"
clap = { version = "4.0.10", features = ["derive", "env"] } clap = { version = "4.1.4", features = ["derive", "env"] }
futures-util = "0.3.24" futures-util = "0.3.25"
handlebars = { version = "4.3.5", features = ["dir_source"] } handlebars = { version = "4.3.6", features = ["dir_source"] }
http = "0.2.8" http = "0.2.8"
lettre = { version = "0.10.1", default-features = false, features = ["sendmail-transport", "tokio1", "builder", "serde"] } lettre = { version = "0.10.1", default-features = false, features = ["sendmail-transport", "tokio1", "builder", "serde"] }
# use rustls a native tls library rather than openssl, # use rustls a native tls library rather than openssl,
# as depending on c dependencies can get annoying even when vendoring # as depending on c dependencies can get annoying even when vendoring
ldap3 = { version = "0.10.5", default-features = false, features = ["tls-rustls"] } ldap3 = { version = "0.11.1", default-features = false, features = ["tls-rustls"] }
listenfd = "1.0.0" listenfd = "1.0.0"
log = "0.4.17" log = "0.4.17"
mime_guess = "2.0.4" mime_guess = "2.0.4"
multipart_helper = {path = "packages/multipart_helper"} multipart_helper = {path = "packages/multipart_helper"}
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
rand = "0.8.5" rand = "0.8.5"
serde = { version = "1.0.145", features = ["derive"] } # https://doc.rust-lang.org/cargo/reference/manifest.html serde = { version = "1.0.152", features = ["derive"] } # https://doc.rust-lang.org/cargo/reference/manifest.html
serde_json = "1.0.85" serde_json = "1.0.91"
tempfile = "3.3.0" tempfile = "3.3.0"
thiserror = "1.0.37" thiserror = "1.0.38"
toml = "0.5.9" toml = "0.7.0"
tokio = "1.21.2" tokio = "1.24.2"
url = { version = "2.3.1", features = ["serde"] } url = { version = "2.3.1", features = ["serde"] }
[profile.release] [profile.release]

View file

@ -156,14 +156,14 @@ impl TryFrom<toml::value::Datetime> for Time {
#[derive(Clone, Debug, Hash)] #[derive(Clone, Debug, Hash)]
pub enum Offset { pub enum Offset {
Z, Z,
Custom { hours: i8, minutes: u8 }, Custom { minutes: i16 },
} }
impl From<toml::value::Offset> for Offset { impl From<toml::value::Offset> for Offset {
fn from(toml_offset: toml::value::Offset) -> Self { fn from(toml_offset: toml::value::Offset) -> Self {
match toml_offset { match toml_offset {
toml::value::Offset::Z => Self::Z, toml::value::Offset::Z => Self::Z,
toml::value::Offset::Custom { hours, minutes } => Self::Custom { hours, minutes }, toml::value::Offset::Custom { minutes } => Self::Custom { minutes },
} }
} }
} }
@ -172,7 +172,7 @@ impl From<Offset> for toml::value::Offset {
fn from(our_offset: Offset) -> Self { fn from(our_offset: Offset) -> Self {
match our_offset { match our_offset {
Offset::Z => Self::Z, Offset::Z => Self::Z,
Offset::Custom { hours, minutes } => Self::Custom { hours, minutes }, Offset::Custom { minutes } => Self::Custom { minutes },
} }
} }
} }

BIN
packages/jobboerse/THIRDPARTY.toml (Stored with Git LFS)

Binary file not shown.

View file

@ -411,13 +411,12 @@ impl JobOffer<PathBuf> {
.map(|date| toml_date_to_chrono_date(&date.0)) .map(|date| toml_date_to_chrono_date(&date.0))
.unwrap_or_else(|| { .unwrap_or_else(|| {
toml_datetime_to_chrono_datetime(&self.date_of_submission) toml_datetime_to_chrono_datetime(&self.date_of_submission)
.date()
.add(chrono::Duration::days(6 * 30)) .add(chrono::Duration::days(6 * 30))
}); });
use chrono::Offset as _; use chrono::Offset as _;
let now = crate::util::now(); let now = crate::util::now();
let now_date = now.with_timezone(&now.offset().fix()).date(); let now_date = now.with_timezone(&now.offset().fix());
now_date > expires_after now_date > expires_after
} }
@ -727,7 +726,7 @@ impl JobOffers {
Tz: TimeZone, Tz: TimeZone,
Tz::Offset: std::fmt::Display, Tz::Offset: std::fmt::Display,
{ {
let submission_date = submission_time.date().format("%Y-%m-%d").to_string(); let submission_date = submission_time.format("%F").to_string();
let seconds_since_midnight = submission_time.num_seconds_from_midnight(); let seconds_since_midnight = submission_time.num_seconds_from_midnight();
let guard = self.data.write().await; let guard = self.data.write().await;
@ -960,7 +959,7 @@ mod test {
println!("{}", serialized); println!("{}", serialized);
toml::de::from_str::<'_, JobOfferStatus>(&serialized).expect_err( toml::de::from_str::<JobOfferStatus>(&serialized).expect_err(
"V1 should not parse as current, this will prevent migration from applying", "V1 should not parse as current, this will prevent migration from applying",
); );
} }

View file

@ -175,7 +175,7 @@ fn base<'a>(
banner: config.config.banner.clone(), banner: config.config.banner.clone(),
operation_mode: config.args.mode.clone(), operation_mode: config.args.mode.clone(),
dev_build: dev_available, dev_build: dev_available,
date: crate::util::now().date().format("%F").to_string(), date: crate::util::now().format("%F").to_string(),
}; };
Ok(data) Ok(data)

View file

@ -436,7 +436,7 @@ impl JobOfferSubmitForm {
} }
name => { name => {
warn!( warn!(
"Unknown field `{}` in multipart form: {}", "Unknown field `{}` in multipart form: {:?}",
name, name,
field.content_type() field.content_type()
); );

View file

@ -417,7 +417,7 @@ impl JobOfferEditForm {
} }
name => { name => {
warn!( warn!(
"Unknown field `{}` in multipart form: {}", "Unknown field `{}` in multipart form: {:?}",
name, name,
field.content_type() field.content_type()
); );

View file

@ -284,4 +284,3 @@ pub(crate) enum FormProcessingError {
#[error("invalid hash")] #[error("invalid hash")]
InvalidHash, InvalidHash,
} }

View file

@ -1,6 +1,6 @@
use crate::job_offers::{Attachment, Link}; use crate::job_offers::{Attachment, Link};
use better_toml_datetime::Offset; use better_toml_datetime::Offset;
use chrono::{DateTime, FixedOffset, NaiveDate, Offset as _, TimeZone, Utc}; use chrono::{DateTime, FixedOffset, NaiveDate, NaiveTime, Offset as _, TimeZone, Utc};
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use std::str::FromStr; use std::str::FromStr;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
@ -20,7 +20,6 @@ pub fn chrono_datetime_to_toml_datetime<Tz: chrono::TimeZone>(
let offset_seconds = datetime.offset().fix().local_minus_utc(); let offset_seconds = datetime.offset().fix().local_minus_utc();
let offset_minutes = offset_seconds / 60; let offset_minutes = offset_seconds / 60;
let offset_hours = offset_minutes / 60;
toml::value::Datetime { toml::value::Datetime {
date: Some(toml::value::Date { date: Some(toml::value::Date {
@ -53,25 +52,22 @@ pub fn chrono_datetime_to_toml_datetime<Tz: chrono::TimeZone>(
nanosecond: datetime.nanosecond(), nanosecond: datetime.nanosecond(),
}), }),
offset: Some(toml::value::Offset::Custom { offset: Some(toml::value::Offset::Custom {
hours: offset_hours.try_into().expect( minutes: offset_minutes as i16,
"the hours of the offset should be in the range -12 to 12 and as such fit in an i8",
),
minutes: (offset_minutes % 60).abs().try_into().expect(
"the minutes of the offset should be in the range 0 to 59 and as such fit in an i8",
// especially since we have a % 60 and abs() here
),
}), }),
} }
.into() .into()
} }
pub fn toml_date_to_chrono_date(date: &toml::value::Date) -> chrono::Date<FixedOffset> { pub fn toml_date_to_chrono_date(date: &toml::value::Date) -> chrono::DateTime<FixedOffset> {
let local_date = NaiveDate::from_ymd(date.year.into(), date.month.into(), date.day.into()); let local_date =
NaiveDate::from_ymd_opt(date.year.into(), date.month.into(), date.day.into()).unwrap();
let offset = chrono_tz::Europe::Berlin let offset = chrono_tz::Europe::Berlin
.offset_from_local_date(&local_date) .offset_from_local_date(&local_date)
.map(|offset| offset.fix()) .map(|offset| offset.fix())
.unwrap(); .unwrap();
offset.from_local_date(&local_date).unwrap() offset
.from_local_datetime(&local_date.and_time(NaiveTime::default()))
.unwrap()
} }
pub fn toml_datetime_to_chrono_datetime( pub fn toml_datetime_to_chrono_datetime(
@ -91,32 +87,28 @@ pub fn toml_datetime_to_chrono_datetime(
.into() .into()
}); });
let local_datetime = chrono::NaiveDate::from_ymd( let local_datetime = chrono::NaiveDate::from_ymd_opt(
toml_date.year.into(), toml_date.year.into(),
toml_date.month.into(), toml_date.month.into(),
toml_date.day.into(), toml_date.day.into(),
) )
.and_hms_nano( .unwrap()
.and_hms_nano_opt(
toml_time.hour.into(), toml_time.hour.into(),
toml_time.minute.into(), toml_time.minute.into(),
toml_time.second.into(), toml_time.second.into(),
toml_time.nanosecond, toml_time.nanosecond,
); )
.unwrap();
let offset: FixedOffset = datetime let offset: FixedOffset = datetime
.offset .offset
.as_ref() .as_ref()
.map(|offset| match offset { .map(|offset| match offset {
Offset::Z => 0, Offset::Z => 0,
Offset::Custom { hours, minutes } => { Offset::Custom { minutes } => *minutes as i32 * 60,
let hours: i32 = (*hours).into();
let minutes: i32 = (*minutes).into();
let offset_in_minutes = 60 * hours + hours.signum() * minutes;
offset_in_minutes * 60
}
}) })
.map(FixedOffset::east) .and_then(|sec_offset| FixedOffset::east_opt(sec_offset))
.unwrap_or_else(|| { .unwrap_or_else(|| {
// try to interpret timestamp as local Europe/Berlin time // try to interpret timestamp as local Europe/Berlin time
let tz_result = chrono_tz::Europe::Berlin let tz_result = chrono_tz::Europe::Berlin

View file

@ -1,4 +1,13 @@
#!/bin/bash #!/bin/bash
DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
OUT="${DIR}/../packages/jobboerse/THIRDPARTY.toml"
RUN_DIR="${DIR}/../packages/jobboerse"
cargo bundle-licenses --format toml --output packages/jobboerse/THIRDPARTY.toml pushd "${RUN_DIR}"
cargo bundle-licenses \
--format toml \
--output "${OUT}"
popd