Metadata-Version: 2.1
Name: edx-notices
Version: 0.15.0
Summary: An edx-platform plugin which manages notices that must be acknowledged
Home-page: https://github.com/edx/platform-plugin-notices
Author: edX
Author-email: mtuchfarber@edx.org
License: AGPL 3.0
Keywords: Python edx
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >3.8
License-File: LICENSE.txt
Requires-Dist: Django>=1.11
Requires-Dist: django-model-utils
Requires-Dist: django-rest-framework
Requires-Dist: django-simple-history
Requires-Dist: edx-drf-extensions
Requires-Dist: edx-toggles

platform-plugin-notices
=============================

|pypi-badge| |ci-badge| |codecov-badge| |doc-badge| |pyversions-badge| |license-badge|

**This repo is not currently accepting open source contributions**

Overview
--------

This plugin for edx-platform manages notices that a user must acknowledge. It only stores the content of the notices and whether a user has acknowledged them. Presentation and other client side decisions will be left to the frontends that utilize these APIs.

This Django app contains notices that a user must acknowledge before continuing to use the site. This app will have two API endpoints to facilitate that:
1. An endpoint to return links to all notices that the user hasn't acknowledged.
2. An endpoint to acknowledge that a user has seen the notice. This endpoint's URL will be passed to the client via the first endpoint.

Two ways to show a notice
~~~~~~~~~~~~~~~~~~~~~~~~~

Notices are created and edited in Django Admin (``Notice`` with one ``TranslatedNoticeContent`` per language, an ``en`` row is required as the fallback). No deploy is needed to add, change or switch off a notice (untick ``active``).

* **Full-page notices (default).** ``GET /notices/api/v1/unacknowledged`` returns links to the rendered notice pages. Frontends such as the Learning MFE redirect the learner to the page, which acknowledges through ``POST /notices/api/v1/acknowledge``. The global flag ``notices.enable_notices`` turns this on.
* **Refund policy modal.** ``GET /notices/api/v1/refund-policy`` returns ``{"show", "notice_id", "body", "language"}`` as JSON so an MFE can show the notice in a modal (see ``@edx/refund-policy-notice-plugin`` in ``frontend-plugins``, mounted in the ``header_notice_slot`` of ``frontend-component-header-edx``). It is served for the ``Notice`` whose name equals the ``NOTICES_REFUND_POLICY_NOTICE_NAME`` setting (default ``Refund Policy Change``) and is controlled by the waffle flag ``commerce.show_refund_policy_change_notice``. It ignores ``launch_date`` and snoozing, strips HTML from the body, and the modal acknowledges with ``POST /notices/api/v1/acknowledge`` (``confirmed``). That notice is excluded from the ``unacknowledged`` list, so it never redirects to a full page.

Refund policy modal notes:

* The ``Notice`` name must match ``NOTICES_REFUND_POLICY_NOTICE_NAME`` exactly and must not be renamed afterwards. The name decides how the notice is shown: if it no longer matches, the notice becomes a full-page notice and appears in ``unacknowledged`` (when ``notices.enable_notices`` is on), and learners are redirected to a page with no confirm button.
* The body is converted from HTML to plain text: paragraphs are separated by one blank line, ``<br>`` becomes a line break, links keep only their text (the URL is dropped), and the contents of ``<style>``, ``<script>`` or ``<button>`` show up as text, so keep the HTML to simple paragraphs.
* The notice is web only. Mobile apps calling ``unacknowledged?mobile=true`` do not receive it.
* ``edx.bi.user.displayed_notice`` and ``edx.bi.user.acknowledged_notice`` are emitted server side with ``tracker.emit``, so they always reach the tracking log. They reach Segment only if both names are in ``EVENT_TRACKING_SEGMENTIO_EMIT_WHITELIST`` in the LMS config. Full-page notices send the acknowledgement event to Segment from the browser, so add both names to the whitelist to keep the two in one place.

