Пример #1
0
def is_group_pending(user, group):
    """Template filter to check if the given user is a member of the given
    group.

    .. seealso:: func:`cosinnus.utils.permissions.check_ug_membership`
    """
    return check_ug_pending(user, group)
Пример #2
0
    def __init__(self, haystack_result, obj, user, *args, **kwargs):
        kwargs.update({
            'is_superuser':
            check_user_superuser(user),
            'is_member':
            check_ug_membership(user, obj),
            'is_pending':
            check_ug_pending(user, obj),
            'is_invited':
            check_ug_invited_pending(user, obj),
            'creator_name':
            obj.creator and obj.creator.get_full_name(),
            'creator_slug':
            obj.creator and obj.creator.username,
            'title':
            obj.name,
            'organization_type':
            obj.get_type(),
            'website_url':
            obj.website,
            'email':
            obj.email,
            'phone_number':
            obj.phone_number.as_international if obj.phone_number else None,
            'social_media': [{
                'url': sm.url,
                'icon': sm.icon
            } for sm in obj.social_media.all()],
            'edit_url':
            obj.get_edit_url(),
            'accept_url':
            reverse('cosinnus:organization-user-accept',
                    kwargs={'organization': obj.slug}),
        })

        # collect administrator users. these are *not* filtered by visibility, as project admins are always visible!
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['people'])
        sqs = sqs.filter_and(admin_organizations=obj.id)
        #sqs = filter_searchqueryset_for_read_access(sqs, user)
        # private users are not visible to anonymous users, BUT they are visible to logged in users!
        # because if a user chose to make his group visible, he has to take authorship responsibilities
        if not user.is_authenticated:
            sqs = filter_searchqueryset_for_read_access(sqs, user)
        kwargs.update(
            {'admins': [HaystackUserMapCard(result) for result in sqs]})

        # Groups
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['projects'],
                                      SEARCH_MODEL_NAMES_REVERSE['groups'])
        sqs = sqs.filter_and(id__in=haystack_result.groups)
        sqs = filter_searchqueryset_for_read_access(sqs, user)
        sqs = sqs.order_by('title')
        kwargs.update(
            {'groups': [HaystackGroupMapCard(result) for result in sqs]})

        super(DetailedOrganizationMapResult,
              self).__init__(haystack_result, obj, user, *args, **kwargs)
Пример #3
0
    def __init__(self, haystack_result, obj, user, *args, **kwargs):
        group_admins = list(obj.actual_admins)
        message_url = None
        if not settings.COSINNUS_IS_INTEGRATED_PORTAL:
            message_url = message_group_admins_url(obj, group_admins)

        kwargs.update({
            'is_member':
            check_ug_membership(user, obj),
            'is_pending':
            check_ug_pending(user, obj),
            'is_invited':
            check_ug_invited_pending(user, obj),
            'action_url_1':
            _prepend_url(user, obj.portal) +
            group_aware_reverse('cosinnus:group-microsite',
                                kwargs={'group': obj},
                                skip_domain=True) + '?join=1',
            'action_url_2': (_prepend_url(user, obj.portal) +
                             message_url) if message_url else None,
            'youtube_url':
            obj.video,
            'twitter_username':
            obj.twitter_username,
            'flickr_url':
            obj.flickr_url,
            'website_url':
            obj.website,
            'contact':
            linebreaksbr(escape(obj.contact_info)),
        })
        """ TODO: check all read permissions on related objects! """

        # collect upcoming and visible project/group events
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['events'])
        sqs = sqs.filter_and(group=obj.id)
        sqs = filter_searchqueryset_for_read_access(sqs, user)
        sqs = filter_event_searchqueryset_by_upcoming(sqs)
        sqs = sqs.order_by('from_date')
        kwargs.update(
            {'events': [HaystackEventMapCard(result) for result in sqs]})

        # collect administrator users. these are *not* filtered by visibility, as project admins are always visible!
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['people'])
        sqs = sqs.filter_and(admin_groups=obj.id)
        #sqs = filter_searchqueryset_for_read_access(sqs, user)
        sqs = sqs.order_by('title')
        kwargs.update(
            {'admins': [HaystackUserMapCard(result) for result in sqs]})

        return super(DetailedBaseGroupMapResult,
                     self).__init__(haystack_result, obj, user, *args,
                                    **kwargs)
Пример #4
0
    def __init__(self, haystack_result, obj, user, *args, **kwargs):
        message_url = None
        if not settings.COSINNUS_IS_INTEGRATED_PORTAL and not 'cosinnus_message' in settings.COSINNUS_DISABLED_COSINNUS_APPS:
            if settings.COSINNUS_ROCKET_ENABLED:
                message_url = reverse('cosinnus:message-write-group',
                                      kwargs={'slug': obj.slug})
            else:
                group_admins = list(obj.actual_admins)
                message_url = message_group_admins_url(obj, group_admins)

        kwargs.update({
            'is_member':
            check_ug_membership(user, obj),
            'is_pending':
            check_ug_pending(user, obj),
            'is_invited':
            check_ug_invited_pending(user, obj),
            'action_url_1':
            _prepend_url(user, obj.portal) +
            group_aware_reverse('cosinnus:group-microsite',
                                kwargs={'group': obj},
                                skip_domain=True) + '?join=1',
            'action_url_2': (_prepend_url(user, obj.portal) +
                             message_url) if message_url else None,
            'youtube_url':
            obj.video,
            'twitter_username':
            obj.twitter_username,
            'flickr_url':
            obj.flickr_url,
            'website_url':
            obj.website,
            'contact':
            linebreaksbr(escape(obj.contact_info)),
            'followed':
            obj.is_user_following(user),
            'starred':
            obj.is_user_starring(user)
        })
        """ TODO: check all read permissions on related objects! """

        # collect upcoming and visible project/group events
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['events'])
        sqs = sqs.filter_and(group=obj.id)
        sqs = filter_searchqueryset_for_read_access(sqs, user)
        sqs = filter_event_searchqueryset_by_upcoming(sqs)
        sqs = sqs.order_by('from_date')
        kwargs.update(
            {'events': [HaystackEventMapCard(result) for result in sqs]})

        # collect administrator users. these are *not* filtered by visibility, as project admins are always visible!
        sqs = SearchQuerySet().models(SEARCH_MODEL_NAMES_REVERSE['people'])
        sqs = sqs.filter_and(admin_groups=obj.id)
        #sqs = filter_searchqueryset_for_read_access(sqs, user)
        sqs = sqs.order_by('title')

        # private users are not visible to anonymous users, BUT they are visible to logged in users!
        # because if a user chose to make his group visible, he has to take authorship responsibilities
        if not user.is_authenticated:
            sqs = filter_searchqueryset_for_read_access(sqs, user)

        kwargs.update(
            {'admins': [HaystackUserMapCard(result) for result in sqs]})

        if settings.COSINNUS_ORGANIZATIONS_ENABLED:
            sqs = SearchQuerySet().models(
                SEARCH_MODEL_NAMES_REVERSE['organizations'])
            sqs = sqs.filter_and(groups=obj.id)
            sqs = filter_searchqueryset_for_read_access(sqs, user)
            sqs = sqs.order_by('title')

            kwargs.update({
                'organizations':
                [HaystackOrganizationMapCard(result) for result in sqs]
            })

        return super(DetailedBaseGroupMapResult,
                     self).__init__(haystack_result, obj, user, *args,
                                    **kwargs)