(project) add Room, Ressource, Access models from Magnify

I picked few models from Magnify to build our MVP:

- Resource:
   A generic model representing any type of resource. Though currently used only by Room,
   it encapsulates a meaningful business logic as an abstract model.
- Room:
   The primary object we manipulate, representing a meeting room with access
   and permission controls.
- ResourceAccess
   Ensures relevant users have the appropriate permissions for a given room.

** What’s different from Magnify ? **

Removed group logic; it will be added later. For now, we rely on the user model's
property to get its groups via desk.

Removed any logic or method related to Jitsi or LiveKit. These servers will be integrated
in the upcomming commits.

Focus on Room-related models to maintain a minimal and functional product (KISS principle)
until we achieve product-market fit (PMF).

Creating simple public and private, permanent and temporary rooms
is sufficient for building our MVP.

The Meeting model in Magnify, which supports recurrence, should be handled by
the collaborative calendar instead.

Adapted the unit test to use Pytest, and linted all the sources using Ruff linter.

(Migrations will be squashed before releasing the MVP)
This commit is contained in:
lebaudantoine
2024-06-24 19:14:27 +02:00
parent fbe79b7b2b
commit 2e6feede31
6 changed files with 565 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ Core application factories
"""
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.utils.text import slugify
import factory.fuzzy
from faker import Faker
@@ -23,3 +24,43 @@ class UserFactory(factory.django.DjangoModelFactory):
email = factory.Faker("email")
language = factory.fuzzy.FuzzyChoice([lang[0] for lang in settings.LANGUAGES])
password = make_password("password")
class ResourceFactory(factory.django.DjangoModelFactory):
"""Create fake resources for testing."""
class Meta:
model = models.Resource
is_public = factory.Faker("boolean", chance_of_getting_true=50)
@factory.post_generation
def users(self, create, extracted, **kwargs):
"""Add users to resource from a given list of users."""
if create and extracted:
for item in extracted:
if isinstance(item, models.User):
UserResourceAccessFactory(resource=self, user=item)
else:
UserResourceAccessFactory(resource=self, user=item[0], role=item[1])
class UserResourceAccessFactory(factory.django.DjangoModelFactory):
"""Create fake resource user accesses for testing."""
class Meta:
model = models.ResourceAccess
resource = factory.SubFactory(ResourceFactory)
user = factory.SubFactory(UserFactory)
role = factory.fuzzy.FuzzyChoice(models.RoleChoices.values)
class RoomFactory(ResourceFactory):
"""Create fake rooms for testing."""
class Meta:
model = models.Room
name = factory.Faker("catch_phrase")
slug = factory.LazyAttribute(lambda o: slugify(o.name))