def METHOD_NAME(sender, instance, created, **kwargs):
    from taiga.projects.userstories import services
    UserStory = apps.get_model("userstories", "UserStory")
    for user_story in UserStory.objects.filter(tasks__status=instance).distinct():
        if services.calculate_userstory_is_closed(user_story):
            services.close_userstory(user_story)
        else:
            services.open_userstory(user_story)