# Path: virtool/users/utils.py
# def generate_base_permissions() -> dict:
#     """
#     Return a `dict` keyed with all Virtool permissions where all the values are `False`.
# 
#     :return: all-false permissions
#     """
#     return {p: False for p in PERMISSIONS}


import pymongo.errors
import virtool.groups.db
import virtool.http.routes
import virtool.validators
from aiohttp.web import Request, Response
from aiohttp.web_exceptions import HTTPBadRequest, HTTPNoContent
from virtool.api.response import NotFound, json_response
from virtool.http.schema import schema
from virtool.users.utils import generate_base_permissions
from virtool.utils import base_processor
@routes.get("/groups")
async def find(req: Request) -> Response:
    """
    Get a list of all existing group documents.

    """
    cursor = req.app["db"].groups.find()
    return json_response([base_processor(d) async for d in cursor])


@routes.post("/groups", admin=True)
@schema(
    {
        "group_id": {
            "type": "string",
            "coerce": virtool.validators.strip,
            "empty": False,
            "required": True,
        }
    }
)
async def create(req: Request) -> Response:
    """
    Adds a new user group.

    """
    db, data = req.app["db"], req["data"]

    document = {
        "_id": data["group_id"].lower(),

# Path: virtool/users/utils.py
# def generate_base_permissions() -> dict:
#     """
#     Return a `dict` keyed with all Virtool permissions where all the values are `False`.
# 
#     :return: all-false permissions
#     """
#     return {p: False for p in PERMISSIONS}


# Path: virtool/groups/api.py
import pymongo.errors
import virtool.groups.db
import virtool.http.routes
import virtool.validators
from aiohttp.web import Request, Response
from aiohttp.web_exceptions import HTTPBadRequest, HTTPNoContent
from virtool.api.response import NotFound, json_response
from virtool.http.schema import schema
from virtool.users.utils import generate_base_permissions
from virtool.utils import base_processor

@routes.get("/groups")
async def find(req: Request) -> Response:
    """
    Get a list of all existing group documents.

    """
    cursor = req.app["db"].groups.find()
    return json_response([base_processor(d) async for d in cursor])


@routes.post("/groups", admin=True)
@schema(
    {
        "group_id": {
            "type": "string",
            "coerce": virtool.validators.strip,
            "empty": False,
            "required": True,
        }
    }
)
async def create(req: Request) -> Response:
    """
    Adds a new user group.

    """
    db, data = req.app["db"], req["data"]

    document = {
        "_id": data["group_id"].lower(),

        "permissions": generate_base_permissions(),