-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Invitation letter generation (#4266)
- Loading branch information
1 parent
2617a8c
commit c4ed4ce
Showing
82 changed files
with
7,802 additions
and
2,979 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
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ def _unassigned_schedule_items(client, **input): | |
id | ||
} | ||
}""", | ||
variables={**input}, | ||
variables=input, | ||
) | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -141,3 +141,8 @@ def paginate_list( | |
), | ||
items=items, | ||
) | ||
|
||
|
||
@strawberry.type | ||
class NotFound: | ||
message: str = "Not found" |
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,73 @@ | ||
from typing import Annotated | ||
from api.context import Context | ||
from api.types import NotFound | ||
from custom_admin.audit import create_change_admin_log_entry | ||
from visa.models import InvitationLetterDocument as InvitationLetterDocumentModel | ||
from api.visa.permissions import CanEditInvitationLetterDocument | ||
from strawberry.tools import create_type | ||
from api.visa.types import InvitationLetterDocument | ||
import strawberry | ||
|
||
|
||
@strawberry.input | ||
class UpdateInvitationLetterDocumentPageInput: | ||
id: strawberry.ID | ||
title: str | ||
content: str | ||
|
||
|
||
@strawberry.input | ||
class UpdateInvitationLetterDocumentStructureInput: | ||
header: str | ||
footer: str | ||
pages: list[UpdateInvitationLetterDocumentPageInput] | ||
|
||
|
||
@strawberry.input | ||
class UpdateInvitationLetterDocumentInput: | ||
id: strawberry.ID | ||
dynamic_document: UpdateInvitationLetterDocumentStructureInput | ||
|
||
|
||
@strawberry.type | ||
class InvitationLetterNotEditable: | ||
message: str = "Invitation letter document is not editable" | ||
|
||
|
||
UpdateInvitationLetterDocumentResult = Annotated[ | ||
InvitationLetterDocument | InvitationLetterNotEditable | NotFound, | ||
strawberry.union(name="UpdateInvitationLetterDocumentResult"), | ||
] | ||
|
||
|
||
@strawberry.field(permission_classes=[CanEditInvitationLetterDocument]) | ||
def update_invitation_letter_document( | ||
info: strawberry.Info[Context], input: UpdateInvitationLetterDocumentInput | ||
) -> UpdateInvitationLetterDocumentResult: | ||
invitation_letter_document = InvitationLetterDocumentModel.objects.filter( | ||
id=input.id, | ||
).first() | ||
|
||
if not invitation_letter_document: | ||
return NotFound() | ||
|
||
if invitation_letter_document.document: | ||
return InvitationLetterNotEditable() | ||
|
||
invitation_letter_document.dynamic_document = strawberry.asdict( | ||
input.dynamic_document | ||
) | ||
invitation_letter_document.save(update_fields=["dynamic_document"]) | ||
|
||
create_change_admin_log_entry( | ||
info.context.request.user, | ||
invitation_letter_document, | ||
change_message="Invitation letter document updated", | ||
) | ||
return InvitationLetterDocument.from_model(invitation_letter_document) | ||
|
||
|
||
VisaMutation = create_type( | ||
"VisaMutation", | ||
(update_invitation_letter_document,), | ||
) |
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,38 @@ | ||
from api.permissions import IsStaffPermission | ||
from visa.models import InvitationLetterDocument | ||
|
||
|
||
class CanViewInvitationLetterDocument(IsStaffPermission): | ||
message = "Cannot view invitation letter document" | ||
|
||
def has_permission(self, source, info, **kwargs): | ||
if not super().has_permission(source, info, **kwargs): | ||
return False | ||
|
||
self.invitation_letter_document = self.get_invitation_letter_document(kwargs) | ||
user = info.context.request.user | ||
return user.has_perm( | ||
"visa.view_invitationletterdocument", self.invitation_letter_document | ||
) | ||
|
||
def get_invitation_letter_document(self, kwargs): | ||
if input := kwargs.get("input", None): | ||
id = input.id | ||
else: | ||
id = kwargs.get("id") | ||
|
||
return InvitationLetterDocument.objects.filter(id=id).first() | ||
|
||
|
||
class CanEditInvitationLetterDocument(CanViewInvitationLetterDocument): | ||
message = "Cannot edit invitation letter document" | ||
|
||
def has_permission(self, source, info, **kwargs): | ||
if not super().has_permission(source, info, **kwargs): | ||
return False | ||
|
||
invitation_letter_document = self.invitation_letter_document | ||
user = info.context.request.user | ||
return user.has_perm( | ||
"visa.change_invitationletterdocument", invitation_letter_document | ||
) |
Oops, something went wrong.