|
10 | 10 | from django.utils import timezone
|
11 | 11 |
|
12 | 12 | from dojo.celery import app
|
13 |
| -from dojo.models import Alerts, Engagement, Finding, Product, System_Settings, User |
| 13 | +from dojo.models import Alerts, Announcement, Endpoint, Engagement, Finding, Product, System_Settings, User |
14 | 14 | from dojo.notifications.helper import create_notification
|
15 | 15 | from dojo.utils import calculate_grade, sla_compute_and_notify
|
16 | 16 |
|
@@ -190,3 +190,30 @@ def jira_status_reconciliation_task(*args, **kwargs):
|
190 | 190 | def fix_loop_duplicates_task(*args, **kwargs):
|
191 | 191 | from dojo.finding.helper import fix_loop_duplicates
|
192 | 192 | return fix_loop_duplicates()
|
| 193 | + |
| 194 | + |
| 195 | +@app.task |
| 196 | +def evaluate_pro_proposition(*args, **kwargs): |
| 197 | + # Ensure we should be doing this |
| 198 | + if not settings.CREATE_CLOUD_BANNER: |
| 199 | + return |
| 200 | + # Get the announcement object |
| 201 | + announcement = Announcement.objects.get_or_create(id=1)[0] |
| 202 | + # Quick check for a user has modified the current banner - if not, exit early as we dont want to stomp |
| 203 | + if not any( |
| 204 | + entry in announcement.message |
| 205 | + for entry in [ |
| 206 | + "", |
| 207 | + "Cloud and On-Premise Subscriptions Now Available!", |
| 208 | + "Findings/Endpoints in their systems", |
| 209 | + ] |
| 210 | + ): |
| 211 | + return |
| 212 | + # Count the objects the determine if the banner should be updated |
| 213 | + object_count = Finding.objects.count() + Endpoint.objects.count() |
| 214 | + # Unless the count is greater than 100k, exit early |
| 215 | + if object_count < 100000: |
| 216 | + return |
| 217 | + # Update the announcement |
| 218 | + announcement.message = f'Only professionals have {object_count:,} Findings and Endpoints in their systems... <a href="https://www.defectdojo.com/pricing" target="_blank">Get DefectDojo Pro</a> today!' |
| 219 | + announcement.save() |
0 commit comments