Skip to content

Commit

Permalink
fix: sms content item snippet program filters and page permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
SharleneNdinda committed Oct 5, 2023
1 parent 2faf19e commit 6874a71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
WAGTAIL_CONTENT_LANGUAGES = [
("en", _("English")),
("sw", _("Swahili")),
("fr", _("French")),
]
WAGTAILEMBEDS_RESPONSIVE_HTML = True
WAGTAILADMIN_RECENT_EDITS_LIMIT = 5
Expand Down
24 changes: 24 additions & 0 deletions mycarehub/content/migrations/0017_alter_contentitem_facilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.20 on 2023-10-05 12:28

import modelcluster.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("common", "0007_alter_auditlog_organisation_and_more"),
("content", "0016_auto_20231003_1602"),
]

operations = [
migrations.AlterField(
model_name="contentitem",
name="facilities",
field=modelcluster.fields.ParentalManyToManyField(
blank=True,
help_text="Determines which facilities content is meant for.",
null=True,
to="common.Facility",
),
),
]
5 changes: 4 additions & 1 deletion mycarehub/content/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ class ItemTypes(models.TextChoices):
)

facilities = ParentalManyToManyField(
Facility, help_text="Determines which facilities content is meant for."
Facility,
help_text="Determines which facilities content is meant for.",
blank=True,
null=True,
)

date = models.DateField(
Expand Down
3 changes: 3 additions & 0 deletions mycarehub/content/models/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from wagtail.search import index

from mycarehub.common.models import Organisation, Program
from mycarehub.content.models.snippets import CustomSnippetForm

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +57,7 @@ class SMSContentItemCategory(ClusterableModel):
blank=True,
related_name="%(app_label)s_%(class)s_related",
)
base_form_class = CustomSnippetForm

def __str__(self):
return f"{self.name}"
Expand Down Expand Up @@ -96,6 +98,7 @@ class SMSContentItemTag(ClusterableModel):
blank=True,
related_name="%(app_label)s_%(class)s_related",
)
base_form_class = CustomSnippetForm

def __str__(self):
return f"{self.name}"
Expand Down
15 changes: 9 additions & 6 deletions mycarehub/content/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def create_program_content_index_page(sender, instance, created, **kwargs):
if settings.DEFAULT_PROGRAM_ID == str(instance.id) and created:
return

if created and ContentItemIndexPage.objects.filter(program=instance).exists():
return

try:
homepage = HomePage.objects.get(title="Mycarehub Home Page")
except ObjectDoesNotExist:
Expand Down Expand Up @@ -77,7 +80,7 @@ def create_program_content_index_page(sender, instance, created, **kwargs):
@receiver(post_save, sender=ContentItemIndexPage)
def create_program_content_editor_permissions(sender, instance, created, **kwargs):
if created:
group = Group.objects.create(name=f"{instance.program.name} Editor")
group, _ = Group.objects.get_or_create(name=f"{instance.program.name} Editor")

can_access_wagtail_admin = Permission.objects.get(
content_type=ContentType.objects.get(app_label="wagtailadmin", model="admin"),
Expand Down Expand Up @@ -116,7 +119,7 @@ def create_program_content_editor_permissions(sender, instance, created, **kwarg

allowed_sms_content_item_tag_permissions = [
"add_smscontentitemtag",
"add_smscontentitemtag",
"change_smscontentitemtag",
]
for permission in allowed_sms_content_item_tag_permissions:
permission_object = Permission.objects.get(
Expand All @@ -141,14 +144,14 @@ def create_program_content_editor_permissions(sender, instance, created, **kwarg

allowed_page_permissions = ["add", "edit", "publish"]
for permission in allowed_page_permissions:
GroupPagePermission.objects.create(
GroupPagePermission.objects.get_or_create(
group=group, page=instance, permission_type=permission
)

root_collection = Collection.get_first_root_node()
allowed_image_permissions = ["add_image", "choose_image", "change_image", "delete_image"]
for permission in allowed_image_permissions:
GroupCollectionPermission.objects.create(
GroupCollectionPermission.objects.get_or_create(
group=group,
collection=root_collection,
permission=Permission.objects.get(
Expand All @@ -164,7 +167,7 @@ def create_program_content_editor_permissions(sender, instance, created, **kwarg
]

for permission in allowed_document_permissions:
GroupCollectionPermission.objects.create(
GroupCollectionPermission.objects.get_or_create(
group=group,
collection=root_collection,
permission=Permission.objects.get(
Expand All @@ -175,7 +178,7 @@ def create_program_content_editor_permissions(sender, instance, created, **kwarg
allowed_media_permissions = ["add_media", "delete_media", "change_media"]

for permission in allowed_media_permissions:
GroupCollectionPermission.objects.create(
GroupCollectionPermission.objects.get_or_create(
group=group,
collection=root_collection,
permission=Permission.objects.get(
Expand Down

0 comments on commit 6874a71

Please sign in to comment.