core: added a base menu allowing to set encryption session or show the trust management UI.

This commit is contained in:
Goffi 2019-02-24 14:11:08 +01:00
commit d8f6620d00

View file

@ -17,12 +17,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from functools import partial
from sat.core.i18n import D_, _
from sat.core.constants import Const as C
from sat.core import exceptions
from collections import namedtuple
from sat.core.log import getLogger
from sat.tools.common import data_format
from twisted.words.protocols.jabber import jid
from twisted.internet import defer
from twisted.python import failure
import copy
@ -257,7 +259,7 @@ class EncryptionHandler(object):
"""Stop an encryption session with an entity
@param entity(jid.JID): entity with who the encryption session must be stopped
must be bare jid is the algorithm encrypt for all devices
must be bare jid if the algorithm encrypt for all devices
@param namespace(unicode): namespace of the session to stop
when specified, used to check we stop the right encryption session
"""
@ -357,6 +359,59 @@ class EncryptionHandler(object):
else:
return defer.maybeDeferred(get_trust_ui, self.client, entity_jid)
## Menus ##
@classmethod
def _importMenus(cls, host):
host.importMenu(
(D_(u"Encryption"), D_(u"unencrypted (plain text)")),
partial(cls._onMenuUnencrypted, host=host),
security_limit=0,
help_string=D_(u"End encrypted session"),
type_=C.MENU_SINGLE,
)
for plg in cls.getPlugins():
host.importMenu(
(D_(u"Encryption"), plg.name),
partial(cls._onMenuName, host=host, plg=plg),
security_limit=0,
help_string=D_(u"Start {name} session").format(name=plg.name),
type_=C.MENU_SINGLE,
)
host.importMenu(
(D_(u"Encryption"), D_(u"⛨ {name} trust").format(name=plg.name)),
partial(cls._onMenuTrust, host=host, plg=plg),
security_limit=0,
help_string=D_(u"Manage {name} trust").format(name=plg.name),
type_=C.MENU_SINGLE,
)
@classmethod
def _onMenuUnencrypted(cls, data, host, profile):
client = host.getClient(profile)
peer_jid = jid.JID(data[u'jid']).userhostJID()
d = client.encryption.stop(peer_jid)
d.addCallback(lambda __: {})
return d
@classmethod
def _onMenuName(cls, data, host, plg, profile):
client = host.getClient(profile)
peer_jid = jid.JID(data[u'jid'])
if not plg.directed:
peer_jid = peer_jid.userhostJID()
d = client.encryption.start(peer_jid, plg.namespace, replace=True)
d.addCallback(lambda __: {})
return d
@classmethod
@defer.inlineCallbacks
def _onMenuTrust(cls, data, host, plg, profile):
client = host.getClient(profile)
peer_jid = jid.JID(data[u'jid']).userhostJID()
ui = yield client.encryption.getTrustUI(peer_jid, plg.namespace)
defer.returnValue({u'xmlui': ui.toXml()})
## Triggers ##
def setEncryptionFlag(self, mess_data):