Documentation
-------------

(TODO: `Set up documentation <https://openedx.atlassian.net/wiki/spaces/DOC/pages/21627535/Publish+Documentation+on+Read+the+Docs>`_)

Developing in Devstack
~~~~~~~~~~~~~~~~~~~~~~
Make sure the LMS container is running in Devstack, then

.. code-block::

  git clone git@github.com:edx/platform-plugin-notices.git <devstack_folder>/src
  cd <devstack_folder>/devstack
  make dev.shell.lms
  pip install -e /edx/src/platform-plugin-notices
  cd /edx/app/edxapp/edx-platform
  ./manage.py lms migrate

Once that is done, LMS will pickup the plugin and saves to existing files should cause a devserver restart with your changes. Occasionally when adding a new file, you may need to restart the LMS container in order for it to pickup the changes.

Enabling the Notices Plugin in the LMS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Notices plugin functionality is enabled via use of a waffle flag. After installation of the plugin you need to do the following in devstack:

#. Log into the LMS Django Admin (http://localhost:18000/admin/)
#. Add a new waffle flag (http://localhost:18000/admin/waffle/flag/add/)
#. Name the waffle flag ``notices.enable_notices``
#. Set `Everyone` to `Yes`
#. Save the waffle flag.

License
-------

The code in this repository is licensed under the AGPL 3.0 unless
otherwise noted.

Please see `LICENSE.txt <LICENSE.txt>`_ for details.

How To Contribute
-----------------

This repo is not currently accepting open source contributions

Reporting Security Issues
-------------------------

Please do not report security issues in public. Please email security@edx.org.

Support
-------

If you're having trouble, we have discussion forums at https://discuss.openedx.org where you can connect with others in the community.

Our real-time conversations are on Slack. You can request a `Slack invitation`_, then join our `community Slack workspace`_.

For more information about these options, see the `Getting Help`_ page.

.. _Slack invitation: https://openedx-slack-invite.herokuapp.com/
.. _community Slack workspace: https://openedx.slack.com/
.. _Getting Help: https://openedx.org/getting-help

.. |pypi-badge| image:: https://img.shields.io/pypi/v/edx-notices.svg
    :target: https://pypi.python.org/pypi/edx-notices/
    :alt: PyPI

.. |ci-badge| image:: https://github.com/edx/platform-plugin-notices/workflows/Python%20CI/badge.svg?branch=main
    :target: https://github.com/edx/platform-plugin-notices/actions
    :alt: CI

.. |codecov-badge| image:: https://codecov.io/github/edx/platform-plugin-notices/coverage.svg?branch=main
    :target: https://codecov.io/github/edx/platform-plugin-notices?branch=main
    :alt: Codecov

.. |doc-badge| image:: https://readthedocs.org/projects/platform-plugin-notices/badge/?version=latest
    :target: https://platform-plugin-notices.readthedocs.io/en/latest/
    :alt: Documentation

.. |pyversions-badge| image:: https://img.shields.io/pypi/pyversions/edx-notices.svg
    :target: https://pypi.python.org/pypi/platform-plugin-notices/
    :alt: Supported Python versions

.. |license-badge| image:: https://img.shields.io/github/license/edx/platform-plugin-notices.svg
    :target: https://github.com/edx/platform-plugin-notices/blob/main/LICENSE.txt
    :alt: License


Change Log
----------

