Skip to content

Conversation

@jeriox
Copy link
Contributor

@jeriox jeriox commented Mar 4, 2025

closes #1501

  • pull consequences from FederatedHost and create them locally
  • migrate consequeces?

@jeriox jeriox added the [C] feature New feature or request label Mar 4, 2025
@coveralls
Copy link

Coverage Status

coverage: 83.991% (+0.02%) from 83.971%
when pulling a545fbd on federated-workinghours
into 9b22c56 on main.

@jeriox jeriox force-pushed the federated-workinghours branch from a545fbd to 7276810 Compare July 25, 2025 20:29

class Consequence(Model):
@dont_log # as we log the specific models
class AbstractConsequence(PolymorphicModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the code is not robust against consequence handlers being uninstalled (try removing the youth warden plugin). I think it should be, similar to missing structures and signup flow, it shouldn't crash the application. Maybe setting a custom _default_manager would be a simple solution?

@felixrindt
Copy link
Member

Here's what we discussed about queryset filtering:

def blub():
    handlers = [...]
    consequence_classes = AbstractConsequence.__subclasses__()

    qs = AbstractConsequence.objects.filter(slug__in=map(operator.attrgetter("slug"), handlers)).distinct()
    for handler in enabled_consequence_handlers:
        for ConcreteConsequence in consequence_classes:
            qs = ConcreteConsequence.filter_queryset(handler, qs, user)
	# ==> rather ditch annotations and OR Q-Objects
    return qs

def localConsequence_filter_queryset(handler, qs, user):
    return handler.filter_local_queryset(qs, user)  # filter for nonlocal or other handler or matches criteria

def federatedConsequence_filter_queryset(handler, qs, user):
    return qs.filter(
        Q("is not federated") | Q("matches criteria")
    )

@jeriox jeriox force-pushed the federated-workinghours branch from ba01663 to 0a61e84 Compare September 4, 2025 19:43
@jeriox jeriox marked this pull request as ready for review September 6, 2025 20:22
Copy link
Member

@felixrindt felixrindt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent you a patch on Signal so you can look through my hacks during trying this out.

Comment on lines +235 to +238
if not self.instance and value != AbstractConsequence.States.NEEDS_CONFIRMATION:
raise serializers.ValidationError(
_("Consequences must be created in needs_confirmation state")
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this belongs in the concrete federated code, because in an normal API we would want to serialize consequences in any state?!

queryset = WorkingHours.objects.all()


class ConsequenceViewSet(viewsets.ModelViewSet):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is specifically for federated consequences, the name should reflect that. Can it be moved to the plugin?

Comment on lines +217 to 227
def filter_editable_by_user(cls, user: UserProfile):
return Q(slug=cls.slug) & Q(
# Qualifications can be granted by people who...
| Q( # are responsible for the event the consequence originated from, if applicable
event_id__in=get_objects_for_user(user, perms="change_event", klass=Event),
Q( # are responsible for the event the consequence originated from, if applicable
data__event_id__in=get_objects_for_user(user, perms="change_event", klass=Event),
)
| Q( # can edit the affected user anyway
user__in=get_objects_for_user(
localconsequence__user__in=get_objects_for_user(
user, perms="change_userprofile", klass=get_user_model()
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version doesn't work for me. Postgres complains about having to implicitly typecast somewhere. I think it might be the json values in list checks.

phone = models.CharField(_("phone number"), max_length=254, blank=True)
qualifications = models.ManyToManyField(Qualification)
federated_instance = models.ForeignKey(FederatedGuest, on_delete=models.CASCADE)
federated_instance_identifier = models.CharField(null=True, blank=True, max_length=255)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is filled anywhere?

if event_title:
s = _("{user} acquires '{qualification}' after participating in {event}.").format(
user=user, qualification=qualification_title, event=event_title
s = _("acquires '{qualification}' after participating in {event}.").format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atm this is just "deleted event" when coming from a federated instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assign workinghours for events on federated instances

4 participants