Commit 371cb00e authored by Elizabeth Myers's avatar Elizabeth Myers 💬
Browse files


parent 7d85e676
from sqlalchemy.future import select
from sqlalchemy.exc import NoResultFound
from dcp.config import conf
from dcp.db import (StorageUser,StorageGroup,StorageGroupAcl,
from dcp.db import (StorageUser, StorageGroup, StorageGroupAcl,
StorageGroupMember, StorageUserLine, StorageGroupLine,
from dcp.frame import Frame
from dcp.client import username_to_client
from dcp.send import sendto_user, sendto_group, filt_exclude_client
from dcp.commands import Command, CommandError
class ListGroups(Command):
name = 'listgroups'
async def pre_reg(self, _client, _frame):
raise CommandError('You have not identified')
async def reg(self, client, frame):
target = 'none'
if len(frame.dst)>1:
if len(frame.dst) > 1:
target = frame.dst
if target != 'user' and target != 'none':
raise CommandError(f'{target} is Invalid usage. Accepts user '
f'or none, for listing groups you are a '
......@@ -27,15 +29,17 @@ class ListGroups(Command):
async with async_session() as session:
async with session.begin():
if target == 'user':
stmt = (select(StorageGroup)
stmt = (
select(StorageGroup) .join(
StorageGroupMember.group_id == .where(
StorageUser.username == client.username))
stmt = (select(StorageGroup))
result = await session.execute(stmt)
reply = Frame.create(f'@{client.username}', frame.dst,
{'groups':[ for i in result]})
'listgroups', frame.related,
{'groups': [ for i in result]})
await sendto_user(client.username,reply)
await sendto_user(client.username, reply)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment