You've already forked AstralRinth
forked from didirus/AstralRinth
FlameAnvil Project Sync (#481)
* FlameAnvil Project Sync * Perm fixes * Fix compile * Fix clippy + run prepare
This commit is contained in:
@@ -129,6 +129,8 @@ impl ProjectBuilder {
|
||||
slug: self.slug,
|
||||
moderation_message: None,
|
||||
moderation_message_body: None,
|
||||
flame_anvil_project: None,
|
||||
flame_anvil_user: None,
|
||||
};
|
||||
project_struct.insert(&mut *transaction).await?;
|
||||
|
||||
@@ -203,6 +205,8 @@ pub struct Project {
|
||||
pub slug: Option<String>,
|
||||
pub moderation_message: Option<String>,
|
||||
pub moderation_message_body: Option<String>,
|
||||
pub flame_anvil_project: Option<i32>,
|
||||
pub flame_anvil_user: Option<UserId>,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
@@ -267,7 +271,8 @@ impl Project {
|
||||
updated, approved, status,
|
||||
issues_url, source_url, wiki_url, discord_url, license_url,
|
||||
team_id, client_side, server_side, license, slug,
|
||||
moderation_message, moderation_message_body
|
||||
moderation_message, moderation_message_body, flame_anvil_project,
|
||||
flame_anvil_user
|
||||
FROM mods
|
||||
WHERE id = $1
|
||||
",
|
||||
@@ -303,6 +308,8 @@ impl Project {
|
||||
moderation_message: row.moderation_message,
|
||||
moderation_message_body: row.moderation_message_body,
|
||||
approved: row.approved,
|
||||
flame_anvil_project: row.flame_anvil_project,
|
||||
flame_anvil_user: row.flame_anvil_user.map(UserId),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -327,7 +334,8 @@ impl Project {
|
||||
updated, approved, status,
|
||||
issues_url, source_url, wiki_url, discord_url, license_url,
|
||||
team_id, client_side, server_side, license, slug,
|
||||
moderation_message, moderation_message_body
|
||||
moderation_message, moderation_message_body, flame_anvil_project,
|
||||
flame_anvil_user
|
||||
FROM mods
|
||||
WHERE id = ANY($1)
|
||||
",
|
||||
@@ -361,6 +369,8 @@ impl Project {
|
||||
moderation_message: m.moderation_message,
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
approved: m.approved,
|
||||
flame_anvil_project: m.flame_anvil_project,
|
||||
flame_anvil_user: m.flame_anvil_user.map(UserId)
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<Project>>()
|
||||
@@ -639,7 +649,7 @@ impl Project {
|
||||
m.updated updated, m.approved approved, m.status status,
|
||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
||||
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name, pt.name project_type_name,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name, pt.name project_type_name, m.flame_anvil_project flame_anvil_project, m.flame_anvil_user flame_anvil_user,
|
||||
ARRAY_AGG(DISTINCT c.category || ' |||| ' || mc.is_additional) filter (where c.category is not null) categories,
|
||||
ARRAY_AGG(DISTINCT v.id || ' |||| ' || v.date_published) filter (where v.id is not null) versions,
|
||||
ARRAY_AGG(DISTINCT mg.image_url || ' |||| ' || mg.featured || ' |||| ' || mg.created || ' |||| ' || COALESCE(mg.title, ' ') || ' |||| ' || COALESCE(mg.description, ' ')) filter (where mg.image_url is not null) gallery,
|
||||
@@ -709,6 +719,8 @@ impl Project {
|
||||
moderation_message: m.moderation_message,
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
approved: m.approved,
|
||||
flame_anvil_project: m.flame_anvil_project,
|
||||
flame_anvil_user: m.flame_anvil_user.map(UserId),
|
||||
},
|
||||
project_type: m.project_type_name,
|
||||
categories,
|
||||
@@ -826,7 +838,7 @@ impl Project {
|
||||
m.updated updated, m.approved approved, m.status status,
|
||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
||||
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name, pt.name project_type_name,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name, pt.name project_type_name, m.flame_anvil_project flame_anvil_project, m.flame_anvil_user flame_anvil_user,
|
||||
ARRAY_AGG(DISTINCT c.category || ' |||| ' || mc.is_additional) filter (where c.category is not null) categories,
|
||||
ARRAY_AGG(DISTINCT v.id || ' |||| ' || v.date_published) filter (where v.id is not null) versions,
|
||||
ARRAY_AGG(DISTINCT mg.image_url || ' |||| ' || mg.featured || ' |||| ' || mg.created || ' |||| ' || COALESCE(mg.title, ' ') || ' |||| ' || COALESCE(mg.description, ' ')) filter (where mg.image_url is not null) gallery,
|
||||
@@ -897,7 +909,9 @@ impl Project {
|
||||
follows: m.follows,
|
||||
moderation_message: m.moderation_message,
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
approved: m.approved
|
||||
approved: m.approved,
|
||||
flame_anvil_project: m.flame_anvil_project,
|
||||
flame_anvil_user: m.flame_anvil_user.map(UserId)
|
||||
},
|
||||
project_type: m.project_type_name,
|
||||
categories,
|
||||
|
||||
@@ -160,7 +160,7 @@ impl TeamMember {
|
||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
|
||||
u.payout_address payout_address
|
||||
u.payout_address payout_address, u.flame_anvil_key flame_anvil_key
|
||||
FROM team_members tm
|
||||
INNER JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.team_id = $1
|
||||
@@ -191,7 +191,8 @@ impl TeamMember {
|
||||
balance: m.balance,
|
||||
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
|
||||
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: m.payout_address
|
||||
payout_address: m.payout_address,
|
||||
flame_anvil_key: m.flame_anvil_key,
|
||||
},
|
||||
payouts_split: m.payouts_split
|
||||
})))
|
||||
@@ -228,7 +229,7 @@ impl TeamMember {
|
||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
|
||||
u.payout_address payout_address
|
||||
u.payout_address payout_address, u.flame_anvil_key flame_anvil_key
|
||||
FROM team_members tm
|
||||
INNER JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.team_id = ANY($1)
|
||||
@@ -260,7 +261,8 @@ impl TeamMember {
|
||||
balance: m.balance,
|
||||
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
|
||||
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: m.payout_address
|
||||
payout_address: m.payout_address,
|
||||
flame_anvil_key: m.flame_anvil_key,
|
||||
},
|
||||
payouts_split: m.payouts_split
|
||||
})))
|
||||
@@ -517,15 +519,24 @@ impl TeamMember {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete<'a, 'b, E>(
|
||||
pub async fn delete<'a, 'b>(
|
||||
id: TeamId,
|
||||
user_id: UserId,
|
||||
executor: E,
|
||||
) -> Result<(), super::DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), super::DatabaseError> {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET flame_anvil_user = NULL
|
||||
WHERE (team_id = $1 AND flame_anvil_user = $2 )
|
||||
",
|
||||
id as TeamId,
|
||||
user_id as UserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM team_members
|
||||
WHERE (team_id = $1 AND user_id = $2 AND NOT role = $3)
|
||||
@@ -534,16 +545,9 @@ impl TeamMember {
|
||||
user_id as UserId,
|
||||
crate::models::teams::OWNER_ROLE,
|
||||
)
|
||||
.execute(executor)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() != 1 {
|
||||
return Err(super::DatabaseError::Other(format!(
|
||||
"Deleting a member failed; {} rows deleted",
|
||||
result.rows_affected()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pub struct User {
|
||||
pub payout_wallet: Option<RecipientWallet>,
|
||||
pub payout_wallet_type: Option<RecipientType>,
|
||||
pub payout_address: Option<String>,
|
||||
pub flame_anvil_key: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
@@ -63,7 +64,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
u.payout_address, u.flame_anvil_key
|
||||
FROM users u
|
||||
WHERE u.id = $1
|
||||
",
|
||||
@@ -93,6 +94,7 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
flame_anvil_key: row.flame_anvil_key,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -112,7 +114,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
u.payout_address, u.flame_anvil_key
|
||||
FROM users u
|
||||
WHERE u.github_id = $1
|
||||
",
|
||||
@@ -142,6 +144,7 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
flame_anvil_key: row.flame_anvil_key,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -161,7 +164,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
u.payout_address, u.flame_anvil_key
|
||||
FROM users u
|
||||
WHERE LOWER(u.username) = LOWER($1)
|
||||
",
|
||||
@@ -191,6 +194,7 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
flame_anvil_key: row.flame_anvil_key,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -214,7 +218,7 @@ impl User {
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
u.payout_address, u.flame_anvil_key
|
||||
FROM users u
|
||||
WHERE u.id = ANY($1)
|
||||
",
|
||||
@@ -241,6 +245,7 @@ impl User {
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: u.payout_address,
|
||||
flame_anvil_key: u.flame_anvil_key,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<User>>()
|
||||
|
||||
Reference in New Issue
Block a user