🐛(communes) add missing user creation in domain provisioning
Add user in Dimail for automatically provisioned domains.
This commit is contained in:
committed by
Laurent Bossavit
parent
29d0bbb692
commit
7379d70321
@@ -192,7 +192,7 @@ class CommuneCreation(BaseOrganizationPlugin):
|
|||||||
create_domain = ApiCall()
|
create_domain = ApiCall()
|
||||||
create_domain.method = "POST"
|
create_domain.method = "POST"
|
||||||
create_domain.base = settings.MAIL_PROVISIONING_API_URL
|
create_domain.base = settings.MAIL_PROVISIONING_API_URL
|
||||||
create_domain.url = "/domains"
|
create_domain.url = "/domains/"
|
||||||
create_domain.params = {
|
create_domain.params = {
|
||||||
"name": zone_name,
|
"name": zone_name,
|
||||||
"delivery": "virtual",
|
"delivery": "virtual",
|
||||||
@@ -259,6 +259,36 @@ class CommuneCreation(BaseOrganizationPlugin):
|
|||||||
last_task = self.complete_zone_creation(tasks[-1])
|
last_task = self.complete_zone_creation(tasks[-1])
|
||||||
last_task.execute()
|
last_task.execute()
|
||||||
|
|
||||||
|
def complete_grant_access(self, sub, zone_name):
|
||||||
|
"""Specify the tasks to be completed after making a user admin"""
|
||||||
|
create_user = ApiCall()
|
||||||
|
create_user.method = "POST"
|
||||||
|
create_user.base = settings.MAIL_PROVISIONING_API_URL
|
||||||
|
create_user.url = "/users/"
|
||||||
|
create_user.params = {
|
||||||
|
"name": sub,
|
||||||
|
"password": "no",
|
||||||
|
"is_admin": False,
|
||||||
|
"perms": [],
|
||||||
|
}
|
||||||
|
create_user.headers = {
|
||||||
|
"Authorization": f"Basic {settings.MAIL_PROVISIONING_API_CREDENTIALS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
grant_access = ApiCall()
|
||||||
|
grant_access.method = "POST"
|
||||||
|
grant_access.base = settings.MAIL_PROVISIONING_API_URL
|
||||||
|
grant_access.url = "/allows/"
|
||||||
|
grant_access.params = {
|
||||||
|
"user": sub,
|
||||||
|
"domain": zone_name,
|
||||||
|
}
|
||||||
|
grant_access.headers = {
|
||||||
|
"Authorization": f"Basic {settings.MAIL_PROVISIONING_API_CREDENTIALS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
return [create_user, grant_access]
|
||||||
|
|
||||||
def run_after_grant_access(self, organization_access):
|
def run_after_grant_access(self, organization_access):
|
||||||
"""After granting an organization access, check for needed domain access grant."""
|
"""After granting an organization access, check for needed domain access grant."""
|
||||||
orga = organization_access.organization
|
orga = organization_access.organization
|
||||||
@@ -274,15 +304,7 @@ class CommuneCreation(BaseOrganizationPlugin):
|
|||||||
MailDomainAccess.objects.create(
|
MailDomainAccess.objects.create(
|
||||||
domain=domain, user=user, role=MailDomainRoleChoices.OWNER
|
domain=domain, user=user, role=MailDomainRoleChoices.OWNER
|
||||||
)
|
)
|
||||||
grant_access = ApiCall()
|
|
||||||
grant_access.method = "POST"
|
tasks = self.complete_grant_access(user.sub, zone_name)
|
||||||
grant_access.base = settings.MAIL_PROVISIONING_API_URL
|
for task in tasks:
|
||||||
grant_access.url = "/allows"
|
task.execute()
|
||||||
grant_access.params = {
|
|
||||||
"user": user.sub,
|
|
||||||
"domain": zone_name,
|
|
||||||
}
|
|
||||||
grant_access.headers = {
|
|
||||||
"Authorization": f"Basic {settings.MAIL_PROVISIONING_API_CREDENTIALS}"
|
|
||||||
}
|
|
||||||
grant_access.execute()
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def test_tasks_on_commune_creation_include_dimail_domain_creation():
|
|||||||
tasks = plugin.complete_commune_creation(name)
|
tasks = plugin.complete_commune_creation(name)
|
||||||
|
|
||||||
assert tasks[1].base == settings.MAIL_PROVISIONING_API_URL
|
assert tasks[1].base == settings.MAIL_PROVISIONING_API_URL
|
||||||
assert tasks[1].url == "/domains"
|
assert tasks[1].url == "/domains/"
|
||||||
assert tasks[1].method == "POST"
|
assert tasks[1].method == "POST"
|
||||||
assert tasks[1].params == {
|
assert tasks[1].params == {
|
||||||
"name": "merlaut.collectivite.fr",
|
"name": "merlaut.collectivite.fr",
|
||||||
@@ -171,6 +171,39 @@ def test_tasks_on_commune_creation_include_dns_records():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_tasks_on_grant_access():
|
||||||
|
"""Test the final tasks after making user admin of an org"""
|
||||||
|
plugin = CommuneCreation()
|
||||||
|
|
||||||
|
tasks = plugin.complete_grant_access("some-sub", "mezos.collectivite.fr")
|
||||||
|
|
||||||
|
assert tasks[0].base == settings.MAIL_PROVISIONING_API_URL
|
||||||
|
assert tasks[0].url == "/users/"
|
||||||
|
assert tasks[0].method == "POST"
|
||||||
|
assert tasks[0].params == {
|
||||||
|
"name": "some-sub",
|
||||||
|
"password": "no",
|
||||||
|
"is_admin": False,
|
||||||
|
"perms": [],
|
||||||
|
}
|
||||||
|
assert (
|
||||||
|
tasks[0].headers["Authorization"]
|
||||||
|
== f"Basic {settings.MAIL_PROVISIONING_API_CREDENTIALS}"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert tasks[1].base == settings.MAIL_PROVISIONING_API_URL
|
||||||
|
assert tasks[1].url == "/allows/"
|
||||||
|
assert tasks[1].method == "POST"
|
||||||
|
assert tasks[1].params == {
|
||||||
|
"user": "some-sub",
|
||||||
|
"domain": "mezos.collectivite.fr",
|
||||||
|
}
|
||||||
|
assert (
|
||||||
|
tasks[1].headers["Authorization"]
|
||||||
|
== f"Basic {settings.MAIL_PROVISIONING_API_CREDENTIALS}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_normalize_name():
|
def test_normalize_name():
|
||||||
"""Test name normalization"""
|
"""Test name normalization"""
|
||||||
plugin = CommuneCreation()
|
plugin = CommuneCreation()
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ test.beforeEach(async ({ page, browserName }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.describe('When a commune, domain is created on first login via ProConnect', () => {
|
test.describe('When a commune, domain is created on first login via ProConnect', () => {
|
||||||
test('it checks the domain has been created', async ({ page }) => {
|
test('it checks the domain has been created and is operational', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
const header = page.locator('header').first();
|
const header = page.locator('header').first();
|
||||||
await expect(header.getByAltText('Marianne Logo')).toBeVisible();
|
await expect(header.getByAltText('Marianne Logo')).toBeVisible();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user