mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-23 13:51:15 -05:00
ui: Allow devices to be unverified over the dbus API.
This commit is contained in:
parent
2ae5e181bc
commit
daacd340f9
@ -25,7 +25,12 @@ from nio import EncryptionError, GroupEncryptionError, LoginResponse
|
||||
from pantalaimon.client import PanClient
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import ClientInfo, PanStore
|
||||
from pantalaimon.ui import glib_loop, shutdown_glib_loop, DeviceVerifyMessage
|
||||
from pantalaimon.ui import (
|
||||
glib_loop,
|
||||
shutdown_glib_loop,
|
||||
DeviceVerifyMessage,
|
||||
DeviceUnverifyMessage
|
||||
)
|
||||
|
||||
|
||||
@attr.s
|
||||
@ -89,11 +94,36 @@ class ProxyDaemon:
|
||||
loop = asyncio.get_event_loop()
|
||||
self.queue_task = loop.create_task(self.queue_loop())
|
||||
|
||||
def _verify_device(self, client, device):
|
||||
ret = client.verify_device(device)
|
||||
|
||||
if ret:
|
||||
logger.info(f"Device {device.id} of user "
|
||||
f"{device.user_id} succesfully verified")
|
||||
else:
|
||||
logger.info(f"Device {device.id} of user "
|
||||
f"{device.user_id} already verified")
|
||||
pass
|
||||
|
||||
def _unverify_device(self, client, device):
|
||||
ret = client.unverify_device(device)
|
||||
|
||||
if ret:
|
||||
logger.info(f"Device {device.id} of user "
|
||||
f"{device.user_id} succesfully unverified")
|
||||
else:
|
||||
logger.info(f"Device {device.id} of user "
|
||||
f"{device.user_id} already unverified")
|
||||
|
||||
async def queue_loop(self):
|
||||
while True:
|
||||
message = await self.recv_queue.get()
|
||||
logger.debug(f"Daemon got message {message}")
|
||||
|
||||
if isinstance(message, DeviceVerifyMessage):
|
||||
if isinstance(
|
||||
message,
|
||||
(DeviceVerifyMessage, DeviceUnverifyMessage)
|
||||
):
|
||||
client = self.pan_clients.get(message.pan_user, None)
|
||||
|
||||
if not client:
|
||||
@ -107,14 +137,10 @@ class ProxyDaemon:
|
||||
if not device:
|
||||
return
|
||||
|
||||
ret = client.verify_device(device)
|
||||
|
||||
if ret:
|
||||
logger.info(f"Device {message.device_id} of user "
|
||||
f"{message.user_id} succesfully verified")
|
||||
if isinstance(message, DeviceVerifyMessage):
|
||||
self._verify_device(client, device)
|
||||
else:
|
||||
logger.info(f"Device {message.device_id} of user "
|
||||
f"{message.user_id} already verified")
|
||||
self._unverify_device(client, device)
|
||||
|
||||
def get_access_token(self, request):
|
||||
# type: (aiohttp.web.BaseRequest) -> str
|
||||
|
@ -31,12 +31,22 @@ class DevicesMessage(Message):
|
||||
|
||||
|
||||
@attr.s
|
||||
class DeviceVerifyMessage(Message):
|
||||
class _VerificationMessage(Message):
|
||||
pan_user = attr.ib()
|
||||
user_id = attr.ib()
|
||||
device_id = attr.ib()
|
||||
|
||||
|
||||
@attr.s
|
||||
class DeviceVerifyMessage(_VerificationMessage):
|
||||
pass
|
||||
|
||||
|
||||
@attr.s
|
||||
class DeviceUnverifyMessage(_VerificationMessage):
|
||||
pass
|
||||
|
||||
|
||||
class Devices(dbus.service.Object):
|
||||
def __init__(self, bus_name, queue, device_list):
|
||||
super().__init__(bus_name, "/org/pantalaimon/Devices")
|
||||
@ -51,15 +61,18 @@ class Devices(dbus.service.Object):
|
||||
@dbus.service.method("org.pantalaimon.devices.verify",
|
||||
in_signature="sss")
|
||||
def verify(self, pan_user, user_id, device_id):
|
||||
device_store = self.device_list.get(pan_user)
|
||||
|
||||
if not device_store:
|
||||
logger.debug(f"Not verifying device, no store found for user "
|
||||
f"{pan_user}")
|
||||
message = DeviceVerifyMessage(
|
||||
pan_user,
|
||||
user_id,
|
||||
device_id
|
||||
)
|
||||
self.queue.put(message)
|
||||
return
|
||||
|
||||
logger.debug(f"Verifying device {user_id} {device_id}")
|
||||
message = DeviceVerifyMessage(
|
||||
@dbus.service.method("org.pantalaimon.devices.unverify",
|
||||
in_signature="sss")
|
||||
def unverify(self, pan_user, user_id, device_id):
|
||||
message = DeviceUnverifyMessage(
|
||||
pan_user,
|
||||
user_id,
|
||||
device_id
|
||||
|
Loading…
Reference in New Issue
Block a user