I've been asked on Discord how a custom plugin can be ran after posting action (starting new thread, posting a response, etc. ect.).
Misago 0.39 uses a system of classes implementing functions that are called at different stages of posting process. Those classes are named "posting middlewares". You can find those in misago.threads.api.postingendpoint
directories, but in this post I'll provide basic information for running custom Python code after one starts new thread or posts new reply.
Assuming you've already created a blank plugin, next step is to create postingmiddleware.py
file in it, and implement your basic middleware:
from misago.threads.api.postingendpoint import PostingEndpoint, PostingMiddleware
class PluginMiddleware(PostingMiddleware):
def use_this_middleware(self):
# Disable this middleware for edit actions
return self.mode != PostingEndpoint.EDIT
def post_save(self, serializer):
if self.mode == PostingEndpoint.START:
# run some code when user starts a thread...
...
elif self.mode == PostingEndpoint.REPLY:
# run some code when user posts a reply....
...
Posting middlewares are initialized with following attributes:
self.mode
: anint
with a mode of posting action (START/REPLY/EDIT)self.request
: theHttpRequest
instanceself.category
: theCategory
instanceself.thread
: theThread
instanceself.post
: thePost
instanceself.user
: theUser
instanceself.user_acl
: user's permissions
There is no plugin hook in Misago that plugin can hook up custom posting Middleware in. But if you are using misago-docker
, you can override the configuration by creating settings_override.py
file in right place. See the documentation for more information.
Here's Misago 0.39 MISAGO_POSTING_MIDDLEWARES
setting:
MISAGO_POSTING_MIDDLEWARES = [
# Always keep FloodProtectionMiddleware middleware first one
"misago.threads.api.postingendpoint.floodprotection.FloodProtectionMiddleware",
"misago.threads.api.postingendpoint.category.CategoryMiddleware",
"misago.threads.api.postingendpoint.privatethread.PrivateThreadMiddleware",
"misago.threads.api.postingendpoint.reply.ReplyMiddleware",
"misago.threads.api.postingendpoint.moderationqueue.ModerationQueueMiddleware",
"misago.threads.api.postingendpoint.attachments.AttachmentsMiddleware",
"misago.threads.api.postingendpoint.participants.ParticipantsMiddleware",
"misago.threads.api.postingendpoint.pin.PinMiddleware",
"misago.threads.api.postingendpoint.close.CloseMiddleware",
"misago.threads.api.postingendpoint.hide.HideMiddleware",
"misago.threads.api.postingendpoint.protect.ProtectMiddleware",
"misago.threads.api.postingendpoint.recordedit.RecordEditMiddleware",
"misago.threads.api.postingendpoint.updatestats.UpdateStatsMiddleware",
"misago.threads.api.postingendpoint.mentions.MentionsMiddleware",
"misago.threads.api.postingendpoint.syncprivatethreads.SyncPrivateThreadsMiddleware",
# Always keep SaveChangesMiddleware middleware after all state-changing middlewares
"misago.threads.api.postingendpoint.savechanges.SaveChangesMiddleware",
# Those middlewares are last because they don't change app state
"misago.threads.api.postingendpoint.notifications.NotificationsMiddleware",
]
You can paste this code in your settings_override.py
. You should then update it by adding a new entry with path to your plugin's posting middleware at the end.