29th / personnel-v3

Personnel management system version 3
https://www.29th.org
2 stars 6 forks source link

Move logic out of ActiveAdmin resource callbacks #220

Open wilson29thid opened 7 months ago

wilson29thid commented 7 months ago

At the moment we have a few ActiveAdmin resources that perform actions after records are saved, e.g.

after_save do |user|
  if user.last_name_changed? or user.name_prefix_changed?
    user.update_forum_display_name
    user.update_coat
  end
end

But this is no good because ActiveAdmin has a bug where after_save is called even if the model isn't saved (say, because it's invalid). It's also probably not the right place for them anyway. They should probably be on the model's after_save hook or something.

Whilst we're at it, we can have the callback raise :abort if those third party API commands fail (when it makes sense to).