mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-28 08:06:27 +00:00
feat: 应用授权增加Action动作控制
This commit is contained in:
26
apps/perms/serializers/base.py
Normal file
26
apps/perms/serializers/base.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from rest_framework import serializers
|
||||
from perms.models import Action
|
||||
|
||||
__all__ = ['ActionsDisplayField', 'ActionsField']
|
||||
|
||||
|
||||
class ActionsField(serializers.MultipleChoiceField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['choices'] = Action.CHOICES
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def to_representation(self, value):
|
||||
return Action.value_to_choices(value)
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if data is None:
|
||||
return data
|
||||
return Action.choices_to_value(data)
|
||||
|
||||
|
||||
class ActionsDisplayField(ActionsField):
|
||||
def to_representation(self, value):
|
||||
values = super().to_representation(value)
|
||||
choices = dict(Action.CHOICES)
|
||||
return [choices.get(i) for i in values]
|
||||
|
Reference in New Issue
Block a user