Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to show banner announcements #513

Merged
merged 10 commits into from
Mar 22, 2024
14 changes: 14 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"simple_history",
"dbbackup",
"django_htmx",
"constance",
"constance.backends.database",
]

LOCAL_APPS = [
Expand Down Expand Up @@ -205,6 +207,7 @@
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"constance.context_processors.config",
"primed.utils.context_processors.settings_context",
],
},
Expand Down Expand Up @@ -368,6 +371,17 @@
# https://django-tables2.readthedocs.io/en/latest/pages/custom-rendering.html?highlight=django_tables2_template#available-templates
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html"

# django-constance
# ------------------------------------------------------------------------------
CONSTANCE_CONFIG = {
"ANNOUNCEMENT_TEXT": ("", "Site-wide announcement message", str),
}

CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_IGNORE_ADMIN_VERSION_CHECK = True
# CONSTANCE_DATABASE_CACHE_BACKEND = "default"
CONSTANCE_DATABASE_CACHE_AUTOFILL_TIMEOUT = None

# django-anvil-consortium-manager
# ------------------------------------------------------------------------------
ANVIL_API_SERVICE_ACCOUNT_FILE = env("ANVIL_API_SERVICE_ACCOUNT_FILE")
Expand Down
25 changes: 25 additions & 0 deletions primed/primed_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from anvil_consortium_manager import models as acm_models
from anvil_consortium_manager.tests.factories import AccountFactory
from anvil_consortium_manager.views import AccountList
from constance.test import override_config
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
Expand Down Expand Up @@ -133,6 +134,12 @@ def test_user_has_not_linked_account(self):
response, reverse("anvil_consortium_manager:accounts:link")
)

def test_unauthenticated_user_has_not_linked_account_message(self):
response = self.client.get(settings.LOGIN_URL, follow=True)
self.assertNotContains(
response, reverse("anvil_consortium_manager:accounts:link")
)

def test_staff_view_links(self):
user = UserFactory.create()
user.user_permissions.add(
Expand Down Expand Up @@ -163,6 +170,24 @@ def test_view_links(self):
response, '"{}"'.format(reverse("anvil_consortium_manager:index"))
)

def test_site_announcement_no_text(self):
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertNotContains(response, """id="alert-announcement""")

@override_config(ANNOUNCEMENT_TEXT="This is a test announcement")
def test_site_announcement_text(self):
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertContains(response, """id="alert-announcement""")
self.assertContains(response, "This is a test announcement")

@override_config(ANNOUNCEMENT_TEXT="This is a test announcement")
def test_site_announcement_text_unauthenticated_user(self):
response = self.client.get(self.get_url(), follow=True)
self.assertContains(response, """id="alert-announcement""")
self.assertContains(response, "This is a test announcement")


class StudyDetailTest(TestCase):
"""Tests for the StudyDetail view."""
Expand Down
4 changes: 0 additions & 4 deletions primed/static/css/project.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions primed/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,32 @@
</div>
</nav>

{% block extra_navbar %}
{% endblock %}
<main class="flex-shrink-0">
<div class="container">
<div class="container">

{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %} alert-dismissible fade show" role="alert">{{ message }}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>
{% endfor %}
{% if config.ANNOUNCEMENT_TEXT %}
<div class="alert alert-info" role="alert" id="alert-announcement">
<i class="bi bi-megaphone-fill me-1"></i>
{{ config.ANNOUNCEMENT_TEXT }}
</div>
{% endif %}

{% if not request.user.account %}
<div class="alert alert-info" role="alert">
{% if request.user.is_authenticated and not request.user.account %}
<div class="alert alert-warning" role="alert">
<i class="bi bi-exclamation-triangle-fill me-1"></i>
You must <a href="{% url 'anvil_consortium_manager:accounts:link' %}">link your AnVIL account</a> before you can access any data on AnVIL.
</div>
{% endif %}
{% endif %}

{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %} alert-dismissible fade show" role="alert">{{ message }}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>
{% endfor %}
{% endif %}

{% block extra_navbar %}
{% endblock %}



{% block content %}
Expand Down
3 changes: 3 additions & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ django-htmx
certifi>=2023.7.22
urllib3>=1.26.18
sqlparse>=0.4.4

# Dynamic settings
django-constance
5 changes: 5 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ django-anvil-consortium-manager @ git+https://github.com/UW-GAC/django-anvil-con
# via -r requirements/requirements.in
django-autocomplete-light==3.11.0
# via django-anvil-consortium-manager
django-constance==2.9.1
# via -r requirements/requirements.in
django-crispy-forms==2.1
# via
# -r requirements/requirements.in
Expand All @@ -88,6 +90,9 @@ django-maintenance-mode==0.21.1
# via -r requirements/requirements.in
django-model-utils==4.4.0
# via -r requirements/requirements.in
django-picklefield==3.1.0
# via -r requirements/requirements.in
# django-constnace
django-simple-history==3.5.0
# via
# -r requirements/requirements.in
Expand Down
Loading