diff --git a/epapi/v1/endpoints/groups.py b/epapi/v1/endpoints/groups.py new file mode 100644 index 00000000..a9302e84 --- /dev/null +++ b/epapi/v1/endpoints/groups.py @@ -0,0 +1,23 @@ +from django.conf import settings as s +from ninja import Router +from ninja_extra.pagination import paginate + +from epdb.logic import GroupManager + +from ..pagination import EnhancedPageNumberPagination +from ..schemas import GroupOutSchema + +router = Router() + + +@router.get("/groups/", response=EnhancedPageNumberPagination.Output[GroupOutSchema]) +@paginate( + EnhancedPageNumberPagination, + page_size=s.API_PAGINATION_DEFAULT_PAGE_SIZE, +) +def list_all_groups(request): + """ + List all groups the user has access to. + """ + user = request.user + return GroupManager.get_groups(user) diff --git a/epapi/v1/endpoints/settings.py b/epapi/v1/endpoints/settings.py index dc6ce330..001ea8d2 100644 --- a/epapi/v1/endpoints/settings.py +++ b/epapi/v1/endpoints/settings.py @@ -15,9 +15,9 @@ router = Router() EnhancedPageNumberPagination, page_size=s.API_PAGINATION_DEFAULT_PAGE_SIZE, ) -def list_all_pathways(request): +def list_all_settings(request): """ - List all pathways from reviewed packages. + List all settings the user has access to. """ user = request.user return SettingManager.get_all_settings(user) diff --git a/epapi/v1/router.py b/epapi/v1/router.py index 32cdd5c4..472c6f3c 100644 --- a/epapi/v1/router.py +++ b/epapi/v1/router.py @@ -1,6 +1,7 @@ from ninja import Router from ninja.security import SessionAuth +from envipath import settings as s from .auth import BearerTokenAuth from .endpoints import ( packages, @@ -13,8 +14,8 @@ from .endpoints import ( structure, additional_information, settings, + groups, ) -from envipath import settings as s # Main router with authentication router = Router( @@ -35,6 +36,7 @@ router.add_router("", models.router) router.add_router("", structure.router) router.add_router("", additional_information.router) router.add_router("", settings.router) +router.add_router("", groups.router) if s.IUCLID_EXPORT_ENABLED: from epiuclid.api import router as iuclid_router diff --git a/epapi/v1/schemas.py b/epapi/v1/schemas.py index 85632aae..7d1d9036 100644 --- a/epapi/v1/schemas.py +++ b/epapi/v1/schemas.py @@ -126,3 +126,10 @@ class SettingOutSchema(Schema): url: str = "" name: str description: str + + +class GroupOutSchema(Schema): + uuid: UUID + url: str = "" + name: str + description: str diff --git a/epdb/views.py b/epdb/views.py index 88b59296..0801540e 100644 --- a/epdb/views.py +++ b/epdb/views.py @@ -2846,9 +2846,15 @@ def groups(request): {"Group": s.SERVER_URL + "/group"}, ] - context["objects"] = Group.objects.all() + # Context for paginated template + context["entity_type"] = "group" + context["api_endpoint"] = f"{s.SERVER_PATH}/api/v1/groups/" + context["per_page"] = s.API_PAGINATION_DEFAULT_PAGE_SIZE + context["list_title"] = "groups" + context["list_mode"] = "combined" + + return render(request, "collections/groups_paginated.html", context) - return render(request, "collections/objects_list.html", context) elif request.method == "POST": group_name = request.POST.get("group-name") group_description = request.POST.get("group-description", s.DEFAULT_VALUES["description"]) diff --git a/templates/actions/collections/group.html b/templates/actions/collections/group.html index 40f7e0ef..e69de29b 100644 --- a/templates/actions/collections/group.html +++ b/templates/actions/collections/group.html @@ -1,8 +0,0 @@ -
  • - - New Group -
  • diff --git a/templates/collections/groups_paginated.html b/templates/collections/groups_paginated.html new file mode 100644 index 00000000..70cfc3db --- /dev/null +++ b/templates/collections/groups_paginated.html @@ -0,0 +1,21 @@ +{% extends "collections/paginated_base.html" %} + +{% block page_title %}Groups{% endblock %} + +{% block action_button %} + +{% endblock action_button %} + +{% block action_modals %} + {% include "modals/collections/new_group_modal.html" %} +{% endblock action_modals %} + +{% block description %} +

    Users can team up in groups to share packages.

    +{% endblock description %}