Exemplo n.º 1
0
async def me(
        session: dict = Depends(get_session),
        dao: Dao = Depends(get_dao),
        auth: authorization.Rules = Depends(get_rules)):
    """Returns your quetz profile"""

    # Check if token is still valid
    await check_token_revocation(session)

    user_id = auth.assert_user()

    profile = dao.get_profile(user_id)
    return profile
Exemplo n.º 2
0
def static(
        resource: str,
        session: dict = Depends(get_session),
        dao: Dao = Depends(get_dao),
        auth: authorization.Rules = Depends(get_rules),
):
    user_id = auth.get_user()

    if "." not in resource:
        if index_template is None or user_id is None:
            return FileResponse(path=os.path.join(frontend_dir, "index.html"))
        else:
            profile = dao.get_profile(user_id)
            if profile is not None:
                index_rendered = get_rendered_index(config_data, profile,
                                                    index_template)
                return HTMLResponse(content=index_rendered, status_code=200)
            else:
                return FileResponse(
                    path=os.path.join(frontend_dir, "index.html"))
    else:
        return FileResponse(path=os.path.join(frontend_dir, resource))
Exemplo n.º 3
0
def index(
        resource: str,
        session: dict = Depends(get_session),
        dao: Dao = Depends(get_dao),
        auth: authorization.Rules = Depends(get_rules),
        frontend_dir: Path = Depends(get_frontend_dir),
        extensions_dir: Path = Depends(get_extensions_dir),
        cache_control: Optional[str] = Header(None),
):
    global config_data
    user_id = auth.get_user()
    profile = dao.get_profile(user_id)

    if "." in resource:
        file_name = (resource if
                     ("icons" in resource or "logos" in resource
                      or "page-data" in resource) else resource.split("/")[-1])

        path = frontend_dir / "static" / file_name
        if path.exists():
            return FileResponse(path=path)
        else:
            raise HTTPException(status_code=404)
    else:
        extensions, disabled_extensions = get_federated_extensions(
            [extensions_dir])
        federated_extensions = load_federated_extensions(extensions)
        config_data["federated_extensions"] = federated_extensions
        config_data["disabledExtensions"] = disabled_extensions

        logger.info(cache_control)
        if is_dev_mode():
            get_index_template.cache_clear()

        index_template = get_index_template(frontend_dir)
        index_rendered = get_rendered_index(config_data, profile,
                                            index_template)
        return HTMLResponse(content=index_rendered, status_code=200)