Bump Reset plugin - Annotated to help new devs

(Leo Davidson) #1

This plugin may be interesting to both Discourse admins and people learning how to write Discourse plugins. I’ve given each audience separate sections below.

For Discourse admins:

This plugin gives staff members a button to quickly reset a thread’s bump time to the original time of any post within the thread. The button is added to the admin menu (spanner icon) for each post:

This is useful if you make minor edits to the last post and don’t want the thread bumped or if the wrong person/post are currently marked as the latest in the thread due to a delete or un-delete of a later post.

The plugin doesn’t really let you do anything you could not do already (other than repairing the last post/poster if they go wrong), it just lets you do things more conveniently. The ability to change the timestamp of a thread is built in to Discourse, but the UI for doing so is modal and requires you to separately select the date and time. You can only see the detailed date and time of a post in another modal UI, and cannot copy and paste between the two UIs as they use different formats.

Each use of the Reset Bump To Here button will be logged in the Discourse staff actions log, including the topic and post IDs and URL, and old and new timestamps:

This can help detect abuse of the functionality (e.g. to hide new posts from other admins, rather than the intended use of avoiding bumps when making formatting-only fixes to old threads, or undoing a user’s gratuitous bump without deleting their message entirely).


The plugin is on github as usual: GitHub - LeoDavidson/discourse-reset-bump: A Discourse plugin to quickly reset a thread's bump time to that of a post in the thread.

Follow the Install a Plugin howto, using git clone https://github.com/leodavidson/discourse-reset-bump.git as the plugin command.

Once you’ve installed it, it will be enabled by default and can be disabled under the site’s admin / plugin settings area, via the reset_bump_enabled checkbox.

For new plugin developers:

  • The source code is simple, since what the plugin does is simple.
  • The code is extensively commented. Comments far outweigh code.
  • All logic is in just 2 files (1 client side, 1 server side).
  • I unpacked inline functions into normal top-level functions so you can more easily see the structure of things, and only have to deal with one concept at a time.

This is the first Discourse plugin I’ve written, the first Ruby (let alone Ruby on Rails), and the first time I’ve used Javascript as more than a stand-in for simple VBScript. I’ve got years of C++ and C# experience but found this a steep learning curve (but quite nice in the end). My aim was to properly understand what I was doing and to document the hows and whys to help the next person.

I’m still fuzzy on some concepts but I hope I got the important details right. Corrections to code or comments greatly appreciated.

In terms of what the plugin does:

  • Standard enable/disable setting.
  • Client side uses the newer withPluginApi initialization method.
  • Adds a button to the post admin menu (pictured above) below each post.
  • (Also has commented-out code showing how to add to the main post buttons, outside the menu.)
  • Client side checks for staff privileges (so the UI isn’t shown to people who can’t use it).
  • Button click triggers AJAX request to the server side.
  • Server side checks for staff privileges (can’t rely on client for that; it can be bypassed).
  • Server side checks the plugin is enabled (so if a security issue was found, the AJAX endpoint can be stubbed out quickly without having to restart the server).
  • Server side takes the post ID from the client and looks up the topic details (or returns an error for the client to display).
  • Server side updates the database records of the topic accordingly, and returns success if it worked.
  • Server side logs the action to the staff action log. (Working out the right place for the i18n translated action string was tricky here.)

All easy once you know how, but as a newbie it took me days of unravelling source code, (outdated) forum threads, multiple unfamiliar languages and frameworks, which was quite overwhelming.

I also recommend looking at other plugins to see how you can write things in a “nicer” (or at least more compact!) way once you understand what’s going on. This one’s code is meant to be easy to understand and not necessarily the “best” way to do things.

I hope it helps you!

No-bump for admin edits on first and only post in a topic

I installed the plugin and am able to see the enable/disable setting, but … no button in the post adminstration :confused:

Using Discourse v1.7.2 +2

(Leo Davidson) #3

It’ll probably only work in Discourse 1.8.0 and above as I set the API version to the latest (since it’s the only one I’ve tested with).

Changing the withApi… 0.7 line to 0.6 near the bottom of the .es6 file might make things work, but hasn’t been tested. I might be depending on changes in the latest Discourse.


Okay, good to know! I’ll test it out on my development machine

(Colin Marshall) #5

This plugin is coming in very handy for a migrated forum that has a ton of formatting/editing that needs to be done on old topics/posts. Thank you!

An added feature that might come in handy to make things even more efficient, is to add an option “Reset bump to last post” when you are bulk selecting topics in a topic listing view. That way I could just go to the Latest view and pick through all recently edited posts to bump them all back to where they were in one action.