Skip to content

Commit af147de

Browse files
committed
fix(topbar): support teams in topbar owner links
1 parent 02af83e commit af147de

13 files changed

+110
-44
lines changed

.sqlx/query-d9fdce61d807d32b2c700c29e0b8100b5abf2d283016f48f468d823bd85da551.json renamed to .sqlx/query-24c697ed817d33dbdfb0e5126feaf3f5addfba6ed45f46afdc523b324da2cbab.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-5deb5bb52b993cc54f7b48714c77903829961a7b50ae4bfbdb9b34c38f374932.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

.sqlx/query-87952bd450ed2c13b99bd502a73a84edd7d17e6171523ebbd57f1d9dd7c9b46c.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-073b7016109d65c3d7907ce2b32b47018ce25577d6d9267da38edb53828ada41.json renamed to .sqlx/query-b6273727360630c958b856427cb9dacc3289dcadf82061774866fec3a62669c5.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-8e1cb8355b3586b849494ae1cbde9b034ca01090469a84df2d9af4446f9d9451.json renamed to .sqlx/query-ee9dddd0c37c0e89eab1feaddd27e5e9c7016a1b8b35b031cb05b4d0802b6be1.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE owners
2+
DROP COLUMN IF EXISTS kind;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE owners
2+
ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL CHECK (
3+
kind IN ('user', 'team')
4+
) DEFAULT 'user';

src/db/add_package.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,16 @@ async fn update_owners_in_database(
397397
for owner in owners {
398398
oids.push(
399399
sqlx::query_scalar!(
400-
"INSERT INTO owners (login, avatar)
401-
VALUES ($1, $2)
400+
"INSERT INTO owners (login, avatar, kind)
401+
VALUES ($1, $2, $3)
402402
ON CONFLICT (login) DO UPDATE
403403
SET
404-
avatar = EXCLUDED.avatar
404+
avatar = EXCLUDED.avatar,
405+
kind = EXCLUDED.kind
405406
RETURNING id",
406407
owner.login,
407-
owner.avatar
408+
owner.avatar,
409+
owner.kind,
408410
)
409411
.fetch_one(&mut *conn)
410412
.await?,
@@ -596,18 +598,20 @@ mod test {
596598
let owner1 = CrateOwner {
597599
avatar: "avatar".into(),
598600
login: "login".into(),
601+
kind: "user".into(),
599602
};
600603

601604
update_owners_in_database(&mut conn, &[owner1.clone()], crate_id).await?;
602605

603606
let owner_def = sqlx::query!(
604-
"SELECT login, avatar
607+
"SELECT login, avatar, kind
605608
FROM owners"
606609
)
607610
.fetch_one(&mut *conn)
608611
.await?;
609612
assert_eq!(owner_def.login, owner1.login);
610613
assert_eq!(owner_def.avatar, owner1.avatar);
614+
assert_eq!(owner_def.kind, owner1.kind);
611615

612616
let owner_rel = sqlx::query!(
613617
"SELECT o.login
@@ -638,6 +642,7 @@ mod test {
638642
&[CrateOwner {
639643
login: "login".into(),
640644
avatar: "avatar".into(),
645+
kind: "user".into(),
641646
}],
642647
crate_id,
643648
)
@@ -646,14 +651,16 @@ mod test {
646651
let updated_owner = CrateOwner {
647652
login: "login".into(),
648653
avatar: "avatar2".into(),
654+
kind: "team".into(),
649655
};
650656
update_owners_in_database(&mut conn, &[updated_owner.clone()], crate_id).await?;
651657

652-
let owner_def = sqlx::query!("SELECT login, avatar FROM owners")
658+
let owner_def = sqlx::query!("SELECT login, avatar, kind FROM owners")
653659
.fetch_one(&mut *conn)
654660
.await?;
655661
assert_eq!(owner_def.login, updated_owner.login);
656662
assert_eq!(owner_def.avatar, updated_owner.avatar);
663+
assert_eq!(owner_def.kind, updated_owner.kind);
657664

658665
let owner_rel = sqlx::query!(
659666
"SELECT o.login
@@ -689,6 +696,7 @@ mod test {
689696
&[CrateOwner {
690697
login: "login".into(),
691698
avatar: "avatar".into(),
699+
kind: "user".into(),
692700
}],
693701
crate_id,
694702
)
@@ -698,6 +706,7 @@ mod test {
698706
.map(|i| CrateOwner {
699707
login: format!("login{i}"),
700708
avatar: format!("avatar{i}"),
709+
kind: "user".into(),
701710
})
702711
.collect();
703712

src/db/delete.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ mod tests {
329329
.add_owner(CrateOwner {
330330
login: "malicious actor".into(),
331331
avatar: "https://example.org/malicious".into(),
332+
kind: "user".into(),
332333
})
333334
.create()?;
334335
assert!(release_exists(&mut db.conn(), v1)?);
@@ -359,6 +360,7 @@ mod tests {
359360
.add_owner(CrateOwner {
360361
login: "Peter Rabbit".into(),
361362
avatar: "https://example.org/peter".into(),
363+
kind: "user".into(),
362364
})
363365
.create()?;
364366
assert!(release_exists(&mut db.conn(), v2)?);

src/registry_api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl Default for ReleaseData {
4545
pub struct CrateOwner {
4646
pub(crate) avatar: String,
4747
pub(crate) login: String,
48+
pub(crate) kind: String,
4849
}
4950

5051
impl RegistryApi {
@@ -165,6 +166,8 @@ impl RegistryApi {
165166
avatar: Option<String>,
166167
#[serde(default)]
167168
login: Option<String>,
169+
#[serde(default)]
170+
kind: Option<String>,
168171
}
169172

170173
let response: Response = retry_async(
@@ -195,6 +198,7 @@ impl RegistryApi {
195198
.map(|data| CrateOwner {
196199
avatar: data.avatar.unwrap_or_default(),
197200
login: data.login.unwrap_or_default(),
201+
kind: data.kind.unwrap_or("user".into()),
198202
})
199203
.collect();
200204

0 commit comments

Comments
 (0)