<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def restricted_activities_available_to_user(cls, user):
 """Find the restricted activities available to the given user."""

        if not user:
            return []

        activities = set(user.restricted_activity_set.values_list("id", flat=True))

        if user and user.grade and user.grade.number and user.grade.name:
            grade = user.grade
        else:
            grade = None

        if grade is not None and 9 <= grade.number <= 12:
            activities |= set(EighthActivity.objects.filter(**{'{}_allowed'.format(grade.name_plural): True}).values_list("id", flat=True))

        for group in user.groups.all():
            activities |= set(group.restricted_activity_set.values_list("id", flat=True))

        return list(activities)