Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Nov 24, 2024
1 parent 32340f2 commit 73457ba
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 23 deletions.
4 changes: 3 additions & 1 deletion core/rust.bot_modules.core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl SettingView for GuildRolesExecutor {
result.push(map);
}

Ok(result) // TODO: Implement
Ok(result)
}
}

Expand Down Expand Up @@ -1330,6 +1330,8 @@ impl SettingView for GuildTemplateExecutor {
context: HookContext<'a>,
_filters: indexmap::IndexMap<String, splashcore_rs::value::Value>,
) -> Result<Vec<indexmap::IndexMap<String, splashcore_rs::value::Value>>, SettingsError> {
log::info!("Viewing guild templates for guild id: {}", context.guild_id);

check_perms(&context, &"guild_templates.view".into()).await?;

let rows = sqlx::query!("SELECT name, content, events, created_at, created_by, last_updated_at, last_updated_by FROM guild_templates WHERE guild_id = $1", context.guild_id.to_string())
Expand Down
5 changes: 1 addition & 4 deletions core/rust.settings/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::Arc;
pub type Error = Box<dyn std::error::Error + Send + Sync>; // This is constant and should be copy pasted

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
pub enum SettingsError {
/// Operation not supported
OperationNotSupported {
Expand Down Expand Up @@ -233,7 +232,7 @@ pub struct Setting {
pub columns: Arc<Vec<Column>>,

/// The supported operations for this option
#[serde(flatten, skip_deserializing)]
#[serde(skip_deserializing)]
pub operations: SettingOperations,
}

Expand Down Expand Up @@ -310,8 +309,6 @@ pub struct HookContext<'a> {
pub trait SettingView: Send + Sync {
/// View the settings data
///
/// __limit and __offset, if found, contains the limit/offset of the query
///
/// All Executors should return an __count value containing the total count of the total number of entries
async fn view<'a>(
&self,
Expand Down
15 changes: 2 additions & 13 deletions services/go.api/routes/guilds/endpoints/settings_execute/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
return hresp
}

if body.Module == "" || body.Setting == "" {
if body.Setting == "" {
return uapi.HttpResponse{
Status: http.StatusBadRequest,
Json: types.ApiError{
Message: "Both `module` and `setting` must be provided",
Message: "`setting` must be provided",
},
}
}
Expand All @@ -95,7 +95,6 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
&rpc_messages.SettingsOperationRequest{
Fields: body.Fields,
Op: body.Operation,
Module: body.Module,
Setting: body.Setting,
},
)
Expand All @@ -118,16 +117,6 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
}
}

if resp.PermissionError != nil {
return uapi.HttpResponse{
Status: http.StatusForbidden,
Json: resp.PermissionError.Res,
Headers: map[string]string{
"X-Error-Type": "permission_check",
},
}
}

if resp.Err != nil {
return uapi.HttpResponse{
Status: http.StatusBadRequest,
Expand Down
4 changes: 0 additions & 4 deletions services/go.api/rpc_messages/rpc_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type DispatchTrustedWebEventResponse struct{}
type SettingsOperationRequest struct {
Fields orderedmap.OrderedMap[string, any] `json:"fields"`
Op silverpelt.CanonicalOperationType `json:"op"`
Module string `json:"module"`
Setting string `json:"setting"`
}

Expand Down Expand Up @@ -94,9 +93,6 @@ type CanonicalSettingsResult struct {
Ok *struct {
Fields []orderedmap.OrderedMap[string, any] `json:"fields"`
} `json:"Ok"`
PermissionError *struct {
Res silverpelt.PermissionResult `json:"res"`
} `json:"PermissionError"`
Err *struct {
Error silverpelt.CanonicalSettingsError `json:"error"`
} `json:"Err"`
Expand Down
1 change: 0 additions & 1 deletion services/go.api/types/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
// SettingsExecute allows execution of a settings operation
type SettingsExecute struct {
Operation silverpelt.CanonicalOperationType `json:"operation" description:"The operation type to execute"`
Module string `json:"module" description:"The module in which the setting is in"`
Setting string `json:"setting" description:"The name of the setting"`
Fields orderedmap.OrderedMap[string, any] `json:"fields" description:"The fields to execute the operation with"`
}
Expand Down

0 comments on commit 73457ba

Please sign in to comment.