Beispiel #1
0
def home():
    user_id = get_current_user_id()
    if user_id:  # Logged in: return either landing page or user home page
        all_institutions = (
            Institution.objects.filter(
                is_deleted=False,
                nodes__is_public=True,
                nodes__is_deleted=False,
                nodes__type='osf.node'
            )
            .annotate(Count('nodes'))
            .filter(nodes__count__gte=INSTITUTION_DISPLAY_NODE_THRESHOLD)
            .order_by('name').only('_id', 'name', 'logo_name')
        )
        dashboard_institutions = [
            {'id': inst._id, 'name': inst.name, 'logo_path': inst.logo_path_rounded_corners}
            for inst in all_institutions
        ]

        return {
            'home': True,
            'dashboard_institutions': dashboard_institutions,
        }
    else:  # Logged out: return landing page
        return {
            'home': True,
        }
Beispiel #2
0
def index():
    try:  # Check if we're on an institution landing page
        #TODO : make this way more robust
        institution = Institution.objects.get(domains__contains=[request.host.lower()], is_deleted=False)
        inst_dict = serialize_institution(institution)
        inst_dict.update({
            'home': False,
            'institution': True,
            'redirect_url': '/institutions/{}/'.format(institution._id),
        })

        return inst_dict
    except Institution.DoesNotExist:
        pass

    user_id = get_current_user_id()
    if user_id:  # Logged in: return either landing page or user home page
        all_institutions = Institution.objects.filter(is_deleted=False).order_by('name').only('_id', 'name', 'logo_name')
        dashboard_institutions = [
            {'id': inst._id, 'name': inst.name, 'logo_path': inst.logo_path_rounded_corners}
            for inst in all_institutions
        ]

        return {
            'home': True,
            'dashboard_institutions': dashboard_institutions,
        }
    else:  # Logged out: return landing page
        return {
            'home': True,
        }
Beispiel #3
0
def index():
    if request.host_url != settings.DOMAIN:
        try:  # Check if we're on an institution landing page
            #TODO : make this way more robust
            institution = Institution.objects.get(
                domains__contains=[request.host.lower()], is_deleted=False)
            inst_dict = serialize_institution(institution)
            inst_dict.update({
                'home':
                False,
                'institution':
                True,
                'redirect_url':
                '{}institutions/{}/'.format(DOMAIN, institution._id),
            })

            return inst_dict
        except Institution.DoesNotExist:
            pass

    user_id = get_current_user_id()
    if user_id:  # Logged in: return either landing page or user home page
        all_institutions = (Institution.objects.filter(
            is_deleted=False,
            nodes__is_public=True,
            nodes__is_deleted=False,
            nodes__type='osf.node').annotate(Count('nodes')).filter(
                nodes__count__gte=INSTITUTION_DISPLAY_NODE_THRESHOLD).order_by(
                    'name').only('_id', 'name', 'logo_name'))
        dashboard_institutions = [{
            'id': inst._id,
            'name': inst.name,
            'logo_path': inst.logo_path_rounded_corners
        } for inst in all_institutions]

        # generation key check
        key_exists_check = userkey_generation_check(user_id)

        if not key_exists_check:
            userkey_generation(user_id)

        return {
            'home': True,
            'dashboard_institutions': dashboard_institutions,
        }
    else:  # Logged out: return landing page
        return {
            'home': True,
        }
def after_request(resp):
    """Set a cookie specified by api_settings.CSRF_COOKI_NAME so that
    session-authenticated requests from the legacy frontend can pass
    CSRF verification.
    """
    if get_current_user_id():
        csrf_token = g.csrf_token
        # Set the CSRF cookie even if it's already set, so we renew
        # the expiry timer.
        resp.set_cookie(
            api_settings.CSRF_COOKIE_NAME,
            csrf_token,
            max_age=api_settings.CSRF_COOKIE_AGE,
            domain=api_settings.CSRF_COOKIE_DOMAIN,
            path=api_settings.CSRF_COOKIE_PATH,
            httponly=api_settings.CSRF_COOKIE_HTTPONLY,
        )

    return resp
Beispiel #5
0
def after_request(resp):
    """Set a cookie specified by api_settings.CSRF_COOKI_NAME so that
    session-authenticated requests from the legacy frontend can pass
    CSRF verification.
    """
    if get_current_user_id():
        csrf_token = g.csrf_token
        # Set the CSRF cookie even if it's already set, so we renew
        # the expiry timer.
        resp.set_cookie(
            api_settings.CSRF_COOKIE_NAME,
            csrf_token,
            max_age=api_settings.CSRF_COOKIE_AGE,
            domain=api_settings.CSRF_COOKIE_DOMAIN,
            path=api_settings.CSRF_COOKIE_PATH,
            httponly=api_settings.CSRF_COOKIE_HTTPONLY,
        )

    return resp
Beispiel #6
0
def index():
    try:  # Check if we're on an institution landing page
        #TODO : make this way more robust
        institution = Institution.objects.get(domains__contains=[request.host.lower()], is_deleted=False)
        inst_dict = serialize_institution(institution)
        inst_dict.update({
            'home': False,
            'institution': True,
            'redirect_url': '/institutions/{}/'.format(institution._id),
        })

        return inst_dict
    except Institution.DoesNotExist:
        pass

    user_id = get_current_user_id()
    if user_id:  # Logged in: return either landing page or user home page
        all_institutions = (
            Institution.objects.filter(
                is_deleted=False,
                nodes__is_public=True,
                nodes__is_deleted=False,
                nodes__type='osf.node'
            )
            .annotate(Count('nodes'))
            .filter(nodes__count__gte=INSTITUTION_DISPLAY_NODE_THRESHOLD)
            .order_by('name').only('_id', 'name', 'logo_name')
        )
        dashboard_institutions = [
            {'id': inst._id, 'name': inst.name, 'logo_path': inst.logo_path_rounded_corners}
            for inst in all_institutions
        ]

        return {
            'home': True,
            'dashboard_institutions': dashboard_institutions,
        }
    else:  # Logged out: return landing page
        return {
            'home': True,
        }
Beispiel #7
0
def home():
    user_id = get_current_user_id()
    if user_id:  # Logged in: return either landing page or user home page
        all_institutions = (Institution.objects.filter(
            is_deleted=False,
            nodes__is_public=True,
            nodes__is_deleted=False,
            nodes__type='osf.node').annotate(Count('nodes')).filter(
                nodes__count__gte=INSTITUTION_DISPLAY_NODE_THRESHOLD).order_by(
                    'name').only('_id', 'name', 'logo_name'))
        dashboard_institutions = [{
            'id': inst._id,
            'name': inst.name,
            'logo_path': inst.logo_path_rounded_corners
        } for inst in all_institutions]

        return {
            'home': True,
            'dashboard_institutions': dashboard_institutions,
        }
    else:  # Logged out: return landing page
        return {
            'home': True,
        }