Sign-in via django-allauth: emailed one-time codes, GitHub, Discord, and Forgejo instances as OpenID Connect apps registered in admin. Regular users never have a password; sysadmins sign in only at /admin/ and are redirected there from the normal sign-in. Organizations at the URL root with owner and collaborator roles, a per-member project-create grant, and invites by username or email. Email invites carry a bearer token stored only as a hash. The last owner can't leave, be removed or be demoted. Permission checks live in intent/access.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1 KiB
Python
41 lines
1 KiB
Python
import itertools
|
|
|
|
import pytest
|
|
from allauth.account.models import EmailAddress
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from intent.orgs.models import OrgMembership, Role
|
|
from intent.orgs.services import create_org
|
|
|
|
_counter = itertools.count()
|
|
|
|
|
|
@pytest.fixture
|
|
def make_user(db):
|
|
def make(username=None, *, email=None, is_staff=False):
|
|
username = username or f"user{next(_counter)}"
|
|
email = email or f"{username}@example.com"
|
|
user = get_user_model().objects.create_user(
|
|
username=username, email=email, is_staff=is_staff
|
|
)
|
|
EmailAddress.objects.create(user=user, email=email, verified=True, primary=True)
|
|
return user
|
|
|
|
return make
|
|
|
|
|
|
@pytest.fixture
|
|
def owner(make_user):
|
|
return make_user("olive")
|
|
|
|
|
|
@pytest.fixture
|
|
def org(owner):
|
|
return create_org(slug="catbriar", name="Catbriar", owner=owner)
|
|
|
|
|
|
@pytest.fixture
|
|
def collaborator(make_user, org):
|
|
user = make_user("cole")
|
|
OrgMembership.objects.create(org=org, user=user, role=Role.COLLABORATOR)
|
|
return user
|