From 2e35f3608ba34ae23b6f5a42f26ac4f5086d1887 Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Fri, 6 Sep 2024 20:16:28 -0700 Subject: [PATCH] Remove name field (and remove existing data) (#935) * Remove name field (and remove existing data) * run prep, fmt * fix dummy data --- ...f742ae3921c1f2067723ff13f06328debee3e.json | 32 ++++++++++++ ...8d821cd5ff22eb4e39b9dd7f198c9113d4f87.json | 15 ------ ...e1866ec395146d5dabe071a13baa55ec3c09.json} | 52 ++++++++----------- ...f608166e1fa1f4ce5f655849874858d5f9e27.json | 33 ------------ .../20240701213559_remove-user-names.sql | 1 + src/auth/validate.rs | 1 - src/database/models/user_item.rs | 9 ++-- src/models/v2/user.rs | 2 +- src/models/v3/users.rs | 2 - src/routes/internal/billing.rs | 2 +- src/routes/internal/flows.rs | 19 +------ src/routes/v2/users.rs | 1 - src/routes/v3/users.rs | 21 -------- tests/files/dummy_data.sql | 10 ++-- 14 files changed, 67 insertions(+), 133 deletions(-) create mode 100644 .sqlx/query-55f7a2e7fa37697bbcd7031b2bff742ae3921c1f2067723ff13f06328debee3e.json delete mode 100644 .sqlx/query-5eb2795d25d6d03e22564048c198d821cd5ff22eb4e39b9dd7f198c9113d4f87.json rename .sqlx/{query-6a0ca2045bd91a27dce32c730cb5238527ec210f20de13bd8995885159c6d277.json => query-93b8fff7ebe72e55e34e98bd365fe1866ec395146d5dabe071a13baa55ec3c09.json} (78%) delete mode 100644 .sqlx/query-c33fb3503d040fd91a049b10853f608166e1fa1f4ce5f655849874858d5f9e27.json create mode 100644 migrations/20240701213559_remove-user-names.sql diff --git a/.sqlx/query-55f7a2e7fa37697bbcd7031b2bff742ae3921c1f2067723ff13f06328debee3e.json b/.sqlx/query-55f7a2e7fa37697bbcd7031b2bff742ae3921c1f2067723ff13f06328debee3e.json new file mode 100644 index 00000000..c55c2c37 --- /dev/null +++ b/.sqlx/query-55f7a2e7fa37697bbcd7031b2bff742ae3921c1f2067723ff13f06328debee3e.json @@ -0,0 +1,32 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO users (\n id, username, email,\n avatar_url, bio, created,\n github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id,\n email_verified, password, paypal_id, paypal_country, paypal_email,\n venmo_handle, stripe_customer_id\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7,\n $8, $9, $10, $11, $12, $13,\n $14, $15, $16, $17, $18, $19\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz", + "Int8", + "Int8", + "Int8", + "Varchar", + "Int8", + "Varchar", + "Bool", + "Text", + "Text", + "Text", + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "55f7a2e7fa37697bbcd7031b2bff742ae3921c1f2067723ff13f06328debee3e" +} diff --git a/.sqlx/query-5eb2795d25d6d03e22564048c198d821cd5ff22eb4e39b9dd7f198c9113d4f87.json b/.sqlx/query-5eb2795d25d6d03e22564048c198d821cd5ff22eb4e39b9dd7f198c9113d4f87.json deleted file mode 100644 index 5994da73..00000000 --- a/.sqlx/query-5eb2795d25d6d03e22564048c198d821cd5ff22eb4e39b9dd7f198c9113d4f87.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE users\n SET name = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "5eb2795d25d6d03e22564048c198d821cd5ff22eb4e39b9dd7f198c9113d4f87" -} diff --git a/.sqlx/query-6a0ca2045bd91a27dce32c730cb5238527ec210f20de13bd8995885159c6d277.json b/.sqlx/query-93b8fff7ebe72e55e34e98bd365fe1866ec395146d5dabe071a13baa55ec3c09.json similarity index 78% rename from .sqlx/query-6a0ca2045bd91a27dce32c730cb5238527ec210f20de13bd8995885159c6d277.json rename to .sqlx/query-93b8fff7ebe72e55e34e98bd365fe1866ec395146d5dabe071a13baa55ec3c09.json index 759630e8..0589b26b 100644 --- a/.sqlx/query-6a0ca2045bd91a27dce32c730cb5238527ec210f20de13bd8995885159c6d277.json +++ b/.sqlx/query-93b8fff7ebe72e55e34e98bd365fe1866ec395146d5dabe071a13baa55ec3c09.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT id, name, email,\n avatar_url, username, bio,\n created, role, badges,\n balance,\n github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id,\n email_verified, password, totp_secret, paypal_id, paypal_country, paypal_email,\n venmo_handle, stripe_customer_id\n FROM users\n WHERE id = ANY($1) OR LOWER(username) = ANY($2)\n ", + "query": "\n SELECT id, email,\n avatar_url, username, bio,\n created, role, badges,\n balance,\n github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id,\n email_verified, password, totp_secret, paypal_id, paypal_country, paypal_email,\n venmo_handle, stripe_customer_id\n FROM users\n WHERE id = ANY($1) OR LOWER(username) = ANY($2)\n ", "describe": { "columns": [ { @@ -10,116 +10,111 @@ }, { "ordinal": 1, - "name": "name", - "type_info": "Varchar" - }, - { - "ordinal": 2, "name": "email", "type_info": "Varchar" }, { - "ordinal": 3, + "ordinal": 2, "name": "avatar_url", "type_info": "Varchar" }, { - "ordinal": 4, + "ordinal": 3, "name": "username", "type_info": "Varchar" }, { - "ordinal": 5, + "ordinal": 4, "name": "bio", "type_info": "Varchar" }, { - "ordinal": 6, + "ordinal": 5, "name": "created", "type_info": "Timestamptz" }, { - "ordinal": 7, + "ordinal": 6, "name": "role", "type_info": "Varchar" }, { - "ordinal": 8, + "ordinal": 7, "name": "badges", "type_info": "Int8" }, { - "ordinal": 9, + "ordinal": 8, "name": "balance", "type_info": "Numeric" }, { - "ordinal": 10, + "ordinal": 9, "name": "github_id", "type_info": "Int8" }, { - "ordinal": 11, + "ordinal": 10, "name": "discord_id", "type_info": "Int8" }, { - "ordinal": 12, + "ordinal": 11, "name": "gitlab_id", "type_info": "Int8" }, { - "ordinal": 13, + "ordinal": 12, "name": "google_id", "type_info": "Varchar" }, { - "ordinal": 14, + "ordinal": 13, "name": "steam_id", "type_info": "Int8" }, { - "ordinal": 15, + "ordinal": 14, "name": "microsoft_id", "type_info": "Varchar" }, { - "ordinal": 16, + "ordinal": 15, "name": "email_verified", "type_info": "Bool" }, { - "ordinal": 17, + "ordinal": 16, "name": "password", "type_info": "Text" }, { - "ordinal": 18, + "ordinal": 17, "name": "totp_secret", "type_info": "Varchar" }, { - "ordinal": 19, + "ordinal": 18, "name": "paypal_id", "type_info": "Text" }, { - "ordinal": 20, + "ordinal": 19, "name": "paypal_country", "type_info": "Text" }, { - "ordinal": 21, + "ordinal": 20, "name": "paypal_email", "type_info": "Text" }, { - "ordinal": 22, + "ordinal": 21, "name": "venmo_handle", "type_info": "Text" }, { - "ordinal": 23, + "ordinal": 22, "name": "stripe_customer_id", "type_info": "Text" } @@ -134,7 +129,6 @@ false, true, true, - true, false, true, false, @@ -157,5 +151,5 @@ true ] }, - "hash": "6a0ca2045bd91a27dce32c730cb5238527ec210f20de13bd8995885159c6d277" + "hash": "93b8fff7ebe72e55e34e98bd365fe1866ec395146d5dabe071a13baa55ec3c09" } diff --git a/.sqlx/query-c33fb3503d040fd91a049b10853f608166e1fa1f4ce5f655849874858d5f9e27.json b/.sqlx/query-c33fb3503d040fd91a049b10853f608166e1fa1f4ce5f655849874858d5f9e27.json deleted file mode 100644 index da480468..00000000 --- a/.sqlx/query-c33fb3503d040fd91a049b10853f608166e1fa1f4ce5f655849874858d5f9e27.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO users (\n id, username, name, email,\n avatar_url, bio, created,\n github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id,\n email_verified, password, paypal_id, paypal_country, paypal_email,\n venmo_handle, stripe_customer_id\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7,\n $8, $9, $10, $11, $12, $13,\n $14, $15, $16, $17, $18, $19, $20\n )\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Timestamptz", - "Int8", - "Int8", - "Int8", - "Varchar", - "Int8", - "Varchar", - "Bool", - "Text", - "Text", - "Text", - "Text", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "c33fb3503d040fd91a049b10853f608166e1fa1f4ce5f655849874858d5f9e27" -} diff --git a/migrations/20240701213559_remove-user-names.sql b/migrations/20240701213559_remove-user-names.sql new file mode 100644 index 00000000..e44cbb56 --- /dev/null +++ b/migrations/20240701213559_remove-user-names.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN name; \ No newline at end of file diff --git a/src/auth/validate.rs b/src/auth/validate.rs index bf0f1893..4f13af33 100644 --- a/src/auth/validate.rs +++ b/src/auth/validate.rs @@ -51,7 +51,6 @@ where let user = User { id: UserId::from(db_user.id), username: db_user.username, - name: db_user.name, email: db_user.email, email_verified: Some(db_user.email_verified), avatar_url: db_user.avatar_url, diff --git a/src/database/models/user_item.rs b/src/database/models/user_item.rs index ae22907d..45efee74 100644 --- a/src/database/models/user_item.rs +++ b/src/database/models/user_item.rs @@ -37,7 +37,6 @@ pub struct User { pub totp_secret: Option, pub username: String, - pub name: Option, pub email: Option, pub email_verified: bool, pub avatar_url: Option, @@ -57,7 +56,7 @@ impl User { sqlx::query!( " INSERT INTO users ( - id, username, name, email, + id, username, email, avatar_url, bio, created, github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id, email_verified, password, paypal_id, paypal_country, paypal_email, @@ -67,12 +66,11 @@ impl User { $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, - $14, $15, $16, $17, $18, $19, $20 + $14, $15, $16, $17, $18, $19 ) ", self.id as UserId, &self.username, - self.name.as_ref(), self.email.as_ref(), self.avatar_url.as_ref(), self.bio.as_ref(), @@ -166,7 +164,7 @@ impl User { let users = sqlx::query!( " - SELECT id, name, email, + SELECT id, email, avatar_url, username, bio, created, role, badges, balance, @@ -189,7 +187,6 @@ impl User { google_id: u.google_id, steam_id: u.steam_id, microsoft_id: u.microsoft_id, - name: u.name, email: u.email, email_verified: u.email_verified, avatar_url: u.avatar_url, diff --git a/src/models/v2/user.rs b/src/models/v2/user.rs index cea8c18d..cc5c6d63 100644 --- a/src/models/v2/user.rs +++ b/src/models/v2/user.rs @@ -35,7 +35,7 @@ impl From for LegacyUser { Self { id: data.id, username: data.username, - name: data.name, + name: None, email: data.email, email_verified: data.email_verified, avatar_url: data.avatar_url, diff --git a/src/models/v3/users.rs b/src/models/v3/users.rs index 64be5405..790d14fe 100644 --- a/src/models/v3/users.rs +++ b/src/models/v3/users.rs @@ -39,7 +39,6 @@ impl Default for Badges { pub struct User { pub id: UserId, pub username: String, - pub name: Option, pub avatar_url: Option, pub bio: Option, pub created: DateTime, @@ -73,7 +72,6 @@ impl From for User { Self { id: data.id.into(), username: data.username, - name: data.name, email: None, email_verified: None, avatar_url: data.avatar_url, diff --git a/src/routes/internal/billing.rs b/src/routes/internal/billing.rs index 57a15956..877a5da8 100644 --- a/src/routes/internal/billing.rs +++ b/src/routes/internal/billing.rs @@ -999,7 +999,7 @@ pub async fn stripe_webhook( let price = match metadata.product_price.prices { Price::OneTime { price } => Some(price), Price::Recurring { intervals } => { - if let Some((subscription_id, interval)) = + if let Some((_subscription_id, interval)) = metadata.user_subscription_data { if let Some(mut user_subscription) = metadata.user_subscription { diff --git a/src/routes/internal/flows.rs b/src/routes/internal/flows.rs index d889d1a4..edf8f5b6 100644 --- a/src/routes/internal/flows.rs +++ b/src/routes/internal/flows.rs @@ -65,7 +65,6 @@ pub struct TempUser { pub avatar_url: Option, pub bio: Option, - pub name: Option, pub country: Option, } @@ -221,7 +220,6 @@ impl TempUser { stripe_customer_id: None, totp_secret: None, username, - name: self.name, email: self.email, email_verified: true, avatar_url, @@ -578,7 +576,6 @@ impl AuthProvider { email: github_user.email, avatar_url: Some(github_user.avatar_url), bio: github_user.bio, - name: github_user.name, country: None, } } @@ -610,7 +607,6 @@ impl AuthProvider { .avatar .map(|x| format!("https://cdn.discordapp.com/avatars/{}/{}.webp", id, x)), bio: None, - name: discord_user.global_name, country: None, } } @@ -619,7 +615,6 @@ impl AuthProvider { #[serde(rename_all = "camelCase")] pub struct MicrosoftUser { pub id: String, - pub display_name: Option, pub mail: Option, pub user_principal_name: String, } @@ -642,7 +637,6 @@ impl AuthProvider { email: microsoft_user.mail, avatar_url: None, bio: None, - name: microsoft_user.display_name, country: None, } } @@ -672,7 +666,6 @@ impl AuthProvider { email: gitlab_user.email, avatar_url: gitlab_user.avatar_url, bio: gitlab_user.bio, - name: gitlab_user.name, country: None, } } @@ -681,7 +674,6 @@ impl AuthProvider { pub struct GoogleUser { pub id: String, pub email: String, - pub name: Option, pub picture: Option, } @@ -705,7 +697,6 @@ impl AuthProvider { email: Some(google_user.email), avatar_url: google_user.picture, bio: None, - name: google_user.name, country: None, } } @@ -725,7 +716,6 @@ impl AuthProvider { #[derive(Deserialize)] struct Player { steamid: String, - personaname: String, profileurl: String, avatar: Option, } @@ -757,7 +747,6 @@ impl AuthProvider { email: None, avatar_url: player.avatar, bio: None, - name: Some(player.personaname), country: None, } } else { @@ -802,7 +791,6 @@ impl AuthProvider { email: Some(paypal_user.email), avatar_url: paypal_user.picture, bio: None, - name: None, country: Some(paypal_user.address.country), } } @@ -1527,7 +1515,6 @@ pub async fn create_account_with_password( stripe_customer_id: None, totp_secret: None, username: new_account.username.clone(), - name: Some(new_account.username), email: Some(new_account.email.clone()), email_verified: false, avatar_url: None, @@ -2068,11 +2055,7 @@ pub async fn change_password( let update_password = if let Some(new_password) = &change_password.new_password { let score = zxcvbn::zxcvbn( new_password, - &[ - &user.username, - &user.email.clone().unwrap_or_default(), - &user.name.unwrap_or_default(), - ], + &[&user.username, &user.email.clone().unwrap_or_default()], )?; if score.score() < 3 { diff --git a/src/routes/v2/users.rs b/src/routes/v2/users.rs index cf747c79..5835f6ff 100644 --- a/src/routes/v2/users.rs +++ b/src/routes/v2/users.rs @@ -163,7 +163,6 @@ pub async fn user_edit( info, web::Json(v3::users::EditUser { username: new_user.username, - name: new_user.name, bio: new_user.bio, role: new_user.role, badges: new_user.badges, diff --git a/src/routes/v3/users.rs b/src/routes/v3/users.rs index 4b7702dd..a3f611f3 100644 --- a/src/routes/v3/users.rs +++ b/src/routes/v3/users.rs @@ -274,13 +274,6 @@ pub struct EditUser { skip_serializing_if = "Option::is_none", with = "::serde_with::rust::double_option" )] - #[validate(length(min = 1, max = 64), regex = "RE_URL_SAFE")] - pub name: Option>, - #[serde( - default, - skip_serializing_if = "Option::is_none", - with = "::serde_with::rust::double_option" - )] #[validate(length(max = 160))] pub bio: Option>, pub role: Option, @@ -345,20 +338,6 @@ pub async fn user_edit( } } - if let Some(name) = &new_user.name { - sqlx::query!( - " - UPDATE users - SET name = $1 - WHERE (id = $2) - ", - name.as_deref(), - id as crate::database::models::ids::UserId, - ) - .execute(&mut *transaction) - .await?; - } - if let Some(bio) = &new_user.bio { sqlx::query!( " diff --git a/tests/files/dummy_data.sql b/tests/files/dummy_data.sql index 457353d3..f3fb1e47 100644 --- a/tests/files/dummy_data.sql +++ b/tests/files/dummy_data.sql @@ -4,11 +4,11 @@ -- Inserts 5 dummy users for testing, with slight differences -- 'Friend' and 'enemy' function like 'user', but we can use them to simulate 'other' users that may or may not be able to access certain things -- IDs 1-5, 1-5 -INSERT INTO users (id, username, name, email, role) VALUES (1, 'Admin', 'Administrator Test', 'admin@modrinth.com', 'admin'); -INSERT INTO users (id, username, name, email, role) VALUES (2, 'Moderator', 'Moderator Test', 'moderator@modrinth.com', 'moderator'); -INSERT INTO users (id, username, name, email, role) VALUES (3, 'User', 'User Test', 'user@modrinth.com', 'developer'); -INSERT INTO users (id, username, name, email, role) VALUES (4, 'Friend', 'Friend Test', 'friend@modrinth.com', 'developer'); -INSERT INTO users (id, username, name, email, role) VALUES (5, 'Enemy', 'Enemy Test', 'enemy@modrinth.com', 'developer'); +INSERT INTO users (id, username, email, role) VALUES (1, 'Admin', 'admin@modrinth.com', 'admin'); +INSERT INTO users (id, username, email, role) VALUES (2, 'Moderator', 'moderator@modrinth.com', 'moderator'); +INSERT INTO users (id, username, email, role) VALUES (3, 'User', 'user@modrinth.com', 'developer'); +INSERT INTO users (id, username, email, role) VALUES (4, 'Friend', 'friend@modrinth.com', 'developer'); +INSERT INTO users (id, username, email, role) VALUES (5, 'Enemy', 'enemy@modrinth.com', 'developer'); -- Full PATs for each user, with different scopes -- These are not legal PATs, as they contain all scopes- they mimic permissions of a logged in user