2016-08-02 17:21:57 -04:00
|
|
|
module SpammableActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :authorize_submit_spammable!, only: :mark_as_spam
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_as_spam
|
2016-08-09 13:43:47 -04:00
|
|
|
if SpamService.new(spammable).mark_as_spam!
|
|
|
|
redirect_to spammable, notice: "#{spammable.class.to_s} was submitted to Akismet successfully."
|
2016-08-02 17:21:57 -04:00
|
|
|
else
|
2016-08-09 13:43:47 -04:00
|
|
|
redirect_to spammable, alert: 'Error with Akismet. Please check the logs for more info.'
|
2016-08-02 17:21:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def spammable
|
2016-08-09 13:43:47 -04:00
|
|
|
raise NotImplementedError, "#{self.class} does not implement #{__method__}"
|
2016-08-02 17:21:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_submit_spammable!
|
|
|
|
access_denied! unless current_user.admin?
|
|
|
|
end
|
|
|
|
end
|