(
State(state): State<AppState>,
// Extension(session): Extension<LoggedInSession<CurrentSessionStore>>,
Extension(current_guild): Extension<CurrentUserGuild>,
Path(GuildScriptPathPara
| 268 | } |
| 269 | |
| 270 | pub async fn update_script_plugin( |
| 271 | State(state): State<AppState>, |
| 272 | // Extension(session): Extension<LoggedInSession<CurrentSessionStore>>, |
| 273 | Extension(current_guild): Extension<CurrentUserGuild>, |
| 274 | Path(GuildScriptPathParams { script_id }): Path<GuildScriptPathParams>, |
| 275 | ) -> ApiResult<impl IntoResponse> { |
| 276 | let script = state |
| 277 | .db |
| 278 | .get_script_by_id(current_guild.id, script_id) |
| 279 | .await |
| 280 | .map_err(|err| { |
| 281 | error!(?err, "failed fetching guild script"); |
| 282 | ApiErrorResponse::InternalError |
| 283 | })?; |
| 284 | |
| 285 | let Some(plugin_id) = script.plugin_id else { |
| 286 | return Err(ApiErrorResponse::ScriptNotAPlugin); |
| 287 | }; |
| 288 | |
| 289 | let plugin = fetch_plugin(&state.db, plugin_id).await?; |
| 290 | let new_source = match plugin.data { |
| 291 | common::plugin::PluginData::ScriptPlugin(p) => p.published_version.unwrap_or_default(), |
| 292 | }; |
| 293 | |
| 294 | // I think if we have already added a plugin to a guild then we should still be able to update it even if it's set to private afterwards |
| 295 | // |
| 296 | // TODO decision on this |
| 297 | // |
| 298 | // if !plugin.is_public && plugin.author_id != session.session.user.id { |
| 299 | // return Err(ApiErrorResponse::NoAccessToPlugin); |
| 300 | // } |
| 301 | |
| 302 | let sc = UpdateScript { |
| 303 | id: script_id, |
| 304 | enabled: None, |
| 305 | original_source: Some(new_source), |
| 306 | name: None, |
| 307 | plugin_version_number: Some(plugin.current_version), |
| 308 | settings_values: None, |
| 309 | }; |
| 310 | |
| 311 | let script = state |
| 312 | .db |
| 313 | .update_script(current_guild.id, sc) |
| 314 | .await |
| 315 | .map_err(|err| { |
| 316 | error!(%err, "failed updating guild script"); |
| 317 | ApiErrorResponse::InternalError |
| 318 | })?; |
| 319 | |
| 320 | state |
| 321 | .bot_rpc_client |
| 322 | .reload_vm(GuildSpecifier { |
| 323 | guild_id: current_guild.id, |
| 324 | }) |
| 325 | .await |
| 326 | .map_err(|err| { |
| 327 | error!(%err, "failed reloading guild vm"); |
nothing calls this directly
no test coverage detected