feat: added setting to disable the survey report banner entirely (#34092)
* feat: added setting to disable the survey report banner entirely * fix: fixed unit test with new setting * refactor: changed conditions for better code readability * feat: added exception to stop the report from generating if the setting is set to false * chore: updated the readme file to include the new setting * refactor: move survey settings to common and disable admin by setting * docs: typos in README Co-authored-by: Tim McCormack <tmccormack@edx.org> * refactor: set default values to survey report settings * refactor: rename ENABLE_SURVEY_REPORT setting to SURVEY_REPORT_ENABLE * test: fix quality tests --------- Co-authored-by: Alejandro Cardenas <alecar.main@gmail.com> Co-authored-by: Tim McCormack <tmccormack@edx.org>
This commit is contained in:
@@ -5478,3 +5478,31 @@ derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.cert
|
||||
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.revoked.v1',
|
||||
'learning-certificate-lifecycle', 'enabled')
|
||||
BEAMER_PRODUCT_ID = ""
|
||||
|
||||
#### Survey Report ####
|
||||
# .. toggle_name: SURVEY_REPORT_ENABLE
|
||||
# .. toggle_implementation: DjangoSetting
|
||||
# .. toggle_default: True
|
||||
# .. toggle_description: Set to True to enable the feature to generate and send survey reports.
|
||||
# .. toggle_use_cases: open_edx
|
||||
# .. toggle_creation_date: 2024-01-30
|
||||
SURVEY_REPORT_ENABLE = True
|
||||
# .. setting_name: SURVEY_REPORT_ENDPOINT
|
||||
# .. setting_default: Open edX organization endpoint
|
||||
# .. setting_description: Endpoint where the report will be sent.
|
||||
SURVEY_REPORT_ENDPOINT = 'https://hooks.zapier.com/hooks/catch/11595998/3ouwv7m/'
|
||||
# .. toggle_name: ANONYMOUS_SURVEY_REPORT
|
||||
# .. toggle_implementation: DjangoSetting
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: If enable, the survey report will be send a UUID as ID instead of use lms site name.
|
||||
# .. toggle_use_cases: open_edx
|
||||
# .. toggle_creation_date: 2023-02-21
|
||||
ANONYMOUS_SURVEY_REPORT = False
|
||||
# .. setting_name: SURVEY_REPORT_CHECK_THRESHOLD
|
||||
# .. setting_default: every 6 months
|
||||
# .. setting_description: Survey report banner will appear if a survey report is not sent in the months defined.
|
||||
SURVEY_REPORT_CHECK_THRESHOLD = 6
|
||||
# .. setting_name: SURVEY_REPORT_EXTRA_DATA
|
||||
# .. setting_default: empty dictionary
|
||||
# .. setting_description: Dictionary with additional information that you want to share in the report.
|
||||
SURVEY_REPORT_EXTRA_DATA = {}
|
||||
|
||||
@@ -1125,14 +1125,6 @@ COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = {
|
||||
"URL": ENV_TOKENS.get('BIG_BLUE_BUTTON_GLOBAL_URL', None),
|
||||
}
|
||||
|
||||
############## Settings for survey report ##############
|
||||
SURVEY_REPORT_EXTRA_DATA = ENV_TOKENS.get('SURVEY_REPORT_EXTRA_DATA', {})
|
||||
SURVEY_REPORT_ENDPOINT = ENV_TOKENS.get('SURVEY_REPORT_ENDPOINT',
|
||||
'https://hooks.zapier.com/hooks/catch/11595998/3ouwv7m/')
|
||||
ANONYMOUS_SURVEY_REPORT = ENV_TOKENS.get('ANONYMOUS_SURVEY_REPORT', False)
|
||||
|
||||
SURVEY_REPORT_CHECK_THRESHOLD = ENV_TOKENS.get('SURVEY_REPORT_CHECK_THRESHOLD', 6)
|
||||
|
||||
AVAILABLE_DISCUSSION_TOURS = ENV_TOKENS.get('AVAILABLE_DISCUSSION_TOURS', [])
|
||||
|
||||
############## NOTIFICATIONS EXPIRY ##############
|
||||
|
||||
@@ -664,6 +664,7 @@ MFE_CONFIG_OVERRIDES = {
|
||||
SURVEY_REPORT_EXTRA_DATA = {}
|
||||
SURVEY_REPORT_ENDPOINT = "https://example.com/survey_report"
|
||||
SURVEY_REPORT_CHECK_THRESHOLD = 6
|
||||
SURVEY_REPORT_ENABLE = True
|
||||
ANONYMOUS_SURVEY_REPORT = False
|
||||
|
||||
######################## Subscriptions API SETTINGS ########################
|
||||
|
||||
@@ -65,6 +65,7 @@ You have the following settings to customize the behavior of your reports.
|
||||
|
||||
- ``ANONYMOUS_SURVEY_REPORT``: This is a boolean to specify if you want to use your LMS domain as ID for your report or to send the information anonymously with a UUID. By default, this setting is False.
|
||||
|
||||
- ``SURVEY_REPORT_ENABLE``: This is a boolean to specify if you want to enable or disable the survey report feature completely. The banner will disappear and the report generation will be disabled if set to False. By default, this setting is True.
|
||||
|
||||
About the Survey Report Admin Banner
|
||||
-------------------------------------
|
||||
@@ -74,4 +75,4 @@ This app implements a banner to make it easy for the Open edX operators to gener
|
||||
.. image:: docs/_images/survey_report_banner.png
|
||||
:alt: Survey Report Banner
|
||||
|
||||
**Note:** The banner will appear if a survey report is not sent in the months defined in the ``context_processor`` file, by default, is set to appear monthly.
|
||||
**Note:** The banner will appear if a survey report is not sent in the months defined in the ``context_processor`` file, by default, is set to appear every 6 months.
|
||||
|
||||
@@ -4,6 +4,7 @@ Django Admin page for SurveyReport.
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.conf import settings
|
||||
from .models import SurveyReport
|
||||
from .api import send_report_to_external_api
|
||||
|
||||
@@ -80,4 +81,6 @@ class SurveyReportAdmin(admin.ModelAdmin):
|
||||
del actions['delete_selected']
|
||||
return actions
|
||||
|
||||
admin.site.register(SurveyReport, SurveyReportAdmin)
|
||||
|
||||
if settings.SURVEY_REPORT_ENABLE:
|
||||
admin.site.register(SurveyReport, SurveyReportAdmin)
|
||||
|
||||
@@ -45,6 +45,8 @@ def get_report_data() -> dict:
|
||||
|
||||
def generate_report() -> None:
|
||||
""" Generate a report with relevant data."""
|
||||
if not settings.SURVEY_REPORT_ENABLE:
|
||||
raise Exception("Survey report generation is not enabled")
|
||||
data = {}
|
||||
survey_report = SurveyReport(**data)
|
||||
survey_report.save()
|
||||
|
||||
@@ -1,34 +1,64 @@
|
||||
"""
|
||||
This is the survey report contex_processor modules
|
||||
This module provides context processors for integrating survey report functionality
|
||||
into Django admin sites.
|
||||
|
||||
This is meant to determine the visibility of the survey report banner
|
||||
across all admin pages in case a survey report has not been generated
|
||||
It includes functions for determining whether to display a survey report banner and
|
||||
calculating the date threshold for displaying the banner.
|
||||
|
||||
Functions:
|
||||
- admin_extra_context(request):
|
||||
Sends extra context to every admin site, determining whether to display the
|
||||
survey report banner based on defined settings and conditions.
|
||||
|
||||
- should_show_survey_report_banner():
|
||||
Determines whether to show the survey report banner based on the threshold.
|
||||
|
||||
- get_months_threshold(months):
|
||||
Calculates the date threshold based on the specified number of months.
|
||||
|
||||
Dependencies:
|
||||
- Django: settings, reverse, shortcuts
|
||||
- datetime: datetime
|
||||
- dateutil.relativedelta: relativedelta
|
||||
|
||||
Usage:
|
||||
This module is designed to be imported into Django projects with admin functionality.
|
||||
It enhances the admin interface by providing dynamic context for displaying a survey
|
||||
report banner based on defined conditions and settings.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta # for months test
|
||||
from .models import SurveyReport
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from .models import SurveyReport
|
||||
|
||||
|
||||
def admin_extra_context(request):
|
||||
"""
|
||||
This function sends extra context to every admin site
|
||||
|
||||
The current treshhold to show the banner is one month but this can be redefined in the future
|
||||
|
||||
This function sends extra context to every admin site.
|
||||
The current threshold to show the banner is one month but this can be redefined in the future.
|
||||
"""
|
||||
months = settings.SURVEY_REPORT_CHECK_THRESHOLD
|
||||
if not request.path.startswith(reverse('admin:index')):
|
||||
return {'show_survey_report_banner': False, }
|
||||
if not settings.SURVEY_REPORT_ENABLE or not request.path.startswith(reverse('admin:index')):
|
||||
return {'show_survey_report_banner': False}
|
||||
|
||||
return {'show_survey_report_banner': should_show_survey_report_banner()}
|
||||
|
||||
|
||||
def should_show_survey_report_banner():
|
||||
"""
|
||||
Determine whether to show the survey report banner based on the threshold.
|
||||
"""
|
||||
months_threshold = get_months_threshold(settings.SURVEY_REPORT_CHECK_THRESHOLD)
|
||||
|
||||
try:
|
||||
latest_report = SurveyReport.objects.latest('created_at')
|
||||
months_treshhold = datetime.today().date() - relativedelta(months=months) # Calculate date one month ago
|
||||
show_survey_report_banner = latest_report.created_at.date() <= months_treshhold
|
||||
return latest_report.created_at.date() <= months_threshold
|
||||
except SurveyReport.DoesNotExist:
|
||||
show_survey_report_banner = True
|
||||
return True
|
||||
|
||||
return {'show_survey_report_banner': show_survey_report_banner, }
|
||||
|
||||
def get_months_threshold(months):
|
||||
"""
|
||||
Calculate the date threshold based on the specified number of months.
|
||||
"""
|
||||
return datetime.today().date() - relativedelta(months=months)
|
||||
|
||||
Reference in New Issue
Block a user