1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-02-15 18:21:18 +00:00

Compare commits

..

No commits in common. "b33723efb336239eaef6d55c79b4f95983250e3e" and "642ac94b7a3bb8ee7ba60d7fbc839eef4fbe5448" have entirely different histories.

5 changed files with 20 additions and 74 deletions

View File

@ -2,7 +2,6 @@ import os
import re
from django.template.loader import render_to_string
from nio import RoomVisibility, RoomPreset
from corres2math.lists import get_sympa_client
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.translation import gettext_lazy as _
from corres2math.matrix import Matrix
class Team(models.Model):
name = models.CharField(
@ -66,13 +63,6 @@ class Team(models.Model):
self.access_code = get_random_string(6)
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)
def get_absolute_url(self):

View File

@ -1,4 +1,5 @@
from cas_server.auth import DjangoAuthUser
from django.utils.text import slugify
class CustomAuthUser(DjangoAuthUser):
@ -9,6 +10,5 @@ class CustomAuthUser(DjangoAuthUser):
def attributs(self):
d = super().attributs()
if self.user:
d["matrix_username"] = f"corres2math_{self.user.pk}"
d["display_name"] = str(self.user.registration)
d["matrix_username"] = slugify(str(self.user.registration))
return d

View File

@ -1,17 +1,17 @@
[
{
"model": "cas_server.servicepattern",
"pk": 1,
"fields": {
"pos": 100,
"name": "Plateforme des Correspondances",
"pattern": "^https://correspondances-maths.fr:8448/.*$",
"user_field": "matrix_username",
"restrict_users": false,
"proxy": true,
"proxy_callback": true,
"single_log_out": true,
"single_log_out_callback": ""
}
{
"model": "cas_server.servicepattern",
"pk": 1,
"fields": {
"pos": 100,
"name": "Plateforme des Correspondances",
"pattern": "^https://correspondances-maths.fr:8448/.*$",
"user_field": "matrix_username",
"restrict_users": false,
"proxy": true,
"proxy_callback": true,
"single_log_out": true,
"single_log_out_callback": ""
}
}
]

View File

@ -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))

View File

@ -3,15 +3,14 @@ django-bootstrap-datepicker-plus
django-cas-server
django-crispy-forms
django-extensions
django-filter~=2.3.0
django-haystack~=3.0
django-filter
django-haystack
django-mailer
django-polymorphic
django-tables2
djangorestframework~=3.11.1
djangorestframework
django-rest-polymorphic
matrix-nio
ptpython
python-magic~=0.4.18
python-magic
gunicorn
whoosh