Exemplo n.º 1
0
    async def api_authenticated_organization_stats(self, client_ctx, msg):
        msg = organization_stats_serializer.req_load(msg)

        if client_ctx.profile != UserProfile.ADMIN:
            return {
                "status": "not_allowed",
                "reason":
                f"User `{client_ctx.device_id.user_id}` is not admin",
            }
        # Get organization of the user
        organization_id = client_ctx.organization_id
        try:
            stats = await self.stats(organization_id)

        except OrganizationNotFoundError:
            return {"status": "not_found"}

        return organization_stats_serializer.rep_dump({
            "status":
            "ok",
            "users":
            stats.users,
            "data_size":
            stats.data_size,
            "metadata_size":
            stats.metadata_size,
        })
Exemplo n.º 2
0
    async def api_organization_stats(self, client_ctx, msg):
        msg = organization_stats_serializer.req_load(msg)

        try:
            stats = await self.stats(msg["organization_id"])

        except OrganizationNotFoundError:
            return {"status": "not_found"}

        return organization_stats_serializer.rep_dump({
            "status":
            "ok",
            "users":
            stats.users,
            "data_size":
            stats.data_size,
            "metadata_size":
            stats.metadata_size,
        })