core: method to know if a profile/entity is an admin:
the new `is_admin` SatXMPPEntity property tell if it's an administrator. Admin JIDs are retrieve on init, so they can be looked after when profle is not available (notably when a component handle a request and has only a JID available). The new `memory.isAdminJID` method is then used.
This commit is contained in:
parent
9564647b21
commit
c8025a52eb
2 changed files with 44 additions and 0 deletions
|
|
@ -939,6 +939,10 @@ class SAT(service.Service):
|
|||
return False
|
||||
return self.profiles[profile].isConnected()
|
||||
|
||||
def isAdmin(self, client: xmpp.SatXMPPEntity) -> bool:
|
||||
"""Tells if a client is an administrator with extra privileges"""
|
||||
return client.profile in self.memory.admins
|
||||
|
||||
## Encryption ##
|
||||
|
||||
def registerEncryptionPlugin(self, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -600,6 +600,11 @@ class SatXMPPEntity(core_types.SatXMPPEntity):
|
|||
post_xml_treatments.callback(data)
|
||||
return data
|
||||
|
||||
@property
|
||||
def is_admin(self) -> bool:
|
||||
"""True if a client is an administrator with extra privileges"""
|
||||
return self.host_app.memory.isAdmin(self.profile)
|
||||
|
||||
def addPostXmlCallbacks(self, post_xml_treatments):
|
||||
"""Used to add class level callbacks at the end of the workflow
|
||||
|
||||
|
|
@ -1009,6 +1014,10 @@ class SatXMPPComponent(SatXMPPEntity, component.Component):
|
|||
# FIXME: not the best way to get server jid, maybe use config option?
|
||||
return jid.JID(self.jid.host.split(".", 1)[-1])
|
||||
|
||||
@property
|
||||
def is_admin(self) -> bool:
|
||||
return False
|
||||
|
||||
def _buildDependencies(self, current, plugins, required=True):
|
||||
"""build recursively dependencies needed for a plugin
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue