Esempio n. 1
0
    def test_in_group(self, rget):

        def mocked_get(url, **options):
            if 'peterbe' in url:
                if 'group=losers' in url:
                    return Response(NO_USERS)
                if 'group=winners' in url:
                    return Response(VOUCHED_FOR_USERS)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        ok_(not mozillians.in_group('*****@*****.**', 'losers'))
        ok_(mozillians.in_group('*****@*****.**', 'winners'))
Esempio n. 2
0
    def test_in_group(self, rget):

        def mocked_get(url, **options):
            if 'peterbe' in url:
                if 'group=losers' in url:
                    return Response(NO_USERS)
                if 'group=winners' in url:
                    return Response(VOUCHED_FOR_USERS)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        ok_(not mozillians.in_group('*****@*****.**', 'losers'))
        ok_(mozillians.in_group('*****@*****.**', 'winners'))
Esempio n. 3
0
def can_view_event(event, user):
    """return True if the current user has right to view this event"""
    if event.privacy == Event.PRIVACY_PUBLIC:
        return True
    elif not user.is_active:
        return False

    # you're logged in
    if event.privacy == Event.PRIVACY_COMPANY:
        # but then it's not good enough to be contributor
        if is_contributor(user):
            return False
    else:
        if not is_contributor(user):
            # staff can always see it
            return True

        curated_groups = [
            x[0] for x in CuratedGroup.objects.filter(
                event=event).values_list('name')
        ]
        if curated_groups:
            return any(
                [mozillians.in_group(user.email, x) for x in curated_groups])

    return True
Esempio n. 4
0
def can_view_event(event, user):
    """return True if the current user has right to view this event"""
    if event.privacy == Event.PRIVACY_PUBLIC:
        return True
    elif not user.is_active:
        return False

    # you're logged in
    if event.privacy == Event.PRIVACY_COMPANY:
        # but then it's not good enough to be contributor
        if is_contributor(user):
            return False
    else:
        if not is_contributor(user):
            # staff can always see it
            return True

        curated_groups = [
            x[0] for x in
            CuratedGroup.objects.filter(event=event).values_list('name')
        ]
        if curated_groups:
            return any(
                [mozillians.in_group(user.email, x) for x in curated_groups]
            )

    return True
Esempio n. 5
0
def can_edit_event(event, user, default="manage:events"):
    if not user.has_perm("main.change_event_others") and user != event.creator:
        return redirect(default)
    if event.privacy == Event.PRIVACY_COMPANY and is_contributor(user):
        return redirect(default)
    elif CuratedGroup.objects.filter(event=event) and is_contributor(user):
        # Editing this event requires that you're also part of that curated
        # group.
        curated_group_names = [x[0] for x in CuratedGroup.objects.filter(event=event).values_list("name")]
        any_ = any([mozillians.in_group(user.email, x) for x in curated_group_names])
        if not any_:
            return redirect(default)
Esempio n. 6
0
def can_edit_event(event, user, default='manage:events'):
    if (not user.has_perm('main.change_event_others') and
            user != event.creator):
        return redirect(default)
    if event.privacy == Event.PRIVACY_COMPANY and is_contributor(user):
        return redirect(default)
    elif (
        CuratedGroup.objects.filter(event=event) and is_contributor(user)
    ):
        # Editing this event requires that you're also part of that curated
        # group.
        curated_group_names = [
            x[0] for x in
            CuratedGroup.objects.filter(event=event).values_list('name')
        ]
        any_ = any([
            mozillians.in_group(user.email, x) for x in curated_group_names
        ])
        if not any_:
            return redirect(default)