-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Hook up invite codes to the login screen * Re-organized admin panels, add invite panel, add admin nav, and fix up data table's null filter handling. * Add invite generation, and fix using invites during user registration * Add invite factory * ➕ Add table data type 'code' * 🌐 Update German lang strings * Fix admin nav elements --------- Co-authored-by: Andreas Müller <[email protected]>
- Loading branch information
1 parent
e25f2ba
commit be6c0e6
Showing
15 changed files
with
429 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,32 +19,17 @@ | |
|
||
|
||
@router.get('/', response_model=list[schemas.Invite]) | ||
def get_all_invites(db: Session = Depends(get_db), admin: Subscriber = Depends(get_admin_subscriber)): | ||
def get_all_invites(db: Session = Depends(get_db), _admin: Subscriber = Depends(get_admin_subscriber)): | ||
"""List all existing invites, needs admin permissions""" | ||
return db.query(models.Invite).all() | ||
|
||
|
||
@router.post("/generate/{n}", response_model=list[schemas.Invite]) | ||
def generate_invite_codes(n: int, db: Session = Depends(get_db), admin: Subscriber = Depends(get_admin_subscriber)): | ||
def generate_invite_codes(n: int, db: Session = Depends(get_db), _admin: Subscriber = Depends(get_admin_subscriber)): | ||
"""endpoint to generate n invite codes, needs admin permissions""" | ||
return repo.invite.generate_codes(db, n) | ||
|
||
|
||
@router.put("/redeem/{code}") | ||
def use_invite_code(code: str, db: Session = Depends(get_db)): | ||
raise NotImplementedError | ||
|
||
"""endpoint to create a new subscriber and update the corresponding invite""" | ||
if not repo.invite.code_exists(db, code): | ||
raise validation.InviteCodeNotFoundException() | ||
if not repo.invite.code_is_available(db, code): | ||
raise validation.InviteCodeNotAvailableException() | ||
# TODO: get email from admin panel | ||
email = '[email protected]' | ||
subscriber = repo.subscriber.create(db, schemas.SubscriberBase(email=email, username=email)) | ||
return repo.invite.use_code(db, code, subscriber.id) | ||
|
||
|
||
@router.put("/revoke/{code}") | ||
def revoke_invite_code(code: str, db: Session = Depends(get_db), admin: Subscriber = Depends(get_admin_subscriber)): | ||
"""endpoint to revoke a given invite code and mark in unavailable, needs admin permissions""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
from faker import Faker | ||
from appointment.database import models | ||
from defines import FAKER_RANDOM_VALUE, factory_has_value | ||
|
||
|
||
@pytest.fixture | ||
def make_invite(with_db): | ||
fake = Faker() | ||
|
||
def _make_invite(subscriber_id=None, code=FAKER_RANDOM_VALUE, status=models.InviteStatus.active) -> models.Invite: | ||
with with_db() as db: | ||
invite = models.Invite(subscriber_id=subscriber_id, status=status, code=code if factory_has_value(code) else fake.uuid4()) | ||
db.add(invite) | ||
db.commit() | ||
db.refresh(invite) | ||
return invite | ||
|
||
return _make_invite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div class="mb-4 flex h-12 justify-center gap-8"> | ||
<nav-bar-item | ||
v-for="item in navItems" | ||
:key="item" | ||
:active="route.name == item" | ||
:label="t(`label.${item}`)" | ||
:link-name="item" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useI18n } from 'vue-i18n'; | ||
import { useRoute } from 'vue-router'; | ||
import NavBarItem from '@/elements/NavBarItem.vue'; | ||
const { t } = useI18n(); | ||
const navItems = [ | ||
'admin-invite-codes-panel', | ||
'admin-subscriber-panel', | ||
]; | ||
const route = useRoute(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.