2022-12-06 10:26:07 +00:00
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.response import Response
|
2022-12-01 11:41:18 +00:00
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
|
|
|
from .. import models, serializers
|
|
|
|
|
2022-12-02 04:27:26 +00:00
|
|
|
__all__ = ['CommandFilterACLViewSet', 'CommandGroupViewSet']
|
2022-12-01 11:41:18 +00:00
|
|
|
|
|
|
|
|
2022-12-02 03:53:07 +00:00
|
|
|
class CommandGroupViewSet(OrgBulkModelViewSet):
|
|
|
|
model = models.CommandGroup
|
|
|
|
filterset_fields = ('name',)
|
|
|
|
search_fields = filterset_fields
|
|
|
|
serializer_class = serializers.CommandGroupSerializer
|
|
|
|
|
|
|
|
|
2022-12-01 11:41:18 +00:00
|
|
|
class CommandFilterACLViewSet(OrgBulkModelViewSet):
|
|
|
|
model = models.CommandFilterACL
|
2022-12-02 03:53:07 +00:00
|
|
|
filterset_fields = ('name',)
|
2022-12-01 11:41:18 +00:00
|
|
|
search_fields = filterset_fields
|
2022-12-04 10:01:35 +00:00
|
|
|
serializer_class = serializers.CommandFilterACLSerializer
|
2022-12-06 10:26:07 +00:00
|
|
|
rbac_perms = {
|
|
|
|
'command_review': 'tickets.add_superticket'
|
|
|
|
}
|
|
|
|
|
|
|
|
@action(['POST'], detail=False, url_path='command-review')
|
|
|
|
def command_review(self, request, *args, **kwargs):
|
|
|
|
serializer = serializers.CommandReviewSerializer(data=request.data)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
data = {
|
|
|
|
'run_command': serializer.validated_data['run_command'],
|
|
|
|
'session': serializer.session,
|
|
|
|
'cmd_filter_acl': serializer.cmd_filter_acl,
|
|
|
|
'org_id': serializer.org.id
|
|
|
|
}
|
|
|
|
ticket = serializer.cmd_filter_acl.create_command_review_ticket(**data)
|
2023-01-16 11:02:09 +00:00
|
|
|
info = ticket.get_extra_info_of_review(user=request.user)
|
2023-02-09 03:06:48 +00:00
|
|
|
return Response(data=info)
|