mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-02-19 07:41:18 +00:00
Compare commits
No commits in common. "b33723efb336239eaef6d55c79b4f95983250e3e" and "642ac94b7a3bb8ee7ba60d7fbc839eef4fbe5448" have entirely different histories.
b33723efb3
...
642ac94b7a
@ -2,7 +2,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from nio import RoomVisibility, RoomPreset
|
|
||||||
|
|
||||||
from corres2math.lists import get_sympa_client
|
from corres2math.lists import get_sympa_client
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
@ -15,8 +14,6 @@ from django.utils.crypto import get_random_string
|
|||||||
from django.utils.text import format_lazy
|
from django.utils.text import format_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from corres2math.matrix import Matrix
|
|
||||||
|
|
||||||
|
|
||||||
class Team(models.Model):
|
class Team(models.Model):
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
@ -66,13 +63,6 @@ class Team(models.Model):
|
|||||||
self.access_code = get_random_string(6)
|
self.access_code = get_random_string(6)
|
||||||
self.create_mailing_list()
|
self.create_mailing_list()
|
||||||
|
|
||||||
Matrix.create_room(
|
|
||||||
visibility=RoomVisibility.private,
|
|
||||||
alias=f"team-{self.trigram.lower()}",
|
|
||||||
topic=f"Discussion de l'équipe {self.name}",
|
|
||||||
preset=RoomPreset.private_chat,
|
|
||||||
)
|
|
||||||
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from cas_server.auth import DjangoAuthUser
|
from cas_server.auth import DjangoAuthUser
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
|
|
||||||
class CustomAuthUser(DjangoAuthUser):
|
class CustomAuthUser(DjangoAuthUser):
|
||||||
@ -9,6 +10,5 @@ class CustomAuthUser(DjangoAuthUser):
|
|||||||
def attributs(self):
|
def attributs(self):
|
||||||
d = super().attributs()
|
d = super().attributs()
|
||||||
if self.user:
|
if self.user:
|
||||||
d["matrix_username"] = f"corres2math_{self.user.pk}"
|
d["matrix_username"] = slugify(str(self.user.registration))
|
||||||
d["display_name"] = str(self.user.registration)
|
|
||||||
return d
|
return d
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"model": "cas_server.servicepattern",
|
"model": "cas_server.servicepattern",
|
||||||
"pk": 1,
|
"pk": 1,
|
||||||
"fields": {
|
"fields": {
|
||||||
"pos": 100,
|
"pos": 100,
|
||||||
"name": "Plateforme des Correspondances",
|
"name": "Plateforme des Correspondances",
|
||||||
"pattern": "^https://correspondances-maths.fr:8448/.*$",
|
"pattern": "^https://correspondances-maths.fr:8448/.*$",
|
||||||
"user_field": "matrix_username",
|
"user_field": "matrix_username",
|
||||||
"restrict_users": false,
|
"restrict_users": false,
|
||||||
"proxy": true,
|
"proxy": true,
|
||||||
"proxy_callback": true,
|
"proxy_callback": true,
|
||||||
"single_log_out": true,
|
"single_log_out": true,
|
||||||
"single_log_out_callback": ""
|
"single_log_out_callback": ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
from typing import Any, Dict, Optional, Union
|
|
||||||
|
|
||||||
from nio import AsyncClient, RoomCreateError, RoomCreateResponse, RoomInviteError, RoomInviteResponse, RoomPreset, \
|
|
||||||
RoomVisibility
|
|
||||||
|
|
||||||
|
|
||||||
class Matrix:
|
|
||||||
@classmethod
|
|
||||||
def _get_client(cls) -> AsyncClient:
|
|
||||||
if hasattr(cls, "_client"):
|
|
||||||
return cls._client
|
|
||||||
|
|
||||||
async def login():
|
|
||||||
cls._client = AsyncClient("https://correspondances-maths.fr", "@corres2mathbot:correspondances-maths.fr")
|
|
||||||
await cls._client.login("toto1234")
|
|
||||||
return cls._client
|
|
||||||
return asyncio.get_event_loop().run_until_complete(login())
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create_room(
|
|
||||||
cls,
|
|
||||||
visibility: RoomVisibility = RoomVisibility.private,
|
|
||||||
alias: Optional[str] = None,
|
|
||||||
name: Optional[str] = None,
|
|
||||||
topic: Optional[str] = None,
|
|
||||||
room_version: Optional[str] = None,
|
|
||||||
federate: bool = True,
|
|
||||||
is_direct: bool = False,
|
|
||||||
preset: Optional[RoomPreset] = None,
|
|
||||||
invite=(),
|
|
||||||
initial_state=(),
|
|
||||||
power_level_override: Optional[Dict[str, Any]] = None,
|
|
||||||
) -> Union[RoomCreateResponse, RoomCreateError]:
|
|
||||||
resp: Union[RoomCreateResponse, RoomCreateError]
|
|
||||||
|
|
||||||
return asyncio.get_event_loop().run_until_complete(cls._get_client().room_create(
|
|
||||||
visibility, alias, name, topic, room_version, federate, is_direct, preset, invite, initial_state,
|
|
||||||
power_level_override))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def invite(cls, room_id: str, user_id: str) -> Union[RoomInviteResponse, RoomInviteError]:
|
|
||||||
return asyncio.get_event_loop().run_until_complete(cls._get_client().room_invite(room_id, user_id))
|
|
@ -3,15 +3,14 @@ django-bootstrap-datepicker-plus
|
|||||||
django-cas-server
|
django-cas-server
|
||||||
django-crispy-forms
|
django-crispy-forms
|
||||||
django-extensions
|
django-extensions
|
||||||
django-filter~=2.3.0
|
django-filter
|
||||||
django-haystack~=3.0
|
django-haystack
|
||||||
django-mailer
|
django-mailer
|
||||||
django-polymorphic
|
django-polymorphic
|
||||||
django-tables2
|
django-tables2
|
||||||
djangorestframework~=3.11.1
|
djangorestframework
|
||||||
django-rest-polymorphic
|
django-rest-polymorphic
|
||||||
matrix-nio
|
|
||||||
ptpython
|
ptpython
|
||||||
python-magic~=0.4.18
|
python-magic
|
||||||
gunicorn
|
gunicorn
|
||||||
whoosh
|
whoosh
|
Loading…
x
Reference in New Issue
Block a user