|
|
@ -2,12 +2,11 @@ from django.utils.translation import ugettext as _ |
|
|
|
from rest_framework import serializers |
|
|
|
from rest_framework import serializers |
|
|
|
|
|
|
|
|
|
|
|
from common.serializers import BulkModelSerializer, MethodSerializer |
|
|
|
from common.serializers import BulkModelSerializer, MethodSerializer |
|
|
|
from common.serializers.fields import ObjectRelatedField, LabeledChoiceField |
|
|
|
from common.serializers.fields import ObjectRelatedField |
|
|
|
from jumpserver.utils import has_valid_xpack_license |
|
|
|
|
|
|
|
from users.models import User |
|
|
|
from users.models import User |
|
|
|
|
|
|
|
from .base import ActionAclSerializer |
|
|
|
from .rules import RuleSerializer |
|
|
|
from .rules import RuleSerializer |
|
|
|
from ..models import LoginACL |
|
|
|
from ..models import LoginACL |
|
|
|
from ..models.base import ActionChoices |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [ |
|
|
|
__all__ = [ |
|
|
|
"LoginACLSerializer", |
|
|
|
"LoginACLSerializer", |
|
|
@ -18,12 +17,11 @@ common_help_text = _( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LoginACLSerializer(BulkModelSerializer): |
|
|
|
class LoginACLSerializer(ActionAclSerializer, BulkModelSerializer): |
|
|
|
user = ObjectRelatedField(queryset=User.objects, label=_("User")) |
|
|
|
user = ObjectRelatedField(queryset=User.objects, label=_("User")) |
|
|
|
reviewers = ObjectRelatedField( |
|
|
|
reviewers = ObjectRelatedField( |
|
|
|
queryset=User.objects, label=_("Reviewers"), many=True, required=False |
|
|
|
queryset=User.objects, label=_("Reviewers"), many=True, required=False |
|
|
|
) |
|
|
|
) |
|
|
|
action = LabeledChoiceField(choices=ActionChoices.choices, label=_('Action')) |
|
|
|
|
|
|
|
reviewers_amount = serializers.IntegerField( |
|
|
|
reviewers_amount = serializers.IntegerField( |
|
|
|
read_only=True, source="reviewers.count", label=_("Reviewers amount") |
|
|
|
read_only=True, source="reviewers.count", label=_("Reviewers amount") |
|
|
|
) |
|
|
|
) |
|
|
@ -45,18 +43,5 @@ class LoginACLSerializer(BulkModelSerializer): |
|
|
|
"is_active": {"default": True}, |
|
|
|
"is_active": {"default": True}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
|
|
|
|
self.set_action_choices() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_action_choices(self): |
|
|
|
|
|
|
|
action = self.fields.get("action") |
|
|
|
|
|
|
|
if not action: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
choices = action.choices |
|
|
|
|
|
|
|
if not has_valid_xpack_license(): |
|
|
|
|
|
|
|
choices.pop(LoginACL.ActionChoices.review, None) |
|
|
|
|
|
|
|
action._choices = choices |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_rules_serializer(self): |
|
|
|
def get_rules_serializer(self): |
|
|
|
return RuleSerializer() |
|
|
|
return RuleSerializer() |
|
|
|