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

FIX: Rely on core for staff action logs #176

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

pmusaraj
Copy link
Contributor

Previously, we were deleting the enable_topic_voting custom field param and doing the staff logging in this plugin. This has a problem though, it was being done in the model's create/destroy hooks and was missing the acting user (so the logs would report the change as system).

This PR keeps the custom field param and relies on core to do the staff action logging. This change also results in the custom field being set in the DB when it is enabled even though we don't use it in the serializer.

Previously, we were deleting the `enable_topic_voting` custom field param
and doing the staff logging in this plugin. This has a problem though, it
was being done in the model's create/destroy hooks and was missing the
acting user (so the logs would report the change as `system`).

This PR keeps the custom field param and relies on core to do the staff
action logging. This change also results in the custom field being set
in the DB when it is enabled even though we don't use it in the serializer.
@pmusaraj
Copy link
Contributor Author

@nattsw @renato can you give this a look please given your recent familiarity with the plugin?

@@ -4,7 +4,7 @@ module DiscourseTopicVoting
module CategoriesControllerExtension
def category_params
@vote_enabled ||=
!!ActiveRecord::Type::Boolean.new.cast(params[:custom_fields]&.delete(:enable_topic_voting))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this delete() here removes the parameter from the core controller, I guess it's because we don't want to store the custom field (because we have a separate table for the category/setting mappings) but it also means that it skips core's default handling for the staff action logger.

Keeping the enable_topic_voting param keeps the staff action logging from core, but it also stores a row in the category custom fields table for enable_topic_voting: true.

Copy link
Contributor

@renato renato Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this part of the code and I don't know the history of moving from the custom field, but I feel like if our best practice is having a separate table, we could have a better DX to be able to pass the value from the FE and logging the staff action without relying on a custom field.

But it's a bigger conversation, I don't think having the custom field row will cause any issue.

/cc @nattsw if you have any insights :)

@pmusaraj pmusaraj merged commit be71ec4 into main Dec 18, 2023
7 checks passed
@pmusaraj pmusaraj deleted the fix-staff-logging-for-category-custom-field branch December 18, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants