Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
DCP project
DCPv4
Commits
7eb70310
Commit
7eb70310
authored
Apr 22, 2022
by
Violet White
Committed by
Elizabeth Myers
Apr 22, 2022
Browse files
Listgroup command
parent
ebfd1e53
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
dcp/commands/__init__.py
dcp/commands/__init__.py
+3
-0
dcp/commands/listgroups.py
dcp/commands/listgroups.py
+38
-0
protodoc/dcpv4-rough-draft.md
protodoc/dcpv4-rough-draft.md
+9
-0
No files found.
dcp/commands/__init__.py
View file @
7eb70310
...
...
@@ -68,5 +68,8 @@ def init():
from
dcp.commands.messagedelete
import
MessageDelete
type_registry
[
MessageDelete
.
name
]
=
MessageDelete
()
from
dcp.commands.listgroups
import
ListGroups
type_registry
[
ListGroups
.
name
]
=
ListGroups
()
from
dcp.commands.quit
import
Quit
type_registry
[
Quit
.
name
]
=
Quit
()
dcp/commands/listgroups.py
0 → 100644
View file @
7eb70310
from
sqlalchemy.future
import
select
from
sqlalchemy.exc
import
NoResultFound
from
dcp.config
import
conf
from
dcp.db
import
(
StorageUser
,
StorageGroup
,
StorageGroupAcl
,
StorageGroupMember
,
StorageUserLine
,
StorageGroupLine
,
async_session
)
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"
print
(
frame
.
dst
)
if
len
(
frame
.
dst
)
>
1
:
target
=
frame
.
dst
if
target
!=
'user'
and
target
!=
'none'
:
raise
CommandError
(
f
"
{
target
}
is Invalid usage. Accepts user or none, for listing groups you are a member of, or all publicly listed groups on the server"
)
async
with
async_session
()
as
session
:
async
with
session
.
begin
():
if
target
==
'user'
:
stmt
=
(
select
(
StorageGroup
)
.
join
(
StorageGroupMember
,
StorageGroupMember
.
group_id
==
StorageGroup
.
id
)
.
where
(
StorageUser
.
username
==
client
.
username
))
else
:
stmt
=
(
select
(
StorageGroup
))
result
=
await
session
.
execute
(
stmt
)
reply
=
Frame
.
create
(
f
'@
{
client
.
username
}
'
,
frame
.
dst
,
'listgroups'
,
frame
.
related
,
{
'groups'
:[
i
.
StorageGroup
.
name
for
i
in
result
]})
await
sendto_user
(
client
.
username
,
reply
)
protodoc/dcpv4-rough-draft.md
View file @
7eb70310
...
...
@@ -125,6 +125,15 @@ Format:
See the Registration flow for more information.
### ```
listgroups
```
Client Format:
```
{... 'type': 'listgroups', 'dst':('user'|'group')}
```
Server Format:
```
{... 'type': 'listgroups', 'dst':('user'|'group'),'data':{'groups':[
<strings>
]}}
```
List the groups on the server when the destination is specified as `group` or not at all,
or the groups the user is a part of when `user` is specified.
### ```
login
```
Format:
Client: ```
{... 'type': 'login', 'data': {'auth': 'password', 'password':
<string>
}}
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment