Skip to content

Commit f73d9d3

Browse files
committed
fix(mods): merge dev check and version check in create
1 parent dba04ae commit f73d9d3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/endpoints/mods.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,18 @@ pub async fn get(
112112
.ok_or(ApiError::NotFound(format!("Mod '{id}' not found")))?;
113113

114114
let version_statuses = match dev {
115-
None => Some(vec![ModVersionStatusEnum::Accepted, ModVersionStatusEnum::Pending]),
115+
None => Some(vec![
116+
ModVersionStatusEnum::Accepted,
117+
ModVersionStatusEnum::Pending,
118+
]),
116119
Some(d) => {
117120
if d.admin {
118121
None
119122
} else {
120-
Some(vec![ModVersionStatusEnum::Accepted, ModVersionStatusEnum::Pending])
123+
Some(vec![
124+
ModVersionStatusEnum::Accepted,
125+
ModVersionStatusEnum::Pending,
126+
])
121127
}
122128
}
123129
};
@@ -128,12 +134,8 @@ pub async fn get(
128134
.map(|t| t.name)
129135
.collect();
130136
the_mod.developers = developers::get_all_for_mod(&the_mod.id, &mut pool).await?;
131-
the_mod.versions = mod_versions::get_for_mod(
132-
&the_mod.id,
133-
version_statuses.as_deref(),
134-
&mut pool,
135-
)
136-
.await?;
137+
the_mod.versions =
138+
mod_versions::get_for_mod(&the_mod.id, version_statuses.as_deref(), &mut pool).await?;
137139
the_mod.links = ModLinks::fetch(&the_mod.id, &mut pool).await?;
138140

139141
for i in &mut the_mod.versions {
@@ -164,23 +166,21 @@ pub async fn create(
164166

165167
let existing: Option<Mod> = mods::get_one(&json.id, false, &mut pool).await?;
166168

167-
if let Some(s) = &existing {
168-
let versions = mod_versions::get_for_mod(&s.id, None, &mut pool).await?;
169+
if let Some(m) = &existing {
170+
if !developers::has_access_to_mod(dev.id, &m.id, &mut pool).await? {
171+
return Err(ApiError::Forbidden);
172+
}
173+
174+
let versions = mod_versions::get_for_mod(&m.id, None, &mut pool).await?;
169175

170176
if !versions.is_empty() {
171177
return Ok(HttpResponse::Conflict().json(ApiResponse {
172-
error: format!("Mod {} already exists! Submit a new version.", s.id),
178+
error: format!("Mod {} already exists! Submit a new version.", m.id),
173179
payload: "",
174180
}));
175181
}
176182
}
177183

178-
if let Some(m) = &existing {
179-
if !developers::has_access_to_mod(dev.id, &m.id, &mut pool).await? {
180-
return Err(ApiError::Forbidden);
181-
}
182-
}
183-
184184
let mut tx = pool.begin().await.or(Err(ApiError::TransactionError))?;
185185

186186
let mod_already_exists = existing.is_some();

0 commit comments

Comments
 (0)