Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Matrix
Commits
2a429deb
Verified
Commit
2a429deb
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Move matrix util functions to util namespace
parent
9f7d4071
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Resolve "Review tasks"
Pipeline
#55919
canceled
3 years ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/matrix/models.py
+8
-7
8 additions, 7 deletions
aleksis/apps/matrix/models.py
aleksis/apps/matrix/tests/test_matrix.py
+6
-11
6 additions, 11 deletions
aleksis/apps/matrix/tests/test_matrix.py
aleksis/apps/matrix/util/matrix.py
+0
-0
0 additions, 0 deletions
aleksis/apps/matrix/util/matrix.py
with
14 additions
and
18 deletions
aleksis/apps/matrix/models.py
+
8
−
7
View file @
2a429deb
...
...
@@ -6,11 +6,12 @@ from django.db.models import Q
from
django.template.defaultfilters
import
slugify
from
django.utils.translation
import
gettext_lazy
as
_
from
aleksis.apps.matrix.matrix
import
do_matrix_request
from
aleksis.core.mixins
import
ExtensibleModel
,
ExtensiblePolymorphicModel
from
aleksis.core.models
import
Group
,
Person
from
aleksis.core.util.core_helpers
import
get_site_preferences
from
.util.matrix
import
do_matrix_request
class
MatrixProfile
(
ExtensibleModel
):
"""
Model for a Matrix profile.
"""
...
...
@@ -73,7 +74,7 @@ class MatrixRoom(ExtensiblePolymorphicModel):
@classmethod
def
from_group
(
cls
,
group
:
Group
)
->
"
MatrixRoom
"
:
"""
Create a Matrix room from a group.
"""
from
.matrix
import
MatrixException
,
do_matrix_request
from
.util
.matrix
import
MatrixException
,
do_matrix_request
try
:
room
=
cls
.
get_queryset
().
get
(
group
=
group
)
...
...
@@ -126,7 +127,7 @@ class MatrixRoom(ExtensiblePolymorphicModel):
invite
:
Optional
[
List
[
str
]]
=
None
,
creation_content
:
Optional
[
dict
]
=
None
,
)
->
Dict
[
str
,
Any
]:
from
.matrix
import
do_matrix_request
from
.util
.matrix
import
do_matrix_request
body
=
{
"
preset
"
:
"
private_chat
"
,
"
name
"
:
name
,
"
room_alias_name
"
:
alias
}
...
...
@@ -143,7 +144,7 @@ class MatrixRoom(ExtensiblePolymorphicModel):
@property
def
power_levels
(
self
)
->
Dict
[
str
,
int
]:
"""
Return the power levels for this room.
"""
from
aleksis.apps.matrix
.matrix
import
do_matrix_request
from
.util
.matrix
import
do_matrix_request
r
=
do_matrix_request
(
"
GET
"
,
f
"
rooms/
{
self
.
room_id
}
/state
"
)
...
...
@@ -154,7 +155,7 @@ class MatrixRoom(ExtensiblePolymorphicModel):
@property
def
members
(
self
)
->
List
[
str
]:
from
aleksis.apps.matrix
.matrix
import
do_matrix_request
from
.util
.matrix
import
do_matrix_request
r
=
do_matrix_request
(
"
GET
"
,
f
"
rooms/
{
self
.
room_id
}
/members
"
,
body
=
{
"
membership
"
:
[
"
join
"
,
"
invite
"
]}
...
...
@@ -163,7 +164,7 @@ class MatrixRoom(ExtensiblePolymorphicModel):
def
_invite
(
self
,
profile
:
MatrixProfile
)
->
Dict
[
str
,
Any
]:
"""
Invite a user to this room.
"""
from
aleksis.apps.matrix
.matrix
import
do_matrix_request
from
.util
.matrix
import
do_matrix_request
r
=
do_matrix_request
(
"
POST
"
,
...
...
@@ -280,7 +281,7 @@ class MatrixSpace(MatrixRoom):
@property
def
child_spaces
(
self
)
->
List
[
str
]:
"""
Get all child spaces of this space.
"""
from
aleksis.apps.matrix
.matrix
import
do_matrix_request
from
.util
.matrix
import
do_matrix_request
r
=
do_matrix_request
(
"
GET
"
,
f
"
rooms/
{
self
.
room_id
}
/state
"
)
return
[
c
[
"
state_key
"
]
for
c
in
r
if
c
[
"
type
"
]
==
"
m.space.child
"
]
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/matrix/tests/test_matrix.py
+
6
−
11
View file @
2a429deb
...
...
@@ -7,8 +7,13 @@ import pytest
import
requests
from
celery.result
import
AsyncResult
from
aleksis.apps.matrix.matrix
import
do_matrix_request
from
aleksis.apps.matrix.models
import
MatrixProfile
,
MatrixRoom
,
MatrixSpace
from
aleksis.apps.matrix.util.matrix
import
(
MatrixException
,
build_url
,
do_matrix_request
,
get_headers
,
)
from
aleksis.core.models
import
Group
,
Person
,
SchoolTerm
from
aleksis.core.util.core_helpers
import
get_site_preferences
...
...
@@ -27,8 +32,6 @@ def test_connection(synapse):
@pytest.fixture
def
matrix_bot_user
(
synapse
):
from
aleksis.apps.matrix.matrix
import
build_url
body
=
{
"
username
"
:
"
aleksis-bot
"
,
"
password
"
:
"
test
"
,
"
auth
"
:
{
"
type
"
:
"
m.login.dummy
"
}}
get_site_preferences
()[
"
matrix__homeserver
"
]
=
SERVER_URL
...
...
@@ -52,8 +55,6 @@ def test_matrix_bot_user(matrix_bot_user):
def
test_create_room_for_group
(
matrix_bot_user
):
from
aleksis.apps.matrix.matrix
import
build_url
,
get_headers
g
=
Group
.
objects
.
create
(
name
=
"
Test Room
"
)
assert
not
MatrixRoom
.
objects
.
all
().
exists
()
room
=
MatrixRoom
.
from_group
(
g
)
...
...
@@ -79,8 +80,6 @@ def test_create_room_for_group_short_name(matrix_bot_user):
def
test_room_alias_collision_same_name
(
matrix_bot_user
):
from
aleksis.apps.matrix.matrix
import
MatrixException
g1
=
Group
.
objects
.
create
(
name
=
"
Test Room
"
)
g2
=
Group
.
objects
.
create
(
name
=
"
test-room
"
)
g3
=
Group
.
objects
.
create
(
name
=
"
Test-Room
"
)
...
...
@@ -123,8 +122,6 @@ def test_room_alias_collision_school_term(matrix_bot_user):
def
test_sync_room_members
(
matrix_bot_user
):
from
aleksis.apps.matrix.matrix
import
build_url
,
get_headers
get_site_preferences
()[
"
matrix__homeserver_ids
"
]
=
"
matrix.aleksis.example.org
"
g
=
Group
.
objects
.
create
(
name
=
"
Test Room
"
)
...
...
@@ -235,8 +232,6 @@ def test_sync_room_members_without_homeserver(matrix_bot_user):
def
test_use_room_sync
(
matrix_bot_user
):
from
aleksis.apps.matrix.matrix
import
build_url
,
get_headers
get_site_preferences
()[
"
matrix__homeserver_ids
"
]
=
"
matrix.aleksis.example.org
"
g
=
Group
.
objects
.
create
(
name
=
"
Test Room
"
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/matrix/matrix.py
→
aleksis/apps/matrix/
util/
matrix.py
+
0
−
0
View file @
2a429deb
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment