Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
93cfdc0f
Commit
93cfdc0f
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-94: Adding sending of e-mail for invitations
parent
62d16b4d
No related branches found
No related tags found
1 merge request
!136
GREG-94: Resend invitation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gregui/api/views/invitation.py
+3
-4
3 additions, 4 deletions
gregui/api/views/invitation.py
gregui/mailutils.py
+23
-2
23 additions, 2 deletions
gregui/mailutils.py
with
26 additions
and
6 deletions
gregui/api/views/invitation.py
+
3
−
4
View file @
93cfdc0f
...
...
@@ -23,6 +23,7 @@ from greg.models import Identity, InvitationLink, Person, Invitation
from
greg.permissions
import
IsSponsor
from
gregui.api.serializers.guest
import
GuestRegisterSerializer
from
gregui.api.serializers.invitation
import
InviteGuestSerializer
from
gregui.mailutils
import
send_invite_mail
from
gregui.models
import
GregUserProfile
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -76,8 +77,7 @@ class InvitationView(CreateAPIView, DestroyAPIView):
invitation__role__person_id
=
person
.
id
,
invitation__role__sponsor_id
=
sponsor_user
.
sponsor
.
id
,
)
# TODO: send email to invited guest
print
(
invitationlink
)
send_invite_mail
(
invitationlink
)
return
Response
(
status
=
status
.
HTTP_201_CREATED
)
def
delete
(
self
,
request
,
*
args
,
**
kwargs
)
->
Response
:
...
...
@@ -310,7 +310,6 @@ class ResendInvitationView(UpdateModelMixin, APIView):
# expire=timezone.now() + datetime.timedelta(days=30),
# )
# TODO: send email to invited guest
print
(
link
)
send_invite_mail
(
link
)
return
Response
(
status
=
status
.
HTTP_200_OK
)
This diff is collapsed.
Click to expand it.
gregui/mailutils.py
+
23
−
2
View file @
93cfdc0f
import
logging
from
typing
import
Optional
from
typing
import
Union
from
django.conf
import
settings
from
django.template.context
import
Context
from
django_q.tasks
import
async_task
from
greg.models
import
InvitationLink
from
gregui.models
import
EmailTemplate
logger
=
logging
.
getLogger
(
__name__
)
def
prepare_arguments
(
template
:
EmailTemplate
,
context
:
dict
[
str
,
str
],
mail_to
:
str
template
:
EmailTemplate
,
context
:
dict
[
str
,
str
],
mail_to
:
str
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
"""
Combine input to a dict ready for use as arguments ti django
'
s send_mail
"""
return
{
...
...
@@ -19,7 +25,7 @@ def prepare_arguments(
def
registration_template
(
institution
:
str
,
sponsor
:
str
,
mail_to
:
str
institution
:
str
,
sponsor
:
str
,
mail_to
:
str
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
"""
Prepare email for registration
...
...
@@ -62,3 +68,18 @@ def send_registration_mail(mail_to: str, sponsor: str) -> str:
def
send_confirmation_mail
(
mail_to
:
str
,
guest
:
str
)
->
str
:
arguments
=
confirmation_template
(
guest
,
mail_to
)
return
async_task
(
"
django.core.mail.send_mail
"
,
**
arguments
)
def
send_invite_mail
(
link
:
InvitationLink
)
->
Optional
[
str
]:
email_address
=
link
.
invitation
.
role
.
person
.
private_email
sponsor
=
link
.
invitation
.
role
.
sponsor
if
not
email_address
:
logger
.
warning
(
f
"
No e-mail address found for invitation link with ID:
{
link
.
id
}
"
)
return
None
if
not
sponsor
:
logger
.
warning
(
"
Unable to determine sponsor for invitation link with ID: {link.id}
"
)
return
None
return
send_registration_mail
(
email_address
.
value
,
f
"
{
sponsor
.
first_name
}
{
sponsor
.
last_name
}
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment