Skip to content

assign workinghours to participants on federated instances - #1503

Open
jeriox wants to merge 7 commits into
mainfrom
federated-workinghours
Open

assign workinghours to participants on federated instances#1503
jeriox wants to merge 7 commits into
mainfrom
federated-workinghours

Conversation

@jeriox

@jerioxjeriox commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

closes#1501

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

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

Copy link
Copy Markdown

Coverage Status

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

@jeriox
jerioxforce-pushed the federated-workinghours branch from a545fbd to 7276810CompareJuly 25, 2025 20:29
Comment threadephios/plugins/federation/models.py Outdated

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

Copy link
Copy Markdown
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?

@felixrindtfelixrindt mentioned this pull request Jul 31, 2025
@felixrindt

Copy link
Copy Markdown
Member

Here's what we discussed about queryset filtering:

defblub():
handlers= [...]
consequence_classes=AbstractConsequence.__subclasses__()
qs=AbstractConsequence.objects.filter(slug__in=map(operator.attrgetter("slug"), handlers)).distinct()
forhandlerinenabled_consequence_handlers:
forConcreteConsequenceinconsequence_classes:
qs=ConcreteConsequence.filter_queryset(handler, qs, user)
# ==> rather ditch annotations and OR Q-ObjectsreturnqsdeflocalConsequence_filter_queryset(handler, qs, user):
returnhandler.filter_local_queryset(qs, user) # filter for nonlocal or other handler or matches criteriadeffederatedConsequence_filter_queryset(handler, qs, user):
returnqs.filter(
Q("is not federated") |Q("matches criteria")
)

@jeriox
jerioxforce-pushed the federated-workinghours branch from ba01663 to 0a61e84CompareSeptember 4, 2025 19:43
@jeriox
jeriox marked this pull request as ready for review September 6, 2025 20:22

@felixrindtfelixrindt left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] featureNew 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

@jeriox@coveralls@felixrindt@jb-sap