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

Team page #790

Merged
merged 16 commits into from
Jun 21, 2017
Merged

Team page #790

merged 16 commits into from
Jun 21, 2017

Conversation

natboehm
Copy link
Contributor

Creates a team page listing all crates associated with given team.

screen shot 2017-06-20 at 2 28 58 pm

Fixes #409

src/krate.rs Outdated
@@ -598,6 +602,32 @@ impl Crate {
Ok(users.chain(teams).collect())
}

pub fn owner_team(&self, conn: &PgConnection) -> CargoResult<Vec<Owner>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crate has a lot of behavior on it as is. What do you think about putting this on Team instead and calling it Team::owning(crate: &Crate, conn: &PgConnection)

src/krate.rs Outdated
Ok(teams.collect())
}

pub fn owner_user(&self, conn: &PgConnection) -> CargoResult<Vec<Owner>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crate has a lot of behavior on it as is. What do you think about putting this on User instead and calling it User::owning(crate: &Crate, conn: &PgConnection)

@@ -864,6 +894,15 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
.filter(crate_owners::owner_kind.eq(OwnerKind::User as i32)),
),
);
} else if let Some(team_id) = params.get("team_id").and_then(|s| s.parse::<i32>().ok()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to put this on index instead of adding a new route?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with how getting a user's crates works, mostly. If we're going to pull this out into its own route, then I think users should be pulled out too, which imo should be a separate PR. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that users should be pulled out as well, but I don't think that should block this PR being a separate route, if it's not significantly more work for this PR.

@@ -1423,6 +1462,42 @@ pub fn owners(req: &mut Request) -> CargoResult<Response> {
Ok(req.json(&R { users: owners }))
}

/// Handles the `GET /crates/:crate_id/owner_team` route.
pub fn owner_team(req: &mut Request) -> CargoResult<Response> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this a single route and adding a ?kind parameter if needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tried, but the structure of the response has user: vs team: change that ember cares about, and I suck at ember and I'm not sure why it cares about that. If we duplicate the response structure too, then it's most of the function that's still duplicated :-/

I wouldn't be opposed to refactoring this in the future, it would just take me more time in ember than we'd like to spend right now :P

src/tests/all.rs Outdated
}

fn add_team_to_crate(t: &Team, krate: &Crate, u: &User, conn: &PgConnection) -> CargoResult<()> {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're just talking about cutting the newline here, right? #ambiguousemoji

diesel::insert(&crate_owner.on_conflict(
crate_owners::table.primary_key(),
do_update().set(crate_owners::deleted.eq(false)),
)).into(crate_owners::table)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the indentation rustfmt came up with?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeppers

Copy link
Member

@carols10cents carols10cents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few small things :)

},
(e) => {
if (e.errors.any(e => e.detail === 'Not Found')) {
console.log(params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a debugging console.log left in here :)

src/owner.rs Outdated
)).into(teams::table)
.get_result(conn)
.map_err(Into::into)
fn get_org(login: &str) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can refactor this a bit into one function that returns two string slices in a tuple-- I'll explain what I mean in person :)

one only owned by a user, check that the CrateList returned
for the user_id contains only the crates owned by that user,
and that the CrateList returned for the team_id contains
only crates owned by that team.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻 love these comments!!

@@ -864,6 +894,15 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
.filter(crate_owners::owner_kind.eq(OwnerKind::User as i32)),
),
);
} else if let Some(team_id) = params.get("team_id").and_then(|s| s.parse::<i32>().ok()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with how getting a user's crates works, mostly. If we're going to pull this out into its own route, then I think users should be pulled out too, which imo should be a separate PR. WDYT?

@carols10cents carols10cents merged commit af7f0c1 into rust-lang:master Jun 21, 2017
@natboehm natboehm deleted the team-page branch June 21, 2017 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants