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

Fix: remove views from projects if catalog is changed #1200

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion rdmo/projects/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db.models.signals import m2m_changed
from django.db.models.signals import m2m_changed, post_save
from django.dispatch import receiver

from rdmo.projects.models import Membership, Project
Expand Down Expand Up @@ -58,3 +58,23 @@ def m2m_changed_view_groups_signal(sender, instance, **kwargs):
projects = Project.objects.filter(memberships__in=list(memberships), catalog__in=catalogs, views=instance)
for project in projects:
project.views.remove(instance)


@receiver(post_save, sender=Project)
def update_views_on_catalog_change(sender, instance, **kwargs):
# remove views that are no longer available
view_candidates = instance.views.exclude(catalogs__in=[instance.catalog]) \
.exclude(catalogs=None)

for view in view_candidates:
instance.views.remove(view)

# add views that are now available
view_candidates = View.objects.exclude(id__in=[v.id for v in instance.views.all()]) \
.filter_current_site() \
.filter_catalog(instance.catalog)
# .filter_group(self.request.user) \
# .filter_availability(self.request.user).exists()

for view in view_candidates:
instance.views.add(view)