Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pretix Matrix Inviter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIF
Pretix Matrix Inviter
Commits
3bca31b8
Commit
3bca31b8
authored
3 years ago
by
Felix Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
Allow using an alias instead of a room ID
parent
d614b8f9
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!5
Allow using room aliases
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pretix_matrix_inviter/forms.py
+1
-1
1 addition, 1 deletion
pretix_matrix_inviter/forms.py
pretix_matrix_inviter/helpers.py
+20
-0
20 additions, 0 deletions
pretix_matrix_inviter/helpers.py
pretix_matrix_inviter/tasks.py
+11
-9
11 additions, 9 deletions
pretix_matrix_inviter/tasks.py
with
32 additions
and
10 deletions
pretix_matrix_inviter/forms.py
+
1
−
1
View file @
3bca31b8
...
...
@@ -23,7 +23,7 @@ class MatrixInviterForm(SettingsForm):
)
matrix_inviter_matrix_room
=
forms
.
RegexField
(
label
=
_
(
"
Matrix room
"
),
regex
=
"
!
[^:]+:.+
"
,
regex
=
"
(!|#)
[^:]+:.+
"
,
strip
=
True
,
)
matrix_inviter_hint
=
I18nFormField
(
...
...
This diff is collapsed.
Click to expand it.
pretix_matrix_inviter/helpers.py
0 → 100644
+
20
−
0
View file @
3bca31b8
import
requests
from
urllib.parse
import
quote
as
url_quote
def
matrix_room_id
(
server
,
room_id_or_alias
):
if
room_id_or_alias
.
startswith
(
"
!
"
):
return
room_id_or_alias
else
:
return
matrix_room_id_from_alias
(
server
,
room_id_or_alias
)
def
matrix_room_id_from_alias
(
server
,
alias
):
r
=
requests
.
get
(
"
https://{}/_matrix/client/v3/directory/room/{}
"
.
format
(
url_quote
(
server
),
url_quote
(
alias
),
),
)
return
r
.
json
().
get
(
"
room_id
"
)
This diff is collapsed.
Click to expand it.
pretix_matrix_inviter/tasks.py
+
11
−
9
View file @
3bca31b8
...
...
@@ -6,6 +6,8 @@ from pretix.base.services.tasks import TransactionAwareTask
from
pretix.celery_app
import
app
from
urllib.parse
import
quote
as
url_quote
from
.helpers
import
matrix_room_id
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -30,7 +32,9 @@ def matrix_inviter_invite(
event
=
Event
.
objects
.
get
(
pk
=
event
)
order
=
Order
.
objects
.
get
(
pk
=
order
)
room_matrix_id
=
event
.
settings
.
matrix_inviter_matrix_room
server
=
event
.
settings
.
matrix_inviter_matrix_server
token
=
event
.
settings
.
matrix_inviter_authorization_token
room_id
=
matrix_room_id
(
server
,
event
.
settings
.
matrix_inviter_matrix_room
)
payload
=
{
"
user_id
"
:
user_matrix_id
}
if
invitation_reason
:
payload
[
"
reason
"
]
=
invitation_reason
...
...
@@ -38,13 +42,11 @@ def matrix_inviter_invite(
try
:
r
=
requests
.
post
(
"
https://{}/_matrix/client/v3/rooms/{}/invite
"
.
format
(
url_quote
(
event
.
settings
.
matrix_inviter_matrix_
server
),
url_quote
(
room_
matrix_
id
),
url_quote
(
server
),
url_quote
(
room_id
),
),
headers
=
{
"
Authorization
"
:
"
Bearer {}
"
.
format
(
event
.
settings
.
matrix_inviter_authorization_token
),
"
Authorization
"
:
"
Bearer {}
"
.
format
(
token
),
},
json
=
payload
,
)
...
...
@@ -55,7 +57,7 @@ def matrix_inviter_invite(
"
pretix_matrix_inviter.error
"
,
data
=
{
"
matrix_id
"
:
user_matrix_id
,
"
matrix_room
"
:
room_
matrix_
id
,
"
matrix_room
"
:
room_id
,
"
error
"
:
"
HTTP Code {} ({})
"
.
format
(
r
.
status_code
,
r
.
json
()[
"
error
"
]
),
...
...
@@ -73,7 +75,7 @@ def matrix_inviter_invite(
"
pretix_matrix_inviter.error
"
,
data
=
{
"
matrix_id
"
:
user_matrix_id
,
"
matrix_room
"
:
room_
matrix_
id
,
"
matrix_room
"
:
room_id
,
"
error
"
:
"
HTTP Code {}
"
.
format
(
r
.
status_code
),
},
)
...
...
@@ -83,6 +85,6 @@ def matrix_inviter_invite(
"
pretix_matrix_inviter.invite_sent
"
,
data
=
{
"
matrix_id
"
:
user_matrix_id
,
"
matrix_room
"
:
room_
matrix_
id
,
"
matrix_room
"
:
room_id
,
},
)
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