2022-06-03 08:09:47 -06:00
|
|
|
from rest_framework import mixins
|
|
|
|
|
from rest_framework.filters import SearchFilter
|
|
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
|
from rest_framework.viewsets import GenericViewSet
|
|
|
|
|
|
2023-10-19 14:39:08 -03:00
|
|
|
from apps.api.permissions import RBACPermission
|
2022-06-03 08:09:47 -06:00
|
|
|
from apps.api.serializers.slack_channel import SlackChannelSerializer
|
|
|
|
|
from apps.auth_token.auth import PluginAuthentication
|
|
|
|
|
from apps.slack.models import SlackChannel
|
|
|
|
|
from common.api_helpers.mixins import PublicPrimaryKeyMixin
|
|
|
|
|
from common.api_helpers.paginators import HundredPageSizePaginator
|
|
|
|
|
|
|
|
|
|
|
2024-01-30 13:07:19 -05:00
|
|
|
class SlackChannelView(
|
|
|
|
|
PublicPrimaryKeyMixin[SlackChannel], mixins.ListModelMixin, mixins.RetrieveModelMixin, GenericViewSet
|
|
|
|
|
):
|
2022-06-03 08:09:47 -06:00
|
|
|
authentication_classes = (PluginAuthentication,)
|
2023-10-19 14:39:08 -03:00
|
|
|
permission_classes = (IsAuthenticated, RBACPermission)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
pagination_class = HundredPageSizePaginator
|
|
|
|
|
|
|
|
|
|
model = SlackChannel
|
|
|
|
|
filter_backends = (SearchFilter,)
|
|
|
|
|
serializer_class = SlackChannelSerializer
|
|
|
|
|
search_fields = ["name"]
|
|
|
|
|
|
2023-10-19 14:39:08 -03:00
|
|
|
rbac_permissions = {
|
|
|
|
|
"list": [RBACPermission.Permissions.CHATOPS_READ],
|
|
|
|
|
"retrieve": [RBACPermission.Permissions.CHATOPS_READ],
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
def get_queryset(self):
|
|
|
|
|
organization = self.request.auth.organization
|
|
|
|
|
slack_team_identity = organization.slack_team_identity
|
|
|
|
|
queryset = SlackChannel.objects.filter(
|
|
|
|
|
slack_team_identity=slack_team_identity,
|
|
|
|
|
is_archived=False,
|
|
|
|
|
)
|
|
|
|
|
|
2023-06-07 12:51:58 +02:00
|
|
|
return queryset.order_by("id")
|