mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
913 B
30 lines
913 B
# -*- coding: utf-8 -*-
|
|
#
|
|
from rest_framework import status
|
|
from rest_framework.decorators import action
|
|
from rest_framework.response import Response
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
|
from ..models import UserGroup, User
|
|
from ..serializers import UserGroupSerializer
|
|
|
|
__all__ = ['UserGroupViewSet']
|
|
|
|
|
|
class UserGroupViewSet(OrgBulkModelViewSet):
|
|
model = UserGroup
|
|
filterset_fields = ("name",)
|
|
search_fields = filterset_fields
|
|
serializer_class = UserGroupSerializer
|
|
ordering = ('name',)
|
|
rbac_perms = (
|
|
("add_all_users", "users.add_usergroup"),
|
|
)
|
|
|
|
@action(methods=['post'], detail=True, url_path='add-all-users')
|
|
def add_all_users(self, request, *args, **kwargs):
|
|
instance = self.get_object()
|
|
users = User.get_org_users().exclude(groups__id=instance.id)
|
|
instance.users.add(*users)
|
|
return Response(status=status.HTTP_200_OK)
|