oncall-engine/engine/apps/api/views/user_group.py
Michael Derynck 357857faca
Add endpoint to get a single user group (#4395)
# What this PR does
Add endpoint to return slack user group from public primary key

## Which issue(s) this PR closes

<!--
*Note*: if you have more than one GitHub issue that this PR closes, be
sure to preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-05-24 20:26:28 +00:00

32 lines
1.2 KiB
Python

from rest_framework import mixins, viewsets
from rest_framework.filters import SearchFilter
from rest_framework.permissions import IsAuthenticated
from apps.api.permissions import RBACPermission
from apps.api.serializers.user_group import UserGroupSerializer
from apps.auth_token.auth import PluginAuthentication
from apps.slack.models import SlackUserGroup
from common.api_helpers.mixins import PublicPrimaryKeyMixin
class UserGroupViewSet(
PublicPrimaryKeyMixin[SlackUserGroup], mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet
):
authentication_classes = (PluginAuthentication,)
permission_classes = (IsAuthenticated, RBACPermission)
serializer_class = UserGroupSerializer
rbac_permissions = {
"list": [RBACPermission.Permissions.CHATOPS_READ],
"retrieve": [RBACPermission.Permissions.CHATOPS_READ],
}
filter_backends = (SearchFilter,)
search_fields = ("name", "handle")
def get_queryset(self):
slack_team_identity = self.request.auth.organization.slack_team_identity
if slack_team_identity is None:
return SlackUserGroup.objects.none()
return slack_team_identity.usergroups.all()