Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9dc37eb

Browse files
committedDec 14, 2019
Add token for crate owner invitation email
Adds a token to the crate_owner_invitations table to be used in token-based acceptance of invitation via email.
1 parent 55fa81b commit 9dc37eb

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE crate_owner_invitations DROP COLUMN token;
2+
ALTER TABLE crate_owner_invitations DROP COLUMN token_generated_at;
3+
DROP FUNCTION crate_owner_invitations_set_token_generated_at();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ALTER TABLE crate_owner_invitations ADD COLUMN token TEXT NOT NULL DEFAULT random_string(26);
2+
ALTER TABLE crate_owner_invitations ADD COLUMN token_generated_at TIMESTAMP;
3+
4+
CREATE FUNCTION crate_owner_invitations_set_token_generated_at() RETURNS trigger AS $$
5+
BEGIN
6+
NEW.token_generated_at := CURRENT_TIMESTAMP;
7+
RETURN NEW;
8+
END
9+
$$ LANGUAGE plpgsql;
10+
11+
CREATE TRIGGER trigger_crate_owner_invitations_set_token_generated_at BEFORE
12+
INSERT OR UPDATE OF token ON crate_owner_invitations
13+
FOR EACH ROW EXECUTE PROCEDURE crate_owner_invitations_set_token_generated_at();

Diff for: ‎src/models/crate_owner_invitation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ use crate::schema::{crate_owner_invitations, crates, users};
55
use crate::views::EncodableCrateOwnerInvitation;
66

77
/// The model representing a row in the `crate_owner_invitations` database table.
8-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Identifiable, Queryable)]
8+
#[derive(Clone, Debug, PartialEq, Eq, Identifiable, Queryable)]
99
#[primary_key(invited_user_id, crate_id)]
1010
pub struct CrateOwnerInvitation {
1111
pub invited_user_id: i32,
1212
pub invited_by_user_id: i32,
1313
pub crate_id: i32,
1414
pub created_at: NaiveDateTime,
15+
pub token: String,
16+
pub token_created_at: Option<NaiveDateTime>,
1517
}
1618

1719
#[derive(Insertable, Clone, Copy, Debug)]

Diff for: ‎src/schema.rs

+12
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ table! {
208208
///
209209
/// (Automatically generated by Diesel.)
210210
created_at -> Timestamp,
211+
/// The `token` column of the `crate_owner_invitations` table.
212+
///
213+
/// Its SQL type is `Text`.
214+
///
215+
/// (Automatically generated by Diesel.)
216+
token -> Text,
217+
/// The `token_generated_at` column of the `crate_owner_invitations` table.
218+
///
219+
/// Its SQL type is `Nullable<Timestamp>`.
220+
///
221+
/// (Automatically generated by Diesel.)
222+
token_generated_at -> Nullable<Timestamp>,
211223
}
212224
}
213225

Diff for: ‎src/tasks/dump_db/dump-db.toml

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ invited_user_id = "private"
5656
invited_by_user_id = "private"
5757
crate_id = "private"
5858
created_at = "private"
59+
token = "private"
60+
token_generated_at = "private"
5961

6062
[crate_owners]
6163
dependencies = ["crates", "users"]

0 commit comments

Comments
 (0)
Please sign in to comment.