Skip to content

Fixing issues with owner invites and renamed accounts #2177

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

Merged
merged 5 commits into from
Apr 4, 2020
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
2 changes: 2 additions & 0 deletions src/models/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ impl Owner {
} else {
users::table
.filter(users::gh_login.eq(name))
.filter(users::gh_id.ne(-1))
.order(users::gh_id.desc())
.first(conn)
.map(Owner::User)
.map_err(|_| cargo_err(&format_args!("could not find user with login `{}`", name)))
Expand Down
57 changes: 57 additions & 0 deletions src/tests/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,60 @@ fn test_decline_invitation() {
let json = anon.show_crate_owners("decline_invitation");
assert_eq!(json.users.len(), 1);
}

#[test]
fn inactive_users_dont_get_invitations() {
use cargo_registry::models::NewUser;
use std::borrow::Cow;

let (app, _, owner, owner_token) = TestApp::init().with_token();
let owner = owner.as_model();

// An inactive user with gh_id -1 and an active user with a non-negative gh_id both exist
let invited_gh_login = "user_bar";
let krate_name = "inactive_test";

app.db(|conn| {
NewUser {
gh_id: -1,
gh_login: invited_gh_login,
name: None,
gh_avatar: None,
gh_access_token: Cow::Borrowed("some random token"),
}
.create_or_update(None, conn)
.unwrap();
CrateBuilder::new(krate_name, owner.id).expect_build(conn);
});

let invited_user = app.db_new_user(invited_gh_login);

owner_token.add_user_owner(krate_name, invited_user.as_model());

let json = invited_user.list_invitations();
assert_eq!(json.crate_owner_invitations.len(), 1);
}

#[test]
fn highest_gh_id_is_most_recent_account_we_know_of() {
let (app, _, owner, owner_token) = TestApp::init().with_token();
let owner = owner.as_model();

// An inactive user with a lower gh_id and an active user with a higher gh_id both exist
let invited_gh_login = "user_bar";
let krate_name = "newer_user_test";

// This user will get a lower gh_id, given how crate::new_user works
app.db_new_user(invited_gh_login);

let invited_user = app.db_new_user(invited_gh_login);

app.db(|conn| {
CrateBuilder::new(krate_name, owner.id).expect_build(conn);
});

owner_token.add_user_owner(krate_name, invited_user.as_model());

let json = invited_user.list_invitations();
assert_eq!(json.crate_owner_invitations.len(), 1);
}