Project

General

Profile

Plugin Dev - Add a transient field to a model (Issue, in this case)

Added by Nick Peelman over 6 years ago

Quick Background:

We are using the Redmine Slack plugin to send notifications into Slack.

I extended the plugin to include "quiet hours" so that basically notifications only get sent during "business hours", Mon-Fri. Basically we don't want to get spammed after hours if one of us is updating tickets while in a maintenance window or something.

What I would like to do is extend the plugin slightly more to include a "Send to Slack" checkbox on each issue form (both new and updates) that is checked by default, but lets you uncheck it to "mute" the notification when you don't want to alert the channel (effectively this would supersede my "quiet hours" and let you decide per-update if you want to send to the channel or not).

This seems like an easy thing; I thought I'd just generate a monkey patch for the Issue model, adding an `attr_accessor :send_slack_notification` to the class, calling `safe_attributes :send_slack_notification` and bob's your uncle. I'd be able to add a checkbox for that value at the bottom of each form through a Partial, and it would exist in the context of the object for that instance, but not but a persistent, wouldn't require a database migration, etc. I could catch it on the `post_save` hook (which we are already using to send the notifications now), and use it in the logic that determines when a notification could be sent.

buuuut this doesn't work. The patch doesn't ever seem to land successfully. This may be caused by me not having written a plugin in 4-5 years and being rusty and/or things being changed in that timeframe. Anybody have a working example of accomplishing something like this? Essentially adding a transient (or whatever adjective you want to use to describe something that doesn't save) attribute to a model, but is available during the issue CRUD workflow.


    (1-1/1)