..
   All enhancements and patches to notices will be documented
   in this file.  It adheres to the structure of https://keepachangelog.com/ ,
   but in reStructuredText instead of Markdown (for ease of incorporation into
   Sphinx documentation and the PyPI description).

   This project adheres to Semantic Versioning (https://semver.org/).

.. There should always be an "Unreleased" section for changes pending release.

Unreleased
~~~~~~~~~~

[0.15.0] - 2026-11-18
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Added ``GET /notices/api/v1/refund-policy`` returning the refund policy change notice as JSON for MFE modals,
  gated by the ``commerce.show_refund_policy_change_notice`` flag and the ``NOTICES_REFUND_POLICY_NOTICE_NAME`` setting.
* The refund policy notice is excluded from ``GET /notices/api/v1/unacknowledged`` so MFEs do not redirect to its
  full page; it is shown only as a modal.
* Emit server-side ``edx.bi.user.displayed_notice`` (each time the modal notice is returned) and
  ``edx.bi.user.acknowledged_notice`` (modal notice only; full-page notices still report it from the browser).

[0.14.55] - 2023-09-25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fixed PyPI Publish workflow

[0.14.53] - 2023-09-22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Added Django 4.2 Support

[0.14.20] - 2022-07-01
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Updating Python Requirements

[0.14.15] - 2022-07-01
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Updating Python Requirements

[0.14.11] - 2022-06-01
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Updating Python Requirements

[0.14.4] - 2022-02-14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Changed Do not redirect notices/render/{id}/ to login page in case of 403 on mobile request

[0.14.3] - 2022-02-07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Update pip-tools

[0.14.2] - 2022-01-28
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Update Python dependencies

[0.14.1] - 2022-01-05
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Update Python dependencies

[0.14.0] - 2021-11-24
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add logging

[0.13.0] - 2021-11-24
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Added history table to AcknowledgedNotice

[0.12.0] - 2021-11-2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Added support for django 3.2 and dropped support for previous versions

[0.11.8] - 2021-11-10
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Update Python dependencies

[0.11.7] - 2021-11-10
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add userLanguage flag so JavaScript-rendered text can be displayed in the correct language

[0.11.6] - 2021-11-10
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add mobile flag so mobile can be disabled in production

[0.11.5] - 2021-11-09
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add lang tag to HTML element

[0.11.4] - 2021-11-08
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Change name of segment event from "acquisition" to "notice"

[0.11.3] - 2021-11-05
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Allow user to leave page even if API call fails (important for mobile)

[0.11.2] - 2021-11-04
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Updated Django admin form list display and searchable fields.

[0.11.1] - 2021-10-29
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* fix analytics key in template

[0.11.0] - 2021-11-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add in a setting to limit the number of days you can snooze a notice.

[0.10.3] - 2021-10-29
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix dismiss button redirecting

[0.10.2] - 2021-10-29
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* fix analytics key

[0.10.1] - 2021-10-29
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Limit notices to users who were created before it was released

[0.10.0] - 2021-10-25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add segment library for event tracking

[0.9.0] - 2021-10-25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add in a snooze limit feature that will only allow a notice to be snoozed a number of times

[0.8.2] - 2021-10-21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Update requirements

[0.8.1] - 2021-10-21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add ability to reshow notice after a snooze period via setting

[0.7.3] - 2021-10-20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Make AcknowledgedNotice user editable in the admin for testing purposes

[0.7.2] - 2021-10-19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Make AcknowledgedNotice user readonly in the admin for performance

[0.7.1] - 2021-10-19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add Waffle Flag to enable and disable the feature for rollout

[0.6.1] - 2021-10-7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add Python API for retrieving unack'd and active notice data
* Add Plugin Context API for notice data to support redirects on the LMS Course Dashboard

[0.5.1] - 2021-10-7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Disallow dismissal after confirmation of notice

[0.4.1] - 2021-10-7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Allow inactive (non-email-verified) users to call APIs

[0.3.1] - 2021-10-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add mobile calls so notice code can deep link

[0.2.2] - 2021-09-24
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add fallback language on render view
* Add Bearer auth to APIs for mobile
* Add login requirement to render view
* Add first edx-platform dependency

[0.2.1] - 2021-09-22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Utility functions for custom notice code to use to call APIs

[0.1.1] - 2021-09-16
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Moved to server rendered notice model
* Add mandatory types to acknowledgement to track more states

[0.1.0] - 2021-08-19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* First release on PyPI.
