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

[Bug]: PUT requests to /site fail if application_question is not provided, even if the question has already been configured for the site #3323

Closed
4 tasks done
kartikynwa opened this issue Jun 24, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@kartikynwa
Copy link
Contributor

Requirements

  • Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • Did you check to see if this issue already exists?
  • Is this only a single bug? Do not put multiple bugs in one issue.
  • Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.

Summary

If I try to update the rate limit from the UI, the PUT request fails with this error:

{"error": "application_question_required"}

This code is only checking whether application_question is a valid value in the request body and not if the application question has already been set:

let application_question = diesel_option_overwrite(&data.application_question);
check_application_question(
&application_question,
data
.registration_mode
.unwrap_or(local_site.registration_mode),
)?;

As such a request with this body fails:

{
	"auth": "jwt",
	"rate_limit_comment": 999,
	"rate_limit_comment_per_second": 600,
	"rate_limit_id": 1,
	"rate_limit_image": 999,
	"rate_limit_image_per_second": 3600,
	"rate_limit_local_site_id": 1,
	"rate_limit_message": 999,
	"rate_limit_message_per_second": 60,
	"rate_limit_post": 999,
	"rate_limit_post_per_second": 600,
	"rate_limit_published": "2023-06-24T09:34:21.426600",
	"rate_limit_register": 999,
	"rate_limit_register_per_second": 3600,
	"rate_limit_search": 999,
	"rate_limit_search_per_second": 600
}

Steps to Reproduce

  1. As an admin, try to change the rate limit of your instance.
  2. The request fails with a 400 response.

Technical Details

Backend log
2023-06-24T10:12:03.041631Z  WARN Error encountered while processing the incoming HTTP request: lemmy_server::root_span_builder: application_question_required: application_question_required
   0: lemmy_api_crud::site::update::perform
           with self=EditSite { name: None, sidebar: None, description: None, icon: None, banner: None, enable_downvotes: None, enable_nsfw: None, community_creation_admin_only: None, require_email_verification: None, application_question: None, private_instance: None, default_theme: None, default_post_listing_type: None, legal_information: None, application_email_admins: None, hide_modlog_mod_names: None, discussion_languages: None, slur_filter_regex: None, actor_name_max_length: None, rate_limit_message: Some(999), rate_limit_message_per_second: Some(60), rate_limit_post: Some(999), rate_limit_post_per_second: Some(600), rate_limit_register: Some(999), rate_limit_register_per_second: Some(3600), rate_limit_image: Some(999), rate_limit_image_per_second: Some(3600), rate_limit_comment: Some(999), rate_limit_comment_per_second: Some(600), rate_limit_search: Some(999), rate_limit_search_per_second: Some(600), federation_enabled: None, federation_debug: None, federation_worker_count: None, captcha_enabled: None, captcha_difficulty: None, allowed_instances: None, blocked_instances: None, taglines: None, registration_mode: None, reports_email_admins: None, auth: Sensitive }
             at crates/api_crud/src/site/update.rs:39
   1: lemmy_server::root_span_builder::HTTP request
           with http.method=PUT http.scheme="http" http.host=localhost:8536 http.target=/api/v3/site otel.kind="server" request_id=8b5f500e-228f-42fe-8c7d-6f9bca7c8d35 http.status_code=400 otel.status_code="OK"
             at src/root_span_builder.rs:16
LemmyError { message: Some("application_question_required"), inner: application_question_required, context: SpanTrace [{ target: "lemmy_api_crud::site::update", name: "perform", fields: "\u{1b}[3mself\u{1b}[0m\u{1b}[2m=\u{1b}[0mEditSite { name: None, sidebar: None, description: None, icon: None, banner: None, enable_downvotes: None, enable_nsfw: None, community_creation_admin_only: None, require_email_verification: None, application_question: None, private_instance: None, default_theme: None, default_post_listing_type: None, legal_information: None, application_email_admins: None, hide_modlog_mod_names: None, discussion_languages: None, slur_filter_regex: None, actor_name_max_length: None, rate_limit_message: Some(999), rate_limit_message_per_second: Some(60), rate_limit_post: Some(999), rate_limit_post_per_second: Some(600), rate_limit_register: Some(999), rate_limit_register_per_second: Some(3600), rate_limit_image: Some(999), rate_limit_image_per_second: Some(3600), rate_limit_comment: Some(999), rate_limit_comment_per_second: Some(600), rate_limit_search: Some(999), rate_limit_search_per_second: Some(600), federation_enabled: None, federation_debug: None, federation_worker_count: None, captcha_enabled: None, captcha_difficulty: None, allowed_instances: None, blocked_instances: None, taglines: None, registration_mode: None, reports_email_admins: None, auth: Sensitive }", file: "crates/api_crud/src/site/update.rs", line: 39 }, { target: "lemmy_server::root_span_builder", name: "HTTP request", fields: "\u{1b}[3mhttp.method\u{1b}[0m\u{1b}[2m=\u{1b}[0mPUT \u{1b}[3mhttp.scheme\u{1b}[0m\u{1b}[2m=\u{1b}[0m\"http\" \u{1b}[3mhttp.host\u{1b}[0m\u{1b}[2m=\u{1b}[0mlocalhost:8536 \u{1b}[3mhttp.target\u{1b}[0m\u{1b}[2m=\u{1b}[0m/api/v3/site \u{1b}[3motel.kind\u{1b}[0m\u{1b}[2m=\u{1b}[0m\"server\" \u{1b}[3mrequest_id\u{1b}[0m\u{1b}[2m=\u{1b}[0m8b5f500e-228f-42fe-8c7d-6f9bca7c8d35 \u{1b}[3mhttp.status_code\u{1b}[0m\u{1b}[2m=\u{1b}[0m400 \u{1b}[3motel.status_code\u{1b}[0m\u{1b}[2m=\u{1b}[0m\"OK\"", file: "src/root_span_builder.rs", line: 16 }] }

