mirror of https://github.com/jumpserver/jumpserver
Michael Bai
3 years ago
committed by
老广
18 changed files with 258 additions and 139 deletions
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.13 on 2021-12-20 06:55 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
ACTION_CONNECT = 1 |
||||
|
||||
|
||||
def migrate_app_perms_actions(apps, schema_editor): |
||||
perm_model = apps.get_model("perms", "ApplicationPermission") |
||||
perm_model.objects.all().update(actions=ACTION_CONNECT) |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('perms', '0021_auto_20211105_1605'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='applicationpermission', |
||||
name='actions', |
||||
field=models.IntegerField(choices=[(255, 'All'), (1, 'Connect'), (2, 'Upload file'), (4, 'Download file'), (6, 'Upload download'), (8, 'Clipboard copy'), (16, 'Clipboard paste'), (24, 'Clipboard copy paste')], default=255, verbose_name='Actions'), |
||||
), |
||||
migrations.RunPython(migrate_app_perms_actions) |
||||
] |
@ -1,5 +1,6 @@
|
||||
# coding: utf-8 |
||||
# |
||||
from .base import * |
||||
from .asset import * |
||||
from .application import * |
||||
from .system_user_permission import * |
||||
|
@ -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] |
||||
|
Loading…
Reference in new issue