Make scheduled tasks discoverable by hosting account
This commit is contained in:
1 parent
c36cbb6c15
commit
400a0c539c
11 files changed
+255
-75
No files matched your search
+12
-6
@@ -1450,16 +1450,22 @@ sudo systemctl enable --now coulobre-website-job-worker.service
|
|||||||
sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat
|
sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat
|
||||||
```
|
```
|
||||||
|
|
||||||
Set **Website job limit** to the number of saved jobs allowed per hosting
|
Set **Scheduled tasks per hosting account** to the number of saved tasks
|
||||||
account. Paused jobs count toward the saved limit. The default is zero.
|
allowed per account. Paused tasks count toward the limit. The default is zero.
|
||||||
If you lower a limit, the oldest enabled jobs retain their places until
|
If you lower a limit, the oldest enabled jobs retain their places until
|
||||||
the account removes or pauses jobs. Add `website-jobs` to the local service
|
the account removes or pauses jobs. Add `website-jobs` to the local service
|
||||||
health list if you monitor this worker from the panel.
|
health list if you monitor this worker from the panel.
|
||||||
|
|
||||||
Customers can open **Scheduled jobs** from the
|
Customers can open **Advanced Features → Scheduled Tasks** and select a
|
||||||
account page. Operators need both **Can view hosting account** and **Can
|
hosting account. **Add task** is available when the account has an active
|
||||||
manage scheduled website jobs**. Pick the primary or an active independent
|
website and room in its hosting package. The page explains what to check
|
||||||
website. Use five cron fields in UTC. For example, `*/15 * * * *` runs every
|
when adding tasks is unavailable. Operators and managers can open **System →
|
||||||
|
Scheduled Task Overview** to inspect tasks in their workspace. Operators
|
||||||
|
can manage tasks for accounts without an assigned customer when they have
|
||||||
|
both **Can view hosting account** and **Can manage scheduled website jobs**.
|
||||||
|
|
||||||
|
When adding a task, pick the primary or an active independent website.
|
||||||
|
Use five cron fields in UTC. For example, `*/15 * * * *` runs every
|
||||||
15 minutes. Runs must be at least five minutes apart. When both day fields
|
15 minutes. Runs must be at least five minutes apart. When both day fields
|
||||||
are restricted, the date must match both.
|
are restricted, the date must match both.
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
<a class="button secondary" href="{% url 'panel:website_files' account.pk %}">Website files</a>
|
<a class="button secondary" href="{% url 'panel:website_files' account.pk %}">Website files</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if manage_website_jobs %}
|
{% if manage_website_jobs %}
|
||||||
<a class="button secondary" href="{% url 'panel:website_jobs' account.pk %}">Scheduled jobs</a>
|
<a class="button secondary" href="{% url 'panel:website_jobs' account.pk %}">Scheduled Tasks</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if manage_sftp %}
|
{% if manage_sftp %}
|
||||||
<a class="button secondary" href="{% url 'panel:sftp_keys' account.pk %}">SFTP access</a>
|
<a class="button secondary" href="{% url 'panel:sftp_keys' account.pk %}">SFTP access</a>
|
||||||
|
|||||||
@@ -13,10 +13,18 @@
|
|||||||
{% empty %}<tr><td colspan="6">No hosting accounts are available.</td></tr>{% endfor %}</tbody>
|
{% empty %}<tr><td colspan="6">No hosting accounts are available.</td></tr>{% endfor %}</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
{% elif section == 'tasks' %}
|
{% elif section == 'tasks' %}
|
||||||
|
{% if manageable_accounts %}
|
||||||
|
<div class="section-text">
|
||||||
|
<h2>Manage tasks by hosting account</h2>
|
||||||
|
<ul class="workspace-list">
|
||||||
|
{% for account in manageable_accounts.values %}<li><a href="{% url 'panel:website_jobs' account.pk %}">{{ account.primary_domain }}</a></li>{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="table-scroll"><table>
|
<div class="table-scroll"><table>
|
||||||
<thead><tr><th scope="col">Domain</th><th scope="col">Task</th><th scope="col">Status</th><th scope="col">Next run (UTC)</th></tr></thead>
|
<thead><tr><th scope="col">Domain</th><th scope="col">Task</th><th scope="col">Status</th><th scope="col">Next run (UTC)</th></tr></thead>
|
||||||
<tbody>{% for job in tasks %}
|
<tbody>{% for job in tasks %}
|
||||||
<tr><td>{{ job.domain }}</td><th scope="row">{% if target %}<a href="{% url target job.account_id %}">{{ job.name }}</a>{% else %}{{ job.name }}{% endif %}</th><td>{{ job.enabled|yesno:"Enabled,Paused" }}</td><td>{{ job.next_run_at|date:"j M Y H:i"|default:"—" }}</td></tr>
|
<tr><td>{{ job.domain }}</td><th scope="row">{% if job.account_id in manageable_accounts %}<a href="{% url 'panel:website_jobs' job.account_id %}">{{ job.name }}</a>{% else %}{{ job.name }}{% endif %}</th><td>{{ job.enabled|yesno:"Enabled,Paused" }}</td><td>{{ job.next_run_at|date:"j M Y H:i"|default:"—" }}</td></tr>
|
||||||
{% empty %}<tr><td colspan="4">No scheduled tasks for these accounts.</td></tr>{% endfor %}</tbody>
|
{% empty %}<tr><td colspan="4">No scheduled tasks for these accounts.</td></tr>{% endfor %}</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
{% extends "hosting/workspace_page.html" %}
|
{% extends "hosting/workspace_page.html" %}
|
||||||
{% block title %}{% if job %}Edit{% else %}Add{% endif %} website job · Coulobre Panel{% endblock %}
|
{% block title %}{% if job %}Edit{% else %}Add{% endif %} task · Coulobre Panel{% endblock %}
|
||||||
|
{% block workspace_selector %}{% endblock %}
|
||||||
{% block page_header %}
|
{% block page_header %}
|
||||||
<header class="page-heading">
|
<header class="page-heading">
|
||||||
<div>
|
<div>
|
||||||
<h1>{% if job %}Edit{% else %}Add{% endif %} website job</h1>
|
<h1>{% if job %}Edit{% else %}Add{% endif %} task</h1>
|
||||||
{% if job %}<p class="heading-meta domain">{{ job.domain }}</p>{% endif %}
|
<p class="heading-meta domain">{{ job.domain|default:account.primary_domain }}</p>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_context %}
|
{% block page_context %}
|
||||||
<a class="quiet-link" href="{{ list_url }}">← Scheduled website jobs</a>
|
<a class="quiet-link" href="{{ list_url }}">← Scheduled Tasks</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
<section class="surface editor-surface">
|
<section class="surface editor-surface">
|
||||||
@@ -17,9 +18,9 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_div }}
|
{{ form.as_div }}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="button primary" type="submit">Save job</button>
|
<button class="button primary" type="submit">Save task</button>
|
||||||
<a class="button secondary" href="{{ list_url }}">Cancel</a>
|
<a class="button secondary" href="{{ list_url }}">Cancel</a>
|
||||||
{% if job %}<button class="button secondary" name="action" value="remove" type="submit" formnovalidate>Remove job</button>{% endif %}
|
{% if job %}<button class="button secondary" name="action" value="remove" type="submit" formnovalidate>Remove task</button>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,31 +1,54 @@
|
|||||||
{% extends "hosting/workspace_page.html" %}
|
{% extends "hosting/workspace_page.html" %}
|
||||||
{% block title %}Scheduled website jobs · Coulobre Panel{% endblock %}
|
{% block title %}Scheduled Tasks · Coulobre Panel{% endblock %}
|
||||||
{% block page_header %}
|
{% block page_title %}Scheduled Tasks{% endblock %}
|
||||||
<header class="page-heading">
|
{% block page_metadata %}
|
||||||
<div>
|
{% if account %}
|
||||||
<h1>Scheduled website jobs</h1>
|
<p class="heading-meta"><span class="domain">{{ account.primary_domain }}</span> · {{ rows|length }} saved · {% if limit is None %}Unlimited{% else %}{{ limit }} allowed{% endif %}</p>
|
||||||
<p class="heading-meta">{{ rows|length }} of {{ limit|default_if_none:"Unlimited" }} saved jobs</p>
|
{% endif %}
|
||||||
</div>
|
{% endblock %}
|
||||||
{% if add_job %}
|
{% block page_actions %}
|
||||||
<a class="button primary" href="{% url 'panel:website_job_create' account.pk %}">Add job</a>
|
{% if account and not creation_blocker %}
|
||||||
{% endif %}
|
<a class="button primary" href="{% url 'panel:website_job_create' account.pk %}">Add task</a>
|
||||||
</header>
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block workspace_selector %}
|
||||||
|
{% include "hosting/workspace_account_selector.html" with account_workspace='tasks' workspace_selected=account.pk %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_context %}
|
{% block page_context %}
|
||||||
<a class="quiet-link" href="{{ account.get_absolute_url }}">← {{ account.name }}</a>
|
{% if account %}<a class="quiet-link" href="{{ account.get_absolute_url }}">← {{ account.name }}</a>{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
<section class="surface" aria-label="Scheduled website jobs">
|
{% if creation_blocker %}
|
||||||
|
<p class="notice">
|
||||||
|
{% if creation_blocker == 'service' %}
|
||||||
|
Scheduled tasks are disabled on this server.
|
||||||
|
{% if request.user.is_superuser %}<a href="{% url 'panel:operator_settings' 'server' %}">Open Operator Settings</a>{% else %}Ask your hosting provider to enable them.{% endif %}
|
||||||
|
{% elif creation_blocker == 'suspended' %}
|
||||||
|
Hosting services are suspended. Resume them before adding a task.
|
||||||
|
{% elif creation_blocker == 'no-package' %}
|
||||||
|
This account has no hosting package.
|
||||||
|
{% if is_customer %}Ask your hosting provider to assign a package that allows scheduled tasks.{% else %}Assign a package that allows scheduled tasks.{% endif %}
|
||||||
|
{% elif creation_blocker == 'disabled-by-package' %}
|
||||||
|
This hosting package has a scheduled task limit of zero.
|
||||||
|
{% if is_customer %}Ask your hosting provider to increase the limit.{% else %}Increase the limit or assign a package that allows tasks.{% endif %}
|
||||||
|
{% elif creation_blocker == 'no-website' %}
|
||||||
|
An active website is required. <a href="{{ account.get_absolute_url }}#websites">Review your websites</a>.
|
||||||
|
{% elif creation_blocker == 'limit' %}
|
||||||
|
This account has reached its scheduled task limit. Remove a saved task or {% if is_customer %}ask your hosting provider to increase the limit{% else %}increase the hosting package limit{% endif %}.
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
<section class="surface" aria-label="Scheduled tasks">
|
||||||
{% if rows %}
|
{% if rows %}
|
||||||
<div class="table-scroll">
|
<div class="table-scroll">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th scope="col">Job</th><th scope="col">Website</th><th scope="col">Schedule (UTC)</th><th scope="col">Next run</th><th scope="col">Last result</th></tr>
|
<tr><th scope="col">Task</th><th scope="col">Website</th><th scope="col">Schedule (UTC)</th><th scope="col">Next run</th><th scope="col">Last result</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for job, available in rows %}
|
{% for job, available in rows %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><a class="record-link" href="{% url 'panel:website_job_edit' account.pk job.pk %}">{{ job.name }}</a></th>
|
<th scope="row">{% if service_available %}<a class="record-link" href="{% url 'panel:website_job_edit' account.pk job.pk %}">{{ job.name }}</a>{% else %}{{ job.name }}{% endif %}</th>
|
||||||
<td class="domain">{{ job.domain }}</td>
|
<td class="domain">{{ job.domain }}</td>
|
||||||
<td><code>{{ job.expression }}</code></td>
|
<td><code>{{ job.expression }}</code></td>
|
||||||
<td>
|
<td>
|
||||||
@@ -42,8 +65,10 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
{% elif account %}
|
||||||
|
<p class="empty">No tasks have been scheduled for this account.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="empty">No website jobs scheduled.</p>
|
<p class="empty">No hosting accounts are available. Contact your hosting provider to get started.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{% if workspace_accounts %}
|
{% if workspace_accounts %}
|
||||||
<form class="workspace-context form-actions" method="get" action="{% url 'panel:customer_workspace' 'overview' %}">
|
<form class="workspace-context form-actions" method="get" action="{% url 'panel:customer_workspace' account_workspace|default:'overview' %}">
|
||||||
<label for="workspace-account">Hosting account</label>
|
<label for="workspace-account">Hosting account</label>
|
||||||
<select id="workspace-account" name="account">
|
<select id="workspace-account" name="account">
|
||||||
{% for account in workspace_accounts %}
|
{% for account in workspace_accounts %}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</header>
|
</header>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_tabs %}{% endblock %}
|
{% block page_tabs %}{% endblock %}
|
||||||
{% include "hosting/workspace_account_selector.html" %}
|
{% block workspace_selector %}{% include "hosting/workspace_account_selector.html" %}{% endblock %}
|
||||||
{% block page_context %}{% endblock %}
|
{% block page_context %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% if not request.headers.x_coulobre_status %}
|
{% if not request.headers.x_coulobre_status %}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from .models import (
|
|||||||
HostingAccount,
|
HostingAccount,
|
||||||
HostingPlan,
|
HostingPlan,
|
||||||
IndependentWebsite,
|
IndependentWebsite,
|
||||||
|
Reseller,
|
||||||
WebActivation,
|
WebActivation,
|
||||||
WebProvisioningPlan,
|
WebProvisioningPlan,
|
||||||
WebsiteDomain,
|
WebsiteDomain,
|
||||||
@@ -178,7 +179,26 @@ class WebsiteJobWorkflowTests(TestCase):
|
|||||||
|
|
||||||
def test_customer_can_add_pause_and_remove_a_job_for_its_own_site(self):
|
def test_customer_can_add_pause_and_remove_a_job_for_its_own_site(self):
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
self.client.get(self.account.get_absolute_url()), "Scheduled jobs"
|
self.client.get(self.account.get_absolute_url()), "Scheduled Tasks"
|
||||||
|
)
|
||||||
|
legacy = reverse("panel:system_workspace", args=["tasks"])
|
||||||
|
workspace = reverse("panel:customer_workspace", args=["tasks"])
|
||||||
|
self.assertRedirects(
|
||||||
|
self.client.get(legacy), workspace, fetch_redirect_response=False
|
||||||
|
)
|
||||||
|
self.assertRedirects(self.client.get(workspace), self.jobs_url)
|
||||||
|
response = self.client.get(self.jobs_url)
|
||||||
|
task_links = [
|
||||||
|
(group, url)
|
||||||
|
for group, links in response.context["navigation_groups"]
|
||||||
|
for url, label, _ in links
|
||||||
|
if label in {"Scheduled Tasks", "Scheduled Task Overview"}
|
||||||
|
]
|
||||||
|
self.assertEqual(task_links, [("Advanced Features", workspace)])
|
||||||
|
self.assertContains(response, f'href="{self.add_url}"')
|
||||||
|
self.assertContains(response, "No tasks have been scheduled")
|
||||||
|
self.assertContains(
|
||||||
|
self.client.get(self.add_url), "<h1>Add task</h1>", html=True
|
||||||
)
|
)
|
||||||
with patch(CLOCK, return_value=NOW):
|
with patch(CLOCK, return_value=NOW):
|
||||||
self.assertRedirects(
|
self.assertRedirects(
|
||||||
@@ -222,9 +242,73 @@ class WebsiteJobWorkflowTests(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertFalse(WebsiteScheduledJob.objects.exists())
|
self.assertFalse(WebsiteScheduledJob.objects.exists())
|
||||||
|
|
||||||
|
def test_task_selector_keeps_the_selected_account_in_scheduled_tasks(self):
|
||||||
|
second = HostingAccount.objects.create(
|
||||||
|
name="Second site account",
|
||||||
|
primary_domain="second.test",
|
||||||
|
customer=self.account.customer,
|
||||||
|
)
|
||||||
|
workspace = reverse("panel:customer_workspace", args=["tasks"])
|
||||||
|
second_url = reverse("panel:website_jobs", args=[second.pk])
|
||||||
|
self.assertRedirects(
|
||||||
|
self.client.get(workspace, {"account": second.pk}), second_url
|
||||||
|
)
|
||||||
|
response = self.client.get(second_url)
|
||||||
|
self.assertContains(response, f'action="{workspace}"')
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
f'<option value="{second.pk}" selected>second.test</option>',
|
||||||
|
html=True,
|
||||||
|
)
|
||||||
|
self.assertContains(response, "This account has no hosting package")
|
||||||
|
self.assertNotContains(response, "Add task")
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.get(
|
||||||
|
workspace, {"account": self.foreign.pk}
|
||||||
|
).status_code,
|
||||||
|
404,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_no_accounts_and_unavailable_tasks_have_explanations(self):
|
||||||
|
self.client.force_login(
|
||||||
|
Customer.objects.create(
|
||||||
|
user=get_user_model().objects.create_user("new-customer")
|
||||||
|
).user
|
||||||
|
)
|
||||||
|
workspace = reverse("panel:customer_workspace", args=["tasks"])
|
||||||
|
self.assertContains(
|
||||||
|
self.client.get(workspace), "No hosting accounts are available"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
with self.settings(WEBSITE_JOBS=False):
|
||||||
|
response = self.client.get(self.jobs_url)
|
||||||
|
self.assertContains(
|
||||||
|
response, "Scheduled tasks are disabled on this server"
|
||||||
|
)
|
||||||
|
self.assertNotContains(response, "Add task")
|
||||||
|
self.assertEqual(self.client.get(self.add_url).status_code, 404)
|
||||||
|
|
||||||
|
HostingPlan.objects.filter(pk=self.plan.pk).update(website_job_limit=0)
|
||||||
|
response = self.client.get(self.jobs_url)
|
||||||
|
self.assertContains(response, "scheduled task limit of zero")
|
||||||
|
self.assertNotContains(response, "Add task")
|
||||||
|
|
||||||
|
HostingPlan.objects.filter(pk=self.plan.pk).update(website_job_limit=2)
|
||||||
|
WebActivation.objects.all().delete()
|
||||||
|
IndependentWebsite.objects.filter(pk=self.site.pk).update(
|
||||||
|
activated=False
|
||||||
|
)
|
||||||
|
response = self.client.get(self.jobs_url)
|
||||||
|
self.assertContains(response, "An active website is required")
|
||||||
|
self.assertNotContains(response, "Add task")
|
||||||
|
|
||||||
def test_holding_paused_jobs_counts_toward_the_plan_limit(self):
|
def test_holding_paused_jobs_counts_toward_the_plan_limit(self):
|
||||||
self.job()
|
self.job()
|
||||||
self.job(enabled=False, next_run_at=None)
|
self.job(enabled=False, next_run_at=None)
|
||||||
|
response = self.client.get(self.jobs_url)
|
||||||
|
self.assertContains(response, "has reached its scheduled task limit")
|
||||||
|
self.assertNotContains(response, "Add task")
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
self.client.post(self.add_url, self.form()),
|
self.client.post(self.add_url, self.form()),
|
||||||
"has reached its scheduled job limit",
|
"has reached its scheduled job limit",
|
||||||
@@ -254,14 +338,49 @@ class WebsiteJobWorkflowTests(TestCase):
|
|||||||
Permission.objects.get(codename="view_hostingaccount")
|
Permission.objects.get(codename="view_hostingaccount")
|
||||||
)
|
)
|
||||||
self.assertEqual(self.client.get(self.jobs_url).status_code, 403)
|
self.assertEqual(self.client.get(self.jobs_url).status_code, 403)
|
||||||
|
missing = reverse("panel:website_jobs", args=[self.foreign.pk + 100])
|
||||||
|
self.assertEqual(self.client.get(missing).status_code, 403)
|
||||||
self.operator.user_permissions.add(
|
self.operator.user_permissions.add(
|
||||||
Permission.objects.get(codename="manage_website_jobs")
|
Permission.objects.get(codename="manage_website_jobs")
|
||||||
)
|
)
|
||||||
self.assertEqual(self.client.get(self.jobs_url).status_code, 403)
|
self.assertEqual(self.client.get(self.jobs_url).status_code, 403)
|
||||||
HostingAccount.objects.filter(pk=self.account.pk).update(customer=None)
|
HostingAccount.objects.filter(pk=self.account.pk).update(customer=None)
|
||||||
self.assertEqual(self.client.get(self.jobs_url).status_code, 200)
|
self.assertEqual(self.client.get(self.jobs_url).status_code, 200)
|
||||||
|
overview = reverse("panel:system_workspace", args=["tasks"])
|
||||||
|
self.assertContains(
|
||||||
|
self.client.get(overview), f'href="{self.jobs_url}"'
|
||||||
|
)
|
||||||
with self.settings(WEBSITE_JOBS=False):
|
with self.settings(WEBSITE_JOBS=False):
|
||||||
self.assertEqual(self.client.get(self.jobs_url).status_code, 404)
|
self.assertContains(
|
||||||
|
self.client.get(self.jobs_url),
|
||||||
|
"Scheduled tasks are disabled on this server",
|
||||||
|
)
|
||||||
|
self.assertEqual(self.client.get(self.add_url).status_code, 404)
|
||||||
|
|
||||||
|
def test_manager_overview_remains_read_only_and_scoped(self):
|
||||||
|
manager = Reseller.objects.create(
|
||||||
|
user=get_user_model().objects.create_user("manager")
|
||||||
|
)
|
||||||
|
HostingAccount.objects.filter(pk=self.account.pk).update(
|
||||||
|
reseller=manager
|
||||||
|
)
|
||||||
|
self.job(name="Visible task")
|
||||||
|
WebsiteScheduledJob.objects.create(
|
||||||
|
account=self.foreign,
|
||||||
|
domain=self.foreign.primary_domain,
|
||||||
|
name="Foreign task",
|
||||||
|
command="true",
|
||||||
|
expression="*/15 * * * *",
|
||||||
|
)
|
||||||
|
self.client.force_login(manager.user)
|
||||||
|
|
||||||
|
overview = reverse("panel:system_workspace", args=["tasks"])
|
||||||
|
response = self.client.get(overview)
|
||||||
|
self.assertContains(response, "Scheduled Task Overview")
|
||||||
|
self.assertContains(response, "Visible task")
|
||||||
|
self.assertNotContains(response, "Foreign task")
|
||||||
|
self.assertNotContains(response, f'href="{self.jobs_url}"')
|
||||||
|
self.assertEqual(self.client.get(self.add_url).status_code, 403)
|
||||||
|
|
||||||
def test_due_run_is_dispatched_and_only_claimed_once(self):
|
def test_due_run_is_dispatched_and_only_claimed_once(self):
|
||||||
job = self.job()
|
job = self.job()
|
||||||
|
|||||||
@@ -181,8 +181,7 @@ from .website_aliases import (
|
|||||||
queue_website_alias,
|
queue_website_alias,
|
||||||
)
|
)
|
||||||
from .website_file_views import can_manage_website_files
|
from .website_file_views import can_manage_website_files
|
||||||
from .website_job_views import can_manage_website_jobs
|
from .website_job_views import can_access_website_jobs
|
||||||
from .website_jobs import website_job_limit
|
|
||||||
from .workspace_onboarding import onboarding_context
|
from .workspace_onboarding import onboarding_context
|
||||||
|
|
||||||
VIEW_ACCOUNTS = "hosting.view_hostingaccount"
|
VIEW_ACCOUNTS = "hosting.view_hostingaccount"
|
||||||
@@ -671,12 +670,9 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|||||||
and owns_customer_operations(user, self.object)
|
and owns_customer_operations(user, self.object)
|
||||||
)
|
)
|
||||||
context["manage_website_files"] = manage_files
|
context["manage_website_files"] = manage_files
|
||||||
context["manage_website_jobs"] = can_manage_website_jobs(
|
context["manage_website_jobs"] = can_access_website_jobs(
|
||||||
self.request
|
self.request
|
||||||
) and (
|
) and owns_customer_operations(user, self.object)
|
||||||
website_job_limit(self.object) != 0
|
|
||||||
or self.object.website_jobs.exists()
|
|
||||||
)
|
|
||||||
context["primary_file_access"] = manage_files and site_is_active(
|
context["primary_file_access"] = manage_files and site_is_active(
|
||||||
self.object
|
self.object
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,13 +34,9 @@ from .website_jobs import (
|
|||||||
MANAGE_JOBS = ("hosting.view_hostingaccount", "hosting.manage_website_jobs")
|
MANAGE_JOBS = ("hosting.view_hostingaccount", "hosting.manage_website_jobs")
|
||||||
|
|
||||||
|
|
||||||
def can_manage_website_jobs(request):
|
def can_access_website_jobs(request):
|
||||||
user = request.user
|
impersonating = getattr(request, "impersonation", None) is not None
|
||||||
return (
|
return not impersonating and can_manage_hosting(request.user, MANAGE_JOBS)
|
||||||
panel_feature_allowed("WEBSITE_JOBS")
|
|
||||||
and getattr(request, "impersonation", None) is None
|
|
||||||
and can_manage_hosting(user, MANAGE_JOBS)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WebsiteJobForm(forms.Form):
|
class WebsiteJobForm(forms.Form):
|
||||||
@@ -107,13 +103,8 @@ class WebsiteJobAccountView(
|
|||||||
customer_relation = "customer"
|
customer_relation = "customer"
|
||||||
permission_required = MANAGE_JOBS
|
permission_required = MANAGE_JOBS
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
if not panel_feature_allowed("WEBSITE_JOBS"):
|
|
||||||
raise Http404
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def has_permission(self):
|
def has_permission(self):
|
||||||
return can_manage_website_jobs(
|
return can_access_website_jobs(
|
||||||
self.request
|
self.request
|
||||||
) and owns_customer_operations(self.request.user, self.account)
|
) and owns_customer_operations(self.request.user, self.account)
|
||||||
|
|
||||||
@@ -127,9 +118,25 @@ class WebsiteJobList(WebsiteJobAccountView):
|
|||||||
account = self.account
|
account = self.account
|
||||||
jobs = list(account.website_jobs.all())
|
jobs = list(account.website_jobs.all())
|
||||||
limit = website_job_limit(account)
|
limit = website_job_limit(account)
|
||||||
|
service_available = panel_feature_allowed("WEBSITE_JOBS")
|
||||||
sites = (
|
sites = (
|
||||||
{} if account.services_suspended else available_job_sites(account)
|
available_job_sites(account)
|
||||||
|
if service_available and not account.services_suspended
|
||||||
|
else {}
|
||||||
)
|
)
|
||||||
|
blocker = None
|
||||||
|
if not service_available:
|
||||||
|
blocker = "service"
|
||||||
|
elif account.services_suspended:
|
||||||
|
blocker = "suspended"
|
||||||
|
elif account.hosting_plan_id is None:
|
||||||
|
blocker = "no-package"
|
||||||
|
elif limit == 0:
|
||||||
|
blocker = "disabled-by-package"
|
||||||
|
elif not sites:
|
||||||
|
blocker = "no-website"
|
||||||
|
elif limit is not None and len(jobs) >= limit:
|
||||||
|
blocker = "limit"
|
||||||
active = {(site.site_id, site.domain) for site in sites.values()}
|
active = {(site.site_id, site.domain) for site in sites.values()}
|
||||||
enabled_count = 0
|
enabled_count = 0
|
||||||
rows = []
|
rows = []
|
||||||
@@ -149,13 +156,18 @@ class WebsiteJobList(WebsiteJobAccountView):
|
|||||||
"account": account,
|
"account": account,
|
||||||
"rows": rows,
|
"rows": rows,
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
"add_job": bool(sites)
|
"service_available": service_available,
|
||||||
and (limit is None or len(jobs) < limit),
|
"creation_blocker": blocker,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class WebsiteJobEditor(WebsiteJobAccountView):
|
class WebsiteJobEditor(WebsiteJobAccountView):
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if not panel_feature_allowed("WEBSITE_JOBS"):
|
||||||
|
raise Http404
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def job(self):
|
def job(self):
|
||||||
if "job_pk" not in self.kwargs:
|
if "job_pk" not in self.kwargs:
|
||||||
|
|||||||
@@ -8,11 +8,15 @@ from django.utils import timezone
|
|||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
from django.views.decorators.http import require_safe
|
from django.views.decorators.http import require_safe
|
||||||
|
|
||||||
from .access import customer_for_user, reseller_for_user
|
from .access import (
|
||||||
|
customer_for_user,
|
||||||
|
owns_customer_operations,
|
||||||
|
reseller_for_user,
|
||||||
|
)
|
||||||
from .account_metrics import account_metrics
|
from .account_metrics import account_metrics
|
||||||
from .installation_features import panel_feature_allowed
|
from .installation_features import panel_feature_allowed
|
||||||
from .models import HostingAccount, WebsiteScheduledJob
|
from .models import HostingAccount, WebsiteScheduledJob
|
||||||
from .website_job_views import can_manage_website_jobs
|
from .website_job_views import can_access_website_jobs
|
||||||
from .workspace_onboarding import workspace_role
|
from .workspace_onboarding import workspace_role
|
||||||
|
|
||||||
CUSTOMER_ACCOUNT = "coulobre_active_hosting_account"
|
CUSTOMER_ACCOUNT = "coulobre_active_hosting_account"
|
||||||
@@ -35,7 +39,7 @@ CUSTOMER_PAGES = {
|
|||||||
"tasks": ("Scheduled Tasks", "website_jobs", ""),
|
"tasks": ("Scheduled Tasks", "website_jobs", ""),
|
||||||
}
|
}
|
||||||
SYSTEM_PAGES = {
|
SYSTEM_PAGES = {
|
||||||
"tasks": ("Scheduled Tasks", "website_jobs"),
|
"tasks": ("Scheduled Task Overview", None),
|
||||||
"logs": ("Logs", "website_usage"),
|
"logs": ("Logs", "website_usage"),
|
||||||
"statistics": ("Statistics", "website_usage"),
|
"statistics": ("Statistics", "website_usage"),
|
||||||
}
|
}
|
||||||
@@ -131,7 +135,6 @@ def customer_pages(request):
|
|||||||
("redirects", panel_feature_allowed("LOCAL_WEB_ACTIVATION")),
|
("redirects", panel_feature_allowed("LOCAL_WEB_ACTIVATION")),
|
||||||
("sftp", settings.LOCAL_WEB_SFTP),
|
("sftp", settings.LOCAL_WEB_SFTP),
|
||||||
("backups", panel_feature_allowed("LOCAL_ACCOUNT_BACKUPS")),
|
("backups", panel_feature_allowed("LOCAL_ACCOUNT_BACKUPS")),
|
||||||
("tasks", panel_feature_allowed("WEBSITE_JOBS")),
|
|
||||||
):
|
):
|
||||||
if not enabled:
|
if not enabled:
|
||||||
pages.pop(key)
|
pages.pop(key)
|
||||||
@@ -163,6 +166,8 @@ def customer_workspace(request, page):
|
|||||||
).first()
|
).first()
|
||||||
account = account or accounts.first()
|
account = account or accounts.first()
|
||||||
if account is None:
|
if account is None:
|
||||||
|
if page == "tasks":
|
||||||
|
return render(request, "hosting/website_jobs.html")
|
||||||
return redirect("panel:accounts")
|
return redirect("panel:accounts")
|
||||||
if page == "overview":
|
if page == "overview":
|
||||||
return redirect(account)
|
return redirect(account)
|
||||||
@@ -194,21 +199,21 @@ def system_workspace(request, page):
|
|||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
if page not in SYSTEM_PAGES:
|
if page not in SYSTEM_PAGES:
|
||||||
raise Http404
|
raise Http404
|
||||||
|
if page == "tasks" and customer_for_user(request.user) is not None:
|
||||||
|
return redirect("panel:customer_workspace", page="tasks")
|
||||||
title, target = SYSTEM_PAGES[page]
|
title, target = SYSTEM_PAGES[page]
|
||||||
accounts = workspace_accounts(request.user).order_by("primary_domain")
|
accounts = workspace_accounts(request.user).order_by("primary_domain")
|
||||||
operator = (
|
operator = (
|
||||||
customer_for_user(request.user) is None
|
customer_for_user(request.user) is None
|
||||||
and reseller_for_user(request.user) is None
|
and reseller_for_user(request.user) is None
|
||||||
)
|
)
|
||||||
if page == "tasks":
|
may_open = (
|
||||||
may_open = can_manage_website_jobs(request)
|
bool(target)
|
||||||
may_view_tasks = not operator or request.user.has_perm(
|
and settings.WEBSITE_USAGE
|
||||||
"hosting.manage_website_jobs"
|
and (
|
||||||
)
|
|
||||||
else:
|
|
||||||
may_open = settings.WEBSITE_USAGE and (
|
|
||||||
not operator or request.user.has_perm("hosting.view_websiteusage")
|
not operator or request.user.has_perm("hosting.view_websiteusage")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
pagination = Paginator(accounts, 25)
|
pagination = Paginator(accounts, 25)
|
||||||
page_obj = pagination.get_page(request.GET.get("page"))
|
page_obj = pagination.get_page(request.GET.get("page"))
|
||||||
month = timezone.now().strftime("%Y-%m")
|
month = timezone.now().strftime("%Y-%m")
|
||||||
@@ -226,13 +231,19 @@ def system_workspace(request, page):
|
|||||||
)
|
)
|
||||||
rows = [(account, measures.get(account.pk, {})) for account in page_obj]
|
rows = [(account, measures.get(account.pk, {})) for account in page_obj]
|
||||||
tasks = ()
|
tasks = ()
|
||||||
task_accounts = {account.pk for account, _ in rows}
|
manageable_accounts = {}
|
||||||
if page == "tasks" and may_view_tasks:
|
if page == "tasks" and (
|
||||||
tasks = (
|
not operator or request.user.has_perm("hosting.manage_website_jobs")
|
||||||
WebsiteScheduledJob.objects.filter(account_id__in=task_accounts)
|
):
|
||||||
.select_related("account")
|
if can_access_website_jobs(request):
|
||||||
.order_by("domain", "name")[:250]
|
manageable_accounts = {
|
||||||
)
|
account.pk: account
|
||||||
|
for account, _ in rows
|
||||||
|
if owns_customer_operations(request.user, account)
|
||||||
|
}
|
||||||
|
tasks = WebsiteScheduledJob.objects.filter(
|
||||||
|
account_id__in=[account.pk for account, _ in rows]
|
||||||
|
).order_by("domain", "name")[:250]
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"hosting/system_workspace.html",
|
"hosting/system_workspace.html",
|
||||||
@@ -241,6 +252,7 @@ def system_workspace(request, page):
|
|||||||
"section": page,
|
"section": page,
|
||||||
"rows": rows,
|
"rows": rows,
|
||||||
"tasks": tasks,
|
"tasks": tasks,
|
||||||
|
"manageable_accounts": manageable_accounts,
|
||||||
"month": month,
|
"month": month,
|
||||||
"page_obj": page_obj,
|
"page_obj": page_obj,
|
||||||
"is_paginated": pagination.num_pages > 1,
|
"is_paginated": pagination.num_pages > 1,
|
||||||
@@ -452,6 +464,7 @@ def groups_for(request, *, customer, manager):
|
|||||||
system = [
|
system = [
|
||||||
link("system_workspace", title, key)
|
link("system_workspace", title, key)
|
||||||
for key, (title, _) in SYSTEM_PAGES.items()
|
for key, (title, _) in SYSTEM_PAGES.items()
|
||||||
|
if not customer or key != "tasks"
|
||||||
]
|
]
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
system.append(link("updates", "Updates"))
|
system.append(link("updates", "Updates"))
|
||||||
|
|||||||
Reference in new issue
Block a user