You've already forked AstralRinth
forked from didirus/AstralRinth
* Minos push (#589) * moving to other computer * working redirection * incomplete pat setup * no more errors * new migrations * fixed bugs; added user check * pats * resized pats * removed testing callback * lowered kratos_id size * metadata support * google not working * refactoring * restructured github_id * kratos-id optional, legacy accounts connect * default picture * merge mistake * clippy * sqlx-data.json * env vars, clippy * merge error * scopes into an i64, name * requested changes * removed banning * partial completion of github flow * revision --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -83,6 +83,14 @@ generate_ids!(
|
||||
"SELECT EXISTS(SELECT 1 FROM states WHERE id=$1)",
|
||||
StateId
|
||||
);
|
||||
generate_ids!(
|
||||
pub generate_pat_id,
|
||||
PatId,
|
||||
8,
|
||||
"SELECT EXISTS(SELECT 1 FROM pats WHERE id=$1)",
|
||||
PatId
|
||||
);
|
||||
|
||||
generate_ids!(
|
||||
pub generate_user_id,
|
||||
UserId,
|
||||
@@ -177,6 +185,10 @@ pub struct FileId(pub i64);
|
||||
#[sqlx(transparent)]
|
||||
pub struct StateId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct PatId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct NotificationId(pub i64);
|
||||
|
||||
@@ -128,7 +128,7 @@ impl TeamMember {
|
||||
let teams = sqlx::query!(
|
||||
"
|
||||
SELECT tm.id id, tm.team_id team_id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split, tm.ordering,
|
||||
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
||||
u.id user_id, u.name user_name, u.email email, u.kratos_id kratos_id, u.github_id github_id,
|
||||
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,
|
||||
@@ -153,6 +153,7 @@ impl TeamMember {
|
||||
user: User {
|
||||
id: UserId(m.user_id),
|
||||
github_id: m.github_id,
|
||||
kratos_id: m.kratos_id,
|
||||
name: m.user_name,
|
||||
email: m.email,
|
||||
avatar_url: m.avatar_url,
|
||||
|
||||
@@ -5,6 +5,7 @@ use rust_decimal::Decimal;
|
||||
|
||||
pub struct User {
|
||||
pub id: UserId,
|
||||
pub kratos_id: Option<String>, // None if legacy user unconnected to Minos/Kratos
|
||||
pub github_id: Option<i64>,
|
||||
pub username: String,
|
||||
pub name: Option<String>,
|
||||
@@ -28,7 +29,7 @@ impl User {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO users (
|
||||
id, github_id, username, name, email,
|
||||
id, kratos_id, username, name, email,
|
||||
avatar_url, bio, created
|
||||
)
|
||||
VALUES (
|
||||
@@ -37,7 +38,7 @@ impl User {
|
||||
)
|
||||
",
|
||||
self.id as UserId,
|
||||
self.github_id,
|
||||
self.kratos_id,
|
||||
&self.username,
|
||||
self.name.as_ref(),
|
||||
self.email.as_ref(),
|
||||
@@ -50,6 +51,7 @@ impl User {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get<'a, 'b, E>(id: UserId, executor: E) -> Result<Option<Self>, sqlx::error::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
@@ -68,7 +70,7 @@ impl User {
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT u.id, u.name, u.email,
|
||||
SELECT u.id, u.name, u.email, u.kratos_id,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
@@ -87,6 +89,54 @@ impl User {
|
||||
github_id: Some(github_id as i64),
|
||||
name: row.name,
|
||||
email: row.email,
|
||||
kratos_id: row.kratos_id,
|
||||
avatar_url: row.avatar_url,
|
||||
username: row.username,
|
||||
bio: row.bio,
|
||||
created: row.created,
|
||||
role: row.role,
|
||||
badges: Badges::from_bits(row.badges as u64).unwrap_or_default(),
|
||||
balance: row.balance,
|
||||
payout_wallet: row.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
|
||||
payout_wallet_type: row
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&x)),
|
||||
payout_address: row.payout_address,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_from_minos_kratos_id<'a, 'b, E>(
|
||||
kratos_id: String,
|
||||
executor: E,
|
||||
) -> Result<Option<Self>, sqlx::error::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT u.id, u.name, u.kratos_id, u.email, u.github_id,
|
||||
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
|
||||
FROM users u
|
||||
WHERE u.kratos_id = $1
|
||||
",
|
||||
kratos_id as String,
|
||||
)
|
||||
.fetch_optional(executor)
|
||||
.await?;
|
||||
|
||||
if let Some(row) = result {
|
||||
Ok(Some(User {
|
||||
id: UserId(row.id),
|
||||
kratos_id: row.kratos_id,
|
||||
github_id: row.github_id,
|
||||
name: row.name,
|
||||
email: row.email,
|
||||
avatar_url: row.avatar_url,
|
||||
username: row.username,
|
||||
bio: row.bio,
|
||||
@@ -114,7 +164,7 @@ impl User {
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT u.id, u.github_id, u.name, u.email,
|
||||
SELECT u.id, u.kratos_id, u.name, u.email, u.github_id,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
@@ -130,6 +180,7 @@ impl User {
|
||||
if let Some(row) = result {
|
||||
Ok(Some(User {
|
||||
id: UserId(row.id),
|
||||
kratos_id: row.kratos_id,
|
||||
github_id: row.github_id,
|
||||
name: row.name,
|
||||
email: row.email,
|
||||
@@ -160,7 +211,7 @@ impl User {
|
||||
let user_ids_parsed: Vec<i64> = user_ids.iter().map(|x| x.0).collect();
|
||||
let users = sqlx::query!(
|
||||
"
|
||||
SELECT u.id, u.github_id, u.name, u.email,
|
||||
SELECT u.id, u.kratos_id, u.name, u.email, u.github_id,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
@@ -174,6 +225,7 @@ impl User {
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|u| User {
|
||||
id: UserId(u.id),
|
||||
kratos_id: u.kratos_id,
|
||||
github_id: u.github_id,
|
||||
name: u.name,
|
||||
email: u.email,
|
||||
@@ -514,4 +566,28 @@ impl User {
|
||||
Ok(id.map(|x| UserId(x.id)))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn merge_minos_user<'a, 'b, E>(
|
||||
&self,
|
||||
kratos_id: &str,
|
||||
executor: E,
|
||||
) -> Result<(), sqlx::error::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
// If the user exists, link the Minos user into the existing user rather tham create a new one
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE users
|
||||
SET kratos_id = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
kratos_id,
|
||||
self.id.0,
|
||||
)
|
||||
.execute(executor)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user