Пример #1
0
def member_of_team_role(user, role):
    if user.is_anonymous:
        return False

    if is_fum(user) or is_board(user):
        return can_modify_role(user, role)

    team_ids = role.teams.values_list('pk', flat=True)
    return user.teams.filter(pk__in=team_ids).exists()
Пример #2
0
def member_of_team_appl(user, application):
    if user.is_anonymous:
        return False

    if is_fum(user) or is_board(user):
        return can_modify_application(user, application)

    team_ids = application.position.role.teams.values_list('pk', flat=True)
    return user.teams.filter(pk__in=team_ids).exists()
Пример #3
0
    def edit_role_types_of(user, pk=False):
        if user.is_anonymous:
            return [] if pk else Role.objects.none()

        role_type_filter = Role.editable_role_types(user)

        roles = []
        if is_fum(user) | is_board(user):
            # Fum and board can see from all teams
            roles = Role.objects.filter(role_type__in=role_type_filter)
        else:
            roles = Role.objects.filter(role_type__in=role_type_filter,
                                        teams__in=user.teams)
        if pk:
            return roles.values_list('pk', flat=True)
        else:
            return roles
Пример #4
0
    def edit_applicant_role_types(user):
        if user.is_anonymous:
            return []

        if is_admin(user):
            return [
                'admin', 'fum', 'board', 'presidium', 'group_leader', 'engaged'
            ]
        elif is_fum(user):
            return ['board', 'presidium']
        elif is_board(user):
            return ['presidium']
        elif is_presidium(user):
            return ['group_leader', 'engaged']
        elif is_group_leader(user):
            return ['engaged']

        return []