Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/crates_io_database/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ diesel::table! {
///
/// (Automatically generated by Diesel.)
token -> Text,
/// Point in time at which the invitation expires/expired.
expires_at -> Nullable<Timestamptz>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/crates_io_database_dump/src/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ invited_by_user_id = "private"
crate_id = "private"
created_at = "private"
token = "private"
expires_at = "private"

[crate_owners]
dependencies = ["crates", "users"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table crate_owner_invitations drop column expires_at;
7 changes: 7 additions & 0 deletions migrations/2025-02-11-122509_add-expires-at-column/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
alter table crate_owner_invitations add column expires_at timestamptz;

comment on column public.crate_owner_invitations.expires_at is 'Point in time at which the invitation expires/expired.'

-- to be performed manually after the migration:
--
-- update table crate_owner_invitations set expires_at = now() + interval '30 day';
4 changes: 3 additions & 1 deletion src/models/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{NaiveDateTime, Utc};
use chrono::{DateTime, NaiveDateTime, Utc};
use diesel::prelude::*;
use diesel_async::scoped_futures::ScopedFutureExt;
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
Expand All @@ -20,6 +20,7 @@ pub struct NewCrateOwnerInvitation {
pub invited_user_id: i32,
pub invited_by_user_id: i32,
pub crate_id: i32,
pub expires_at: DateTime<Utc>,
}

impl NewCrateOwnerInvitation {
Expand Down Expand Up @@ -82,6 +83,7 @@ pub struct CrateOwnerInvitation {
pub created_at: NaiveDateTime,
#[diesel(deserialize_as = String)]
pub token: SecretString,
pub expires_at: Option<DateTime<Utc>>,
}

impl CrateOwnerInvitation {
Expand Down
4 changes: 3 additions & 1 deletion src/models/krate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::NaiveDateTime;
use chrono::{NaiveDateTime, Utc};
use diesel::associations::Identifiable;
use diesel::dsl;
use diesel::pg::Pg;
Expand Down Expand Up @@ -401,10 +401,12 @@ impl Crate {
match owner {
// Users are invited and must accept before being added
Owner::User(user) => {
let expires_at = Utc::now() + app.config.ownership_invitations_expiration;
let invite = NewCrateOwnerInvitation {
invited_user_id: user.id,
invited_by_user_id: req_user.id,
crate_id: self.id,
expires_at,
};

let creation_ret = invite
Expand Down