Version

BE 0.18.0

Lemmy Instance URL

No response

@kartikynwa kartikynwa added the bug Something isn't working label Jun 24, 2023
@kartikynwa
Copy link
Contributor Author

One thing I forgot to mention is that the instance needs to have been configured to require registration application but that is the default nowadays.

@kartikynwa
Copy link
Contributor Author

This is the fix I am using temporarily:

diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs
index 2a51309a4..8252e299a 100644
--- a/crates/api_crud/src/site/create.rs
+++ b/crates/api_crud/src/site/create.rs
@@ -81,6 +81,7 @@ impl PerformCrud for CreateSite {
       data
         .registration_mode
         .unwrap_or(local_site.registration_mode),
+      &local_site,
     )?;
 
     let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
diff --git a/crates/api_crud/src/site/mod.rs b/crates/api_crud/src/site/mod.rs
index d0c09b935..793a671eb 100644
--- a/crates/api_crud/src/site/mod.rs
+++ b/crates/api_crud/src/site/mod.rs
@@ -1,4 +1,4 @@
-use lemmy_db_schema::RegistrationMode;
+use lemmy_db_schema::{source::local_site::LocalSite, RegistrationMode};
 use lemmy_utils::error::LemmyError;
 
 mod create;
@@ -8,9 +8,11 @@ mod update;
 pub fn check_application_question(
   application_question: &Option<Option<String>>,
   registration_mode: RegistrationMode,
+  local_site: &LocalSite,
 ) -> Result<(), LemmyError> {
   if registration_mode == RegistrationMode::RequireApplication
     && application_question.as_ref().unwrap_or(&None).is_none()
+    && local_site.application_question.is_none()
   {
     Err(LemmyError::from_message("application_question_required"))
   } else {
diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs
index fadde0a0b..433126e0d 100644
--- a/crates/api_crud/src/site/update.rs
+++ b/crates/api_crud/src/site/update.rs
@@ -75,6 +75,7 @@ impl PerformCrud for EditSite {
       data
         .registration_mode
         .unwrap_or(local_site.registration_mode),
+      &local_site,
     )?;
 
     if let Some(listing_type) = &data.default_post_listing_type {

Feel free to suggest changes to it. I can file a PR after that.

@samifinge
Copy link

@kartikynwa I noticed that modifying Taglines also shows this same error. Does your current fix resolve that as well?

Like you mentioned, changing the registration setting is a workaround. Setting Registration Mode to Close Registration temporarily allows you to change both the rates and taglines.

Here is the error log for the tagline for reference.

LemmyError { message: Some("application_question_required"), inner: application_question_required, context: SpanTrace [{ target: "lemmy_api_crud::site::update", name: "perform", fields: "self=EditSite { name: None, sidebar: None, description: None, icon: None, banner: None, enable_downvotes: None, enable_nsfw: None, community_creation_admin_only: None, require_email_verification: None, application_question: None, private_instance: None, default_theme: None, default_post_listing_type: None, legal_information: None, application_email_admins: None, hide_modlog_mod_names: None, discussion_languages: None, slur_filter_regex: None, actor_name_max_length: None, rate_limit_message: None, rate_limit_message_per_second: None, rate_limit_post: None, rate_limit_post_per_second: None, rate_limit_register: None, rate_limit_register_per_second: None, rate_limit_image: None, rate_limit_image_per_second: None, rate_limit_comment: None, rate_limit_comment_per_second: None, rate_limit_search: None, rate_limit_search_per_second: None, federation_enabled: None, federation_debug: None, federation_worker_count: None, captcha_enabled: None, captcha_difficulty: None, allowed_instances: None, blocked_instances: None, taglines: Some([\"Welcome to Lemmy.zip!\"]), registration_mode: None, reports_email_admins: None

@kartikynwa
Copy link
Contributor Author

@samifinge Yeah it should fix that too. :)

@kartikynwa kartikynwa changed the title [Bug]: PUT requests to /site fail if application_question is not set in the data, even if the question has already been configured for the site [Bug]: PUT requests to /site fail if application_question is not provided, even if the question has already been configured for the site Jun 24, 2023
@Nutomic
Copy link
Member

Nutomic commented Jun 27, 2023

Please make a pull request.

@kartikynwa
Copy link
Contributor Author

Filed #3372

@Nutomic
Copy link
Member

Nutomic commented Jun 27, 2023

Was actually fixed in #3146

@Nutomic Nutomic closed this as completed Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants