diff --git a/src/db/model/issue.rs b/src/db/model/issue.rs index 1ee222762f8a0..6268412bee750 100644 --- a/src/db/model/issue.rs +++ b/src/db/model/issue.rs @@ -8,7 +8,7 @@ pub struct Model { #[sea_orm(column_type = "Uuid", indexed)] pub page: Uuid, #[sea_orm(column_type = "Timestamp")] - pub found_at: DateTimeUtc, + pub found_at: DateTime, #[sea_orm(column_type = "String(None)", indexed)] pub issue_type: String, #[sea_orm(column_type = "JsonBinary")] diff --git a/src/db/model/page.rs b/src/db/model/page.rs index f312272f21792..34900395714c0 100644 --- a/src/db/model/page.rs +++ b/src/db/model/page.rs @@ -10,9 +10,9 @@ pub struct Model { #[sea_orm(column_type = "String(Some(255))")] pub title: String, #[sea_orm(column_type = "Timestamp")] - pub last_checked: DateTimeUtc, + pub last_checked: DateTime, #[sea_orm(column_type = "Timestamp", nullable, default_value = "None")] - pub need_check: Option, + pub need_check: Option, #[sea_orm(column_type = "Unsigned", default_value = "0")] pub check_errors: u32, #[sea_orm(column_type = "Unsigned", default_value = "0")] diff --git a/src/db/model/rcsyncer.rs b/src/db/model/rcsyncer.rs index 68c8acd323e4c..1b009e29ebaf6 100644 --- a/src/db/model/rcsyncer.rs +++ b/src/db/model/rcsyncer.rs @@ -6,7 +6,7 @@ pub struct Model { #[sea_orm(primary_key, auto_increment = false, unique, indexed)] pub id: Uuid, #[sea_orm(column_type = "Timestamp")] - pub last_synced_at: DateTimeUtc, + pub last_synced_at: DateTime, #[sea_orm(column_type = "Unsigned", default_value = 0)] pub last_rc_id: u32, } diff --git a/src/db/model/user.rs b/src/db/model/user.rs index 28af79fe44db7..cb5296a3bface 100644 --- a/src/db/model/user.rs +++ b/src/db/model/user.rs @@ -16,7 +16,7 @@ pub struct Model { #[sea_orm(column_type = "Boolean", default_value = "false")] pub sysop: bool, #[sea_orm(column_type = "Timestamp", nullable, default_value = "None")] - pub blocked: Option, + pub blocked: Option, } impl Display for Model { diff --git a/src/page.rs b/src/page.rs index 291c403f7514e..df66a7d4285e1 100644 --- a/src/page.rs +++ b/src/page.rs @@ -90,7 +90,7 @@ impl Page { id: ActiveValue::Set(Self::get_page_id(lang, title)), lang: ActiveValue::Set(lang.to_owned()), title: ActiveValue::Set(title.to_owned()), - need_check: ActiveValue::Set(Some(Utc::now())), + need_check: ActiveValue::Set(Some(Utc::now().naive_utc())), ..Default::default() }; Ok(Some(Self(new.insert(&*db::get()).await?))) @@ -110,15 +110,15 @@ impl Page { } pub fn last_checked(&self) -> Option> { - if self.0.last_checked == DateTime::UNIX_EPOCH { + if self.0.last_checked.and_utc() == DateTime::UNIX_EPOCH { None } else { - Some(self.0.last_checked.to_owned()) + Some(self.0.last_checked.and_utc()) } } pub fn check_requested_time(&self) -> Option> { - self.0.need_check.map(|t|t) + self.0.need_check.map(|ts| ts.and_utc()) } pub fn check_errors(&self) -> u32 { @@ -135,7 +135,7 @@ impl Page { pub async fn mark_check(self) -> Result<()> { let mut model = self.0.into_active_model(); - model.need_check = ActiveValue::Set(Some(Utc::now())); + model.need_check = ActiveValue::Set(Some(Utc::now().naive_utc())); model.check_errors = ActiveValue::Set(0); model.update(&*db::get()).await?; App::get().linter_notify.notify_one(); @@ -168,7 +168,7 @@ impl Page { false }; let mut model = self.0.into_active_model(); - model.last_checked = ActiveValue::Set(Utc::now()); + model.last_checked = ActiveValue::Set(Utc::now().naive_utc()); if !drop_result { model.need_check = ActiveValue::Set(None); } @@ -180,7 +180,7 @@ impl Page { } pub async fn defer_check(self) -> Result<()> { - let check_time = self.check_requested_time(); + let check_time = self.check_requested_time().map(|ts| ts.naive_utc()); let check_errors = self.check_errors(); let mut model = self.0.into_active_model(); model.need_check = ActiveValue::Set(Some( @@ -202,7 +202,7 @@ impl Page { info!("marking all pages for check"); db::page::Entity::update_many() .set(db::page::ActiveModel { - need_check: ActiveValue::Set(Some(Utc::now())), + need_check: ActiveValue::Set(Some(Utc::now().naive_utc())), ..Default::default() }) .exec(&*db::get()) diff --git a/src/rcsyncer.rs b/src/rcsyncer.rs index 7b0bc328027cc..d45e6b1abfab1 100644 --- a/src/rcsyncer.rs +++ b/src/rcsyncer.rs @@ -50,7 +50,7 @@ impl RcSyncerState { } else { let new = db::rcsyncer::ActiveModel { id: ActiveValue::Set(Page::get_lang_id(lang)), - last_synced_at: ActiveValue::Set(Utc::now()), + last_synced_at: ActiveValue::Set(Utc::now().naive_utc()), last_rc_id: ActiveValue::Set(0), }; Ok(Self(new.insert(&*db::get()).await?)) @@ -61,8 +61,8 @@ impl RcSyncerState { &self.0.id } - pub fn last_synced_at(&self) -> &DateTime { - &self.0.last_synced_at + pub fn last_synced_at(&self) -> DateTime { + self.0.last_synced_at.and_utc() } pub fn last_rc_id(&self) -> u32 { @@ -122,7 +122,7 @@ pub async fn sync_rc(lang: &str) -> Result<()> { } let mut state = state.0.into_active_model(); - state.last_synced_at = ActiveValue::Set(end_time); + state.last_synced_at = ActiveValue::Set(end_time.naive_utc()); state.last_rc_id = ActiveValue::Set(last_rcid); state.update(&*db::get()).await?; diff --git a/src/web/auth.rs b/src/web/auth.rs index 64a97b70d118b..8d5d51f079e3a 100644 --- a/src/web/auth.rs +++ b/src/web/auth.rs @@ -161,7 +161,7 @@ async fn auth_handler(auth: AuthResult, Query(params): Query) -> Web } }; if let Some(blocked) = user.blocked { - if blocked <= Utc::now() { + if blocked.and_utc() <= Utc::now() { user = { let mut model = user.into_active_model(); model.blocked = ActiveValue::Set(None); @@ -195,7 +195,7 @@ async fn auth_handler(auth: AuthResult, Query(params): Query) -> Web title: "Login Blocked", message: &format!( "You are blocked until {}", - blocked.to_rfc3339_opts(chrono::SecondsFormat::Secs, true) + blocked.and_utc().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) ), auto_return: false, }, @@ -233,7 +233,7 @@ pub async fn login(token: &str) -> Option { && validate_token(&user.salt, token) { if let Some(blocked) = user.blocked { - if blocked <= Utc::now() { + if blocked.and_utc() <= Utc::now() { let mut user = user.into_active_model(); user.blocked = ActiveValue::Set(None); match user.update(&*db::get()).await { diff --git a/src/web/user.rs b/src/web/user.rs index 4cc5e1b4912b0..0a5ae64cada7a 100644 --- a/src/web/user.rs +++ b/src/web/user.rs @@ -91,7 +91,7 @@ async fn get_user_handler(auth: AuthResult, Path(id): Path) -> WebResult let is_blocked = user.blocked.is_some(); let is_permanent_block = user .blocked - .map(|t| t == DateTime::::MAX_UTC) + .map(|t| t == DateTime::::MAX_UTC.naive_utc()) .unwrap_or(false); return Ok(InfoPage { auth, @@ -196,7 +196,7 @@ async fn block_handler( let time = params.time; info!(target = %user, user = %auth, %time, "block user"); let mut user = user.into_active_model(); - user.blocked = ActiveValue::Set(Some(Utc::now() + time)); + user.blocked = ActiveValue::Set(Some(Utc::now().naive_utc() + time)); let user = user.update(&*db::get()).await?; App::get().login_lru.write().clear(); Ok(MessagePage { @@ -220,7 +220,7 @@ async fn permanent_block_handler( )?; info!(target = %user, user = %auth, "permanently block user"); let mut user = user.into_active_model(); - user.blocked = ActiveValue::Set(Some(DateTime::::MAX_UTC)); + user.blocked = ActiveValue::Set(Some(DateTime::::MAX_UTC.naive_utc())); let user = user.update(&*db::get()).await?; App::get().login_lru.write().clear(); Ok(MessagePage { diff --git a/templates/sysop/rcsyncer.html b/templates/sysop/rcsyncer.html index c88582adae89a..4a0b4c931df0b 100644 --- a/templates/sysop/rcsyncer.html +++ b/templates/sysop/rcsyncer.html @@ -22,7 +22,7 @@ {{ lang }} {{ state.id }} - {{ state.last_synced_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true) }} + {{ state.last_synced_at.and_utc().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) }} {{ state.last_rc_id }} {%- endfor %} diff --git a/templates/user.html b/templates/user.html index cbf46e72cbb04..7671b60bce491 100644 --- a/templates/user.html +++ b/templates/user.html @@ -8,7 +8,7 @@

{{ user.name }}

{{ user.id }}

{%- if let Some(until) = user.blocked -%} -

This user has been blocked until {{ until.to_rfc3339_opts(chrono::SecondsFormat::Secs, true) }}

+

This user has been blocked until {{ until.and_utc().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) }}

{%- endif -%}