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
0b9faf7b
Commit
0b9faf7b
authored
3 years ago
by
Jonas Braathen
Browse files
Options
Downloads
Patches
Plain Diff
Fix links in registration and confirmation emails
parent
49e7ab0e
No related branches found
No related tags found
1 merge request
!255
Fix links in registration and confirmation emails
Pipeline
#111859
passed
3 years ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gregsite/settings/base.py
+3
-0
3 additions, 0 deletions
gregsite/settings/base.py
gregui/mailutils.py
+37
-12
37 additions, 12 deletions
gregui/mailutils.py
gregui/tests/test_mailutils.py
+17
-8
17 additions, 8 deletions
gregui/tests/test_mailutils.py
with
57 additions
and
20 deletions
gregsite/settings/base.py
+
3
−
0
View file @
0b9faf7b
...
@@ -290,6 +290,9 @@ INSTANCE_NAME = "local"
...
@@ -290,6 +290,9 @@ INSTANCE_NAME = "local"
ENVIRONMENT
=
"
unknown
"
ENVIRONMENT
=
"
unknown
"
INTERNAL_RK_PREFIX
=
"
no.{instance}.greg
"
.
format
(
instance
=
INSTANCE_NAME
)
INTERNAL_RK_PREFIX
=
"
no.{instance}.greg
"
.
format
(
instance
=
INSTANCE_NAME
)
# No trailing slash
BASE_URL
=
"
https://example.org
"
FEIDE_SOURCE
=
"
feide
"
FEIDE_SOURCE
=
"
feide
"
...
...
This diff is collapsed.
Click to expand it.
gregui/mailutils.py
+
37
−
12
View file @
0b9faf7b
import
logging
import
logging
from
typing
import
Optional
from
typing
import
Optional
,
Union
from
typing
import
Union
from
django.conf
import
settings
from
django.conf
import
settings
from
django.template.context
import
Context
from
django.template.context
import
Context
from
django_q.tasks
import
async_task
from
django_q.tasks
import
async_task
...
@@ -24,8 +23,22 @@ def prepare_arguments(
...
@@ -24,8 +23,22 @@ def prepare_arguments(
}
}
def
make_registration_url
(
token
:
str
)
->
str
:
return
"
{base}/invite#{token}
"
.
format
(
base
=
settings
.
BASE_URL
,
token
=
token
,
)
def
make_guest_profile_url
(
person_id
:
Union
[
str
,
int
])
->
str
:
return
"
{base}/sponsor/guest/{person_id}
"
.
format
(
base
=
settings
.
BASE_URL
,
person_id
=
person_id
,
)
def
registration_template
(
def
registration_template
(
institution
:
str
,
sponsor
:
str
,
mail_to
:
str
institution
:
str
,
sponsor
:
str
,
mail_to
:
str
,
token
:
str
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
"""
"""
Prepare email for registration
Prepare email for registration
...
@@ -36,17 +49,20 @@ def registration_template(
...
@@ -36,17 +49,20 @@ def registration_template(
template
=
EmailTemplate
.
objects
.
get
(
template
=
EmailTemplate
.
objects
.
get
(
template_key
=
EmailTemplate
.
EmailType
.
GUEST_REGISTRATION
template_key
=
EmailTemplate
.
EmailType
.
GUEST_REGISTRATION
)
)
registration_link
=
make_registration_url
(
token
)
context
=
Context
(
context
=
Context
(
{
{
"
institution
"
:
institution
,
"
institution
"
:
institution
,
"
sponsor
"
:
sponsor
,
"
sponsor
"
:
sponsor
,
"
registration_link
"
:
"
www.google.com
"
,
"
registration_link
"
:
registration_link
,
}
}
)
)
return
prepare_arguments
(
template
,
context
,
mail_to
)
return
prepare_arguments
(
template
,
context
,
mail_to
)
def
confirmation_template
(
guest
:
str
,
mail_to
:
str
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
def
confirmation_template
(
guest_name
:
str
,
mail_to
:
str
,
guest_person_id
:
Union
[
str
,
int
]
)
->
dict
[
str
,
Union
[
str
,
list
[
str
]]]:
"""
"""
Prepare email for confirmation
Prepare email for confirmation
...
@@ -56,7 +72,8 @@ def confirmation_template(guest: str, mail_to: str) -> dict[str, Union[str, list
...
@@ -56,7 +72,8 @@ def confirmation_template(guest: str, mail_to: str) -> dict[str, Union[str, list
template
=
EmailTemplate
.
objects
.
get
(
template
=
EmailTemplate
.
objects
.
get
(
template_key
=
EmailTemplate
.
EmailType
.
SPONSOR_CONFIRMATION
template_key
=
EmailTemplate
.
EmailType
.
SPONSOR_CONFIRMATION
)
)
context
=
Context
({
"
guest
"
:
guest
,
"
confirmation_link
"
:
"
www.google.com
"
})
confirmation_link
=
make_guest_profile_url
(
guest_person_id
)
context
=
Context
({
"
guest
"
:
guest_name
,
"
confirmation_link
"
:
confirmation_link
})
return
prepare_arguments
(
template
,
context
,
mail_to
)
return
prepare_arguments
(
template
,
context
,
mail_to
)
...
@@ -68,13 +85,17 @@ def reminder_template(mail_to: str, num_roles: int) -> dict[str, Union[str, list
...
@@ -68,13 +85,17 @@ def reminder_template(mail_to: str, num_roles: int) -> dict[str, Union[str, list
return
prepare_arguments
(
template
,
context
,
mail_to
)
return
prepare_arguments
(
template
,
context
,
mail_to
)
def
send_registration_mail
(
mail_to
:
str
,
sponsor
:
str
)
->
str
:
def
send_registration_mail
(
mail_to
:
str
,
sponsor
:
str
,
token
:
str
)
->
str
:
arguments
=
registration_template
(
settings
.
INSTANCE_NAME
,
sponsor
,
mail_to
)
arguments
=
registration_template
(
settings
.
INSTANCE_NAME
,
sponsor
,
mail_to
,
token
)
return
async_task
(
"
django.core.mail.send_mail
"
,
**
arguments
)
return
async_task
(
"
django.core.mail.send_mail
"
,
**
arguments
)
def
send_confirmation_mail
(
mail_to
:
str
,
guest
:
str
)
->
str
:
def
send_confirmation_mail
(
arguments
=
confirmation_template
(
guest
,
mail_to
)
mail_to
:
str
,
guest_name
:
str
,
guest_person_id
:
Union
[
int
,
str
]
)
->
str
:
arguments
=
confirmation_template
(
guest_name
=
guest_name
,
mail_to
=
mail_to
,
guest_person_id
=
guest_person_id
)
return
async_task
(
"
django.core.mail.send_mail
"
,
**
arguments
)
return
async_task
(
"
django.core.mail.send_mail
"
,
**
arguments
)
...
@@ -93,7 +114,9 @@ def send_invite_mail(link: InvitationLink) -> Optional[str]:
...
@@ -93,7 +114,9 @@ def send_invite_mail(link: InvitationLink) -> Optional[str]:
sponsor
=
link
.
invitation
.
role
.
sponsor
sponsor
=
link
.
invitation
.
role
.
sponsor
return
send_registration_mail
(
return
send_registration_mail
(
email_address
.
value
,
f
"
{
sponsor
.
first_name
}
{
sponsor
.
last_name
}
"
mail_to
=
email_address
.
value
,
sponsor
=
f
"
{
sponsor
.
first_name
}
{
sponsor
.
last_name
}
"
,
token
=
link
.
uuid
,
)
)
...
@@ -101,4 +124,6 @@ def send_confirmation_mail_from_link(link: InvitationLink) -> Optional[str]:
...
@@ -101,4 +124,6 @@ def send_confirmation_mail_from_link(link: InvitationLink) -> Optional[str]:
email_address
=
link
.
invitation
.
role
.
sponsor
.
work_email
email_address
=
link
.
invitation
.
role
.
sponsor
.
work_email
guest
=
link
.
invitation
.
role
.
person
guest
=
link
.
invitation
.
role
.
person
guest_name
=
f
"
{
guest
.
first_name
}
{
guest
.
last_name
}
"
guest_name
=
f
"
{
guest
.
first_name
}
{
guest
.
last_name
}
"
return
send_confirmation_mail
(
email_address
,
guest_name
)
return
send_confirmation_mail
(
mail_to
=
email_address
,
guest_name
=
guest_name
,
guest_person_id
=
guest
.
id
)
This diff is collapsed.
Click to expand it.
gregui/tests/test_mailutils.py
+
17
−
8
View file @
0b9faf7b
...
@@ -13,14 +13,17 @@ def test_registration_template(registration_template):
...
@@ -13,14 +13,17 @@ def test_registration_template(registration_template):
"
subject
"
:
"
registration subject
"
,
"
subject
"
:
"
registration subject
"
,
"
message
"
:
"""
Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
"
message
"
:
"""
Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
Du har blitt registrert som gjest på InstanceName av Foo Bar.
Du har blitt registrert som gjest på InstanceName av Foo Bar.
For å fullføre registreringen av gjestekontoen følg denne lenken:
www.google.com
For å fullføre registreringen av gjestekontoen følg denne lenken:
https://example.org/invite#secret-key
This message has been automatically generated by the guest registration system.
This message has been automatically generated by the guest registration system.
You have been registered as a guest at InstanceName by Foo Bar.
You have been registered as a guest at InstanceName by Foo Bar.
To complete the registration of your guest account, please follow this link:
www.google.com
"""
,
To complete the registration of your guest account, please follow this link:
https://example.org/invite#secret-key
"""
,
}
}
rendered_template
=
mailutils
.
registration_template
(
rendered_template
=
mailutils
.
registration_template
(
"
InstanceName
"
,
"
Foo Bar
"
,
"
test@example.com
"
institution
=
"
InstanceName
"
,
sponsor
=
"
Foo Bar
"
,
mail_to
=
"
test@example.com
"
,
token
=
"
secret-key
"
,
)
)
assert
rendered_template
==
prefilled_template
assert
rendered_template
==
prefilled_template
...
@@ -32,19 +35,23 @@ def test_confirmation_template(confirmation_template):
...
@@ -32,19 +35,23 @@ def test_confirmation_template(confirmation_template):
"
recipient_list
"
:
[
"
test@example.com
"
],
"
recipient_list
"
:
[
"
test@example.com
"
],
"
subject
"
:
"
confirmation subject
"
,
"
subject
"
:
"
confirmation subject
"
,
"
message
"
:
"""
Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
"
message
"
:
"""
Dette er en automatisk generert melding fra gjesteregistreringstjenesten.
Din gjest, Foo Bar, har fullført registrering, bekreft gjesten her:
www.google.com
Din gjest, Foo Bar, har fullført registrering, bekreft gjesten her:
https://example.org/sponsor/guest/123
This message has been automatically generated by the guest registration system.
This message has been automatically generated by the guest registration system.
Your guest, Foo Bar, has completed their registration, please confirm the guest here:
www.google.com
"""
,
Your guest, Foo Bar, has completed their registration, please confirm the guest here:
https://example.org/sponsor/guest/123
"""
,
}
}
rendered_template
=
mailutils
.
confirmation_template
(
"
Foo Bar
"
,
"
test@example.com
"
)
rendered_template
=
mailutils
.
confirmation_template
(
guest_name
=
"
Foo Bar
"
,
mail_to
=
"
test@example.com
"
,
guest_person_id
=
123
)
assert
rendered_template
==
prefilled_template
assert
rendered_template
==
prefilled_template
@pytest.mark.django_db
@pytest.mark.django_db
def
test_registration_mail
(
registration_template
):
def
test_registration_mail
(
registration_template
):
mail
.
outbox
=
[]
mail
.
outbox
=
[]
task_id
=
mailutils
.
send_registration_mail
(
"
test@example.no
"
,
"
Foo
"
)
task_id
=
mailutils
.
send_registration_mail
(
mail_to
=
"
test@example.no
"
,
sponsor
=
"
Foo
"
,
token
=
"
secret-key
"
)
assert
result
(
task_id
)
==
1
assert
result
(
task_id
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
...
@@ -53,7 +60,9 @@ def test_registration_mail(registration_template):
...
@@ -53,7 +60,9 @@ def test_registration_mail(registration_template):
@pytest.mark.django_db
@pytest.mark.django_db
def
test_confirmation_mail
(
confirmation_template
):
def
test_confirmation_mail
(
confirmation_template
):
mail
.
outbox
=
[]
mail
.
outbox
=
[]
task_id
=
mailutils
.
send_confirmation_mail
(
"
test@example.no
"
,
"
Foo
"
)
task_id
=
mailutils
.
send_confirmation_mail
(
mail_to
=
"
test@example.no
"
,
guest_name
=
"
Foo
"
,
guest_person_id
=
123
)
assert
result
(
task_id
)
==
1
assert
result
(
task_id
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
...
...
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