Remove name field (and remove existing data) (#935)

* Remove name field (and remove existing data)

* run prep, fmt

* fix dummy data
This commit is contained in:
Geometrically
2024-09-06 20:16:28 -07:00
committed by GitHub
parent 637a923e84
commit 2e35f3608b
14 changed files with 67 additions and 133 deletions

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -0,0 +1 @@
ALTER TABLE users DROP COLUMN name;

View File

@@ -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,

View File

@@ -37,7 +37,6 @@ pub struct User {
pub totp_secret: Option<String>,
pub username: String,
pub name: Option<String>,
pub email: Option<String>,
pub email_verified: bool,
pub avatar_url: Option<String>,
@@ -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,

View File

@@ -35,7 +35,7 @@ impl From<crate::models::v3::users::User> 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,

View File

@@ -39,7 +39,6 @@ impl Default for Badges {
pub struct User {
pub id: UserId,
pub username: String,
pub name: Option<String>,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub created: DateTime<Utc>,
@@ -73,7 +72,6 @@ impl From<DBUser> for User {
Self {
id: data.id.into(),
username: data.username,
name: data.name,
email: None,
email_verified: None,
avatar_url: data.avatar_url,

View File

@@ -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 {

View File

@@ -65,7 +65,6 @@ pub struct TempUser {
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub name: Option<String>,
pub country: Option<String>,
}
@@ -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<String>,
pub mail: Option<String>,
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<String>,
pub picture: Option<String>,
}
@@ -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<String>,
}
@@ -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 {

View File

@@ -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,

View File

@@ -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<Option<String>>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::double_option"
)]
#[validate(length(max = 160))]
pub bio: Option<Option<String>>,
pub role: Option<Role>,
@@ -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!(
"

View File

@@ -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