🐛 Introduce ClientAuthed event
May act as entry point for any kind of push messages a plugin might wish to send to the client after a connect happened. Since depending on the current permission configuration this might only be possible once the client has authenticated on the socket, this is required. Should close #3400
This commit is contained in:
1 parent
8d31d6687e
commit
1d0829a1db
3 files changed
+21
-4
No files matched your search
@@ -46,6 +46,8 @@ class Events(object):
|
||||
# connect/disconnect by client
|
||||
CLIENT_OPENED = "ClientOpened"
|
||||
CLIENT_CLOSED = "ClientClosed"
|
||||
CLIENT_AUTHED = "ClientAuthed"
|
||||
CLIENT_DEAUTHED = "ClientDeauthed"
|
||||
|
||||
# user login/logout
|
||||
USER_LOGGED_IN = "UserLoggedIn"
|
||||
|
||||
@@ -78,6 +78,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
|
||||
"*": []}
|
||||
|
||||
_event_payload_processors = {Events.CLIENT_OPENED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()],
|
||||
Events.CLIENT_AUTHED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()],
|
||||
"*": []}
|
||||
|
||||
_emit_permissions = {"connected": [],
|
||||
@@ -436,6 +437,10 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
|
||||
self._logger.exception("Error processing authed hook handler for plugin {}".format(name),
|
||||
extra=dict(plugin=name))
|
||||
|
||||
octoprint.events.eventManager().fire(octoprint.events.Events.CLIENT_AUTHED,
|
||||
payload=dict(username=user.get_name(),
|
||||
remoteAddress=self._remoteAddress))
|
||||
|
||||
def _on_logout(self):
|
||||
self._user = self._userManager.anonymous_user_factory()
|
||||
|
||||
|
||||
Reference in new issue
Block a user