Skip to content

Commit de0b0c7

Browse files
committed
models/team: Inline Team::create_or_update() fn
This fn is not doing anything database-related, so it shouldn't live in the `models` module.
1 parent 5b5fd9d commit de0b0c7

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

src/controllers/krate/owners.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,36 @@ async fn add_team_owner(
337337
login: &str,
338338
) -> Result<NewOwnerInvite, OwnerAddError> {
339339
// Always recreate teams to get the most up-to-date GitHub ID
340-
let team = Team::create_or_update(gh_client, conn, login, req_user).await?;
340+
let mut chunks = login.split(':');
341+
let team = match chunks.next().unwrap() {
342+
// github:rust-lang:owners
343+
"github" => {
344+
// unwrap is documented above as part of the calling contract
345+
let org = chunks.next().unwrap();
346+
let team = chunks.next().ok_or_else(|| {
347+
bad_request(
348+
"missing github team argument; \
349+
format is github:org:team",
350+
)
351+
})?;
352+
Team::create_or_update_github_team(
353+
gh_client,
354+
conn,
355+
&login.to_lowercase(),
356+
org,
357+
team,
358+
req_user,
359+
)
360+
.await?
361+
}
362+
_ => {
363+
return Err(bad_request(
364+
"unknown organization handler, \
365+
only 'github:org:team' is supported",
366+
)
367+
.into());
368+
}
369+
};
341370

342371
// Teams are added as owners immediately, since the above call ensures
343372
// the user is a team member.

src/models/team.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,52 +58,10 @@ impl NewTeam<'_> {
5858
}
5959

6060
impl Team {
61-
/// Tries to create the Team in the DB (assumes a `:` has already been found).
62-
///
63-
/// # Panics
64-
///
65-
/// This function will panic if login contains less than 2 `:` characters.
66-
pub async fn create_or_update(
67-
gh_client: &dyn GitHubClient,
68-
conn: &mut AsyncPgConnection,
69-
login: &str,
70-
req_user: &User,
71-
) -> AppResult<Self> {
72-
// must look like system:xxxxxxx
73-
let mut chunks = login.split(':');
74-
// unwrap is okay, split on an empty string still has 1 chunk
75-
match chunks.next().unwrap() {
76-
// github:rust-lang:owners
77-
"github" => {
78-
// unwrap is documented above as part of the calling contract
79-
let org = chunks.next().unwrap();
80-
let team = chunks.next().ok_or_else(|| {
81-
bad_request(
82-
"missing github team argument; \
83-
format is github:org:team",
84-
)
85-
})?;
86-
Team::create_or_update_github_team(
87-
gh_client,
88-
conn,
89-
&login.to_lowercase(),
90-
org,
91-
team,
92-
req_user,
93-
)
94-
.await
95-
}
96-
_ => Err(bad_request(
97-
"unknown organization handler, \
98-
only 'github:org:team' is supported",
99-
)),
100-
}
101-
}
102-
10361
/// Tries to create or update a Github Team. Assumes `org` and `team` are
10462
/// correctly parsed out of the full `name`. `name` is passed as a
10563
/// convenience to avoid rebuilding it.
106-
async fn create_or_update_github_team(
64+
pub async fn create_or_update_github_team(
10765
gh_client: &dyn GitHubClient,
10866
conn: &mut AsyncPgConnection,
10967
login: &str,

0 commit comments

Comments
 (0)