Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(topbar): support teams in topbar owner links #2432

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

4 changes: 4 additions & 0 deletions migrations/20240227040753_add_owner_kind.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE owners
DROP COLUMN IF EXISTS kind;

DROP TYPE IF EXISTS owner_kind;
14 changes: 14 additions & 0 deletions migrations/20240227040753_add_owner_kind.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TYPE owner_kind AS ENUM (
'user',
'team'
);

ALTER TABLE owners
ADD COLUMN IF NOT EXISTS kind owner_kind NOT NULL DEFAULT 'user';

UPDATE owners
SET
kind = CASE
WHEN login LIKE 'github:%' THEN 'team'::owner_kind
ELSE 'user'::owner_kind
END;
29 changes: 20 additions & 9 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,16 @@ async fn update_owners_in_database(
for owner in owners {
oids.push(
sqlx::query_scalar!(
"INSERT INTO owners (login, avatar)
VALUES ($1, $2)
"INSERT INTO owners (login, avatar, kind)
VALUES ($1, $2, $3)
ON CONFLICT (login) DO UPDATE
SET
avatar = EXCLUDED.avatar
avatar = EXCLUDED.avatar,
kind = EXCLUDED.kind
RETURNING id",
owner.login,
owner.avatar
owner.avatar,
owner.kind as _,
)
.fetch_one(&mut *conn)
.await?,
Expand Down Expand Up @@ -520,6 +522,7 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::registry_api::OwnerKind;
use crate::test::*;
use crate::utils::CargoMetadata;
use test_case::test_case;
Expand Down Expand Up @@ -647,18 +650,20 @@ mod test {
let owner1 = CrateOwner {
avatar: "avatar".into(),
login: "login".into(),
kind: OwnerKind::User,
};

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

let owner_def = sqlx::query!(
"SELECT login, avatar
FROM owners"
r#"SELECT login, avatar, kind as "kind: OwnerKind"
FROM owners"#
)
.fetch_one(&mut *conn)
.await?;
assert_eq!(owner_def.login, owner1.login);
assert_eq!(owner_def.avatar, owner1.avatar);
assert_eq!(owner_def.kind, owner1.kind);

let owner_rel = sqlx::query!(
"SELECT o.login
Expand Down Expand Up @@ -688,6 +693,7 @@ mod test {
&[CrateOwner {
login: "login".into(),
avatar: "avatar".into(),
kind: OwnerKind::User,
}],
crate_id,
)
Expand All @@ -696,14 +702,17 @@ mod test {
let updated_owner = CrateOwner {
login: "login".into(),
avatar: "avatar2".into(),
kind: OwnerKind::Team,
};
update_owners_in_database(&mut conn, &[updated_owner.clone()], crate_id).await?;

let owner_def = sqlx::query!("SELECT login, avatar FROM owners")
.fetch_one(&mut *conn)
.await?;
let owner_def =
sqlx::query!(r#"SELECT login, avatar, kind as "kind: OwnerKind" FROM owners"#)
.fetch_one(&mut *conn)
.await?;
assert_eq!(owner_def.login, updated_owner.login);
assert_eq!(owner_def.avatar, updated_owner.avatar);
assert_eq!(owner_def.kind, updated_owner.kind);

let owner_rel = sqlx::query!(
"SELECT o.login
Expand Down Expand Up @@ -733,6 +742,7 @@ mod test {
&[CrateOwner {
login: "login".into(),
avatar: "avatar".into(),
kind: OwnerKind::User,
}],
crate_id,
)
Expand All @@ -742,6 +752,7 @@ mod test {
.map(|i| CrateOwner {
login: format!("login{i}"),
avatar: format!("avatar{i}"),
kind: OwnerKind::User,
})
.collect();

Expand Down
Loading
Loading