[Merge] 合并标签功能

pull/968/head
ibuler 2018-01-26 15:49:09 +08:00
commit b0fab2453a
28 changed files with 760 additions and 231 deletions

View File

@ -17,25 +17,26 @@ from rest_framework import generics
from rest_framework.response import Response
from rest_framework_bulk import BulkModelViewSet
from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
from rest_framework.pagination import LimitOffsetPagination
from django.shortcuts import get_object_or_404
from django.db.models import Q, Count
from rest_framework.pagination import LimitOffsetPagination
from common.mixins import CustomFilterMixin
from common.utils import get_logger
from .hands import IsSuperUser, IsValidUser, IsSuperUserOrAppUser, \
get_user_granted_assets
from .models import AssetGroup, Asset, Cluster, SystemUser, AdminUser
from .models import AssetGroup, Asset, Cluster, SystemUser, AdminUser, Label
from . import serializers
from .tasks import update_asset_hardware_info_manual, test_admin_user_connectability_manual, \
test_asset_connectability_manual, push_system_user_to_cluster_assets_manual, \
test_system_user_connectability_manual
from .utils import LabelFilter
logger = get_logger(__file__)
class AssetViewSet(CustomFilterMixin, BulkModelViewSet):
class AssetViewSet(CustomFilterMixin, LabelFilter, BulkModelViewSet):
"""
API endpoint that allows Asset to be viewed or edited.
"""
@ -295,3 +296,15 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView):
system_user = self.get_object()
test_system_user_connectability_manual.delay(system_user)
return Response({"msg": "Task created"})
class LabelViewSet(BulkModelViewSet):
queryset = Label.objects.annotate(asset_count=Count("assets"))
permission_classes = (IsSuperUser,)
serializer_class = serializers.LabelSerializer
def list(self, request, *args, **kwargs):
if request.query_params.get("distinct"):
self.serializer_class = serializers.LabelDistinctSerializer
self.queryset = self.queryset.values("name").distinct()
return super().list(request, *args, **kwargs)

View File

@ -2,28 +2,35 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from .models import Cluster, Asset, AssetGroup, AdminUser, SystemUser
from .models import Cluster, Asset, AssetGroup, AdminUser, SystemUser, Label
from common.utils import validate_ssh_private_key, ssh_pubkey_gen, ssh_key_gen, get_logger
logger = get_logger(__file__)
class AssetCreateForm(forms.ModelForm):
class Meta:
model = Asset
fields = [
'hostname', 'ip', 'public_ip', 'port', 'type', 'comment',
'cluster', 'groups', 'status', 'env', 'is_active',
'admin_user'
'admin_user', 'labels'
]
widgets = {
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'data-placeholder': _('Select asset groups')}),
'cluster': forms.Select(attrs={'class': 'select2', 'data-placeholder': _('Select cluster')}),
'admin_user': forms.Select(attrs={'class': 'select2', 'data-placeholder': _('Select admin user')}),
'port': forms.TextInput()
'groups': forms.SelectMultiple(attrs={
'class': 'select2', 'data-placeholder': _('Select asset groups')
}),
'cluster': forms.Select(attrs={
'class': 'select2', 'data-placeholder': _('Select cluster')
}),
'admin_user': forms.Select(attrs={
'class': 'select2', 'data-placeholder': _('Select admin user')
}),
'labels': forms.SelectMultiple(attrs={
'class': 'select2', 'data-placeholder': _('Select labels')
}),
'port': forms.TextInput(),
}
help_texts = {
'hostname': '* required',
@ -40,6 +47,14 @@ class AssetCreateForm(forms.ModelForm):
raise forms.ValidationError(_("You need set a admin user if cluster not have"))
return self.cleaned_data['admin_user']
def is_valid(self):
print(self.data)
result = super().is_valid()
if not result:
print(self.errors)
print(self.cleaned_data)
return result
class AssetUpdateForm(forms.ModelForm):
class Meta:
@ -47,11 +62,22 @@ class AssetUpdateForm(forms.ModelForm):
fields = [
'hostname', 'ip', 'port', 'groups', "cluster", 'is_active',
'type', 'env', 'status', 'public_ip', 'remote_card_ip', 'cabinet_no',
'cabinet_pos', 'number', 'comment', 'admin_user',
'cabinet_pos', 'number', 'comment', 'admin_user', 'labels'
]
widgets = {
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'data-placeholder': _('Select asset groups')}),
'admin_user': forms.Select(attrs={'class': 'select2', 'data-placeholder': _("Default using cluster admin user")})
'groups': forms.SelectMultiple(attrs={
'class': 'select2', 'data-placeholder': _('Select asset groups')
}),
'cluster': forms.Select(attrs={
'class': 'select2', 'data-placeholder': _('Select cluster')
}),
'admin_user': forms.Select(attrs={
'class': 'select2', 'data-placeholder': _('Select admin user')
}),
'labels': forms.SelectMultiple(attrs={
'class': 'select2', 'data-placeholder': _('Select labels')
}),
'port': forms.TextInput(),
}
help_texts = {
'hostname': '* required',
@ -68,13 +94,15 @@ class AssetUpdateForm(forms.ModelForm):
raise forms.ValidationError(_("You need set a admin user if cluster not have"))
return self.cleaned_data['admin_user']
def is_valid(self):
print(self.data)
return super().is_valid()
class AssetBulkUpdateForm(forms.ModelForm):
assets = forms.ModelMultipleChoiceField(
required=True,
help_text='* required',
label=_('Select assets'),
queryset=Asset.objects.all(),
required=True, help_text='* required',
label=_('Select assets'), queryset=Asset.objects.all(),
widget=forms.SelectMultiple(
attrs={
'class': 'select2',
@ -83,10 +111,7 @@ class AssetBulkUpdateForm(forms.ModelForm):
)
)
port = forms.IntegerField(
label=_('Port'),
required=False,
min_value=1,
max_value=65535,
label=_('Port'), required=False, min_value=1, max_value=65535,
)
class Meta:
@ -96,7 +121,9 @@ class AssetBulkUpdateForm(forms.ModelForm):
'type', 'env',
]
widgets = {
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'data-placeholder': _('Select asset groups')}),
'groups': forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select asset groups')}
),
}
def save(self, commit=True):
@ -140,7 +167,7 @@ class AssetGroupForm(forms.ModelForm):
def save(self, commit=True):
group = super().save(commit=commit)
assets= self.cleaned_data['assets']
assets = self.cleaned_data['assets']
group.assets.set(assets)
return group
@ -377,3 +404,28 @@ class SystemUserAuthForm(forms.Form):
class FileForm(forms.Form):
file = forms.FileField()
class LabelForm(forms.ModelForm):
assets = forms.ModelMultipleChoiceField(
queryset=Asset.objects.all(), label=_('Asset'), required=False,
widget=forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select assets')}
)
)
class Meta:
model = Label
fields = ['name', 'value', 'assets']
def __init__(self, *args, **kwargs):
if kwargs.get('instance', None):
initial = kwargs.get('initial', {})
initial['assets'] = kwargs['instance'].assets.all()
super().__init__(*args, **kwargs)
def save(self, commit=True):
label = super().save(commit=commit)
assets = self.cleaned_data['assets']
label.assets.set(assets)
return label

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
from .user import AdminUser, SystemUser
from .label import Label
from .cluster import *
from .group import *
from .asset import *

View File

@ -88,6 +88,8 @@ class Asset(models.Model):
os_arch = models.CharField(max_length=16, blank=True, null=True, verbose_name=_('OS arch'))
hostname_raw = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Hostname raw'))
labels = models.ManyToManyField('assets.Label', blank=True, related_name='assets', verbose_name=_("Labels"))
created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by'))
date_created = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name=_('Date created'))
comment = models.TextField(max_length=128, default='', blank=True, verbose_name=_('Comment'))

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
#
import uuid
from django.db import models
from django.utils.translation import ugettext_lazy as _
class Label(models.Model):
SYSTEM_CATEGORY = "S"
USER_CATEGORY = "U"
CATEGORY_CHOICES = (
("S", _("System")),
("U", _("User"))
)
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, verbose_name=_("Name"))
value = models.CharField(max_length=128, verbose_name=_("Value"))
category = models.CharField(max_length=128, choices=CATEGORY_CHOICES, default=USER_CATEGORY, verbose_name=_("Category"))
is_active = models.BooleanField(default=True, verbose_name=_("Is active"))
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
date_created = models.DateTimeField(
auto_now_add=True, null=True, blank=True, verbose_name=_('Date created')
)
@classmethod
def get_queryset_group_by_name(cls):
names = cls.objects.values_list('name', flat=True)
for name in names:
yield name, cls.objects.filter(name=name)
def __str__(self):
return "{}:{}".format(self.name, self.value)
class Meta:
db_table = "assets_label"
unique_together = ('name', 'value')

View File

@ -4,7 +4,7 @@ from rest_framework import serializers
from rest_framework_bulk.serializers import BulkListSerializer
from common.mixins import BulkSerializerMixin
from .models import AssetGroup, Asset, Cluster, AdminUser, SystemUser
from .models import AssetGroup, Asset, Cluster, AdminUser, SystemUser, Label
from .const import ADMIN_USER_CONN_CACHE_KEY, SYSTEM_USER_CONN_CACHE_KEY
@ -286,3 +286,34 @@ class MyAssetGroupGrantedSerializer(serializers.ModelSerializer):
@staticmethod
def get_assets_amount(obj):
return len(obj.assets_granted)
class LabelSerializer(serializers.ModelSerializer):
asset_count = serializers.SerializerMethodField()
class Meta:
model = Label
fields = '__all__'
list_serializer_class = BulkListSerializer
@staticmethod
def get_asset_count(obj):
return obj.asset_count
def get_field_names(self, declared_fields, info):
fields = super().get_field_names(declared_fields, info)
fields.extend(['get_category_display'])
return fields
class LabelDistinctSerializer(serializers.ModelSerializer):
value = serializers.SerializerMethodField()
class Meta:
model = Label
fields = ("name", "value")
@staticmethod
def get_value(obj):
labels = Label.objects.filter(name=obj["name"])
return ', '.join([label.value for label in labels])

View File

@ -2,6 +2,8 @@
{% load static %}
{% load bootstrap3 %}
{% load i18n %}
{% load asset_tags %}
{% load common_tags %}
{% block form %}
<form action="" method="post" class="form-horizontal">
@ -28,12 +30,37 @@
<h3>{% trans 'Group' %}</h3>
{% bootstrap_field form.groups layout="horizontal" %}
<div class="hr-line-dashed"></div>
<h3>{% trans 'Labels' %}</h3>
<div class="form-group {% if form.errors.labels %} has-error {% endif %}">
<label for="{{ form.labels.id_for_label }}" class="col-md-2 control-label">{% trans 'Label' %}</label>
<div class="col-md-9">
<select name="labels" class="select2 labels" data-placeholder="{% trans 'Select labels' %}" style="width: 100%" multiple="" tabindex="4" id="{{ form.labels.id_for_label }}">
{% for name, labels in form.labels.field.queryset|group_labels %}
<optgroup label="{{ name }}">
{% for label in labels %}
{% if label in form.labels.initial %}
<option value="{{ label.id }}" selected>{{ label.value }}</option>
{% else %}
<option value="{{ label.id }}">{{ label.value }}</option>
{% endif %}
{% endfor %}
</optgroup>
{% endfor %}
</select>
{% if form.errors.labels %}
{% for e in form.errors.labels %}
<div class="help-block">{{ e }}</div>
{% endfor %}
{% endif %}
</div>
</div>
<div class="hr-line-dashed"></div>
<h3>{% trans 'Other' %}</h3>
{% bootstrap_field form.comment layout="horizontal" %}
{% bootstrap_field form.is_active layout="horizontal" %}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
@ -45,11 +72,20 @@
{% endblock %}
{% block custom_foot_js %}
<script>
$(document).ready(function () {
$('.select2').select2({
allowClear: true
});
})
</script>
<script>
function format(item) {
var group = item.element.parentElement.label;
return group + ':' + item.text;
}
$(document).ready(function () {
$('.select2').select2({
allowClear: true
});
$(".labels").select2({
allowClear: true,
templateSelection: format
});
})
</script>
{% endblock %}

View File

@ -244,6 +244,33 @@
</table>
</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">
<i class="fa fa-info-circle"></i> {% trans 'Labels' %}
</div>
<div class="panel-body">
{# <table class="table">#}
{# <tbody>#}
{# {% for label in asset.labels.all %}#}
{# <tr {% if forloop.counter == 1 %} class="no-borders-tr" {% endif %}>#}
{# <td>{{ label.name }}</td>#}
{# <td>#}
{# <span class="pull-right">#}
{# {{ label.value }}#}
{# </span>#}
{# </td>#}
{# </tr>#}
{# {% endfor %}#}
{# </tbody>#}
{# </table>#}
<ul class="tag-list" style="padding: 0">
{% for label in asset.labels.all %}
<li ><a href=""><i class="fa fa-tag"></i> {{ label.name }}:{{ label.value }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</div>
</div>

View File

@ -23,6 +23,14 @@
{% block table_container %}
<div class="uc pull-left m-r-5"><a href="{% url "assets:asset-create" %}" class="btn btn-sm btn-primary"> {% trans "Create asset" %} </a></div>
<div class="btn-group" style="float: right">
<button data-toggle="dropdown" class="btn btn-default btn-sm dropdown-toggle">{% trans 'Label' %} <span class="caret"></span></button>
<ul class="dropdown-menu labels">
{% for label in labels %}
<li><a style="font-weight: bolder">{{ label.name }}:{{ label.value }}</a></li>
{% endfor %}
</ul>
</div>
<table class="table table-striped table-bordered table-hover " id="asset_list_table" >
<thead>
<tr>
@ -114,6 +122,20 @@ function initTable() {
$(document).ready(function(){
initTable();
$(".select2").select2();
})
.on('click', '.labels li', function () {
var val = $(this).text();
{#var origin_val = $("#asset_list_table_filter input").val();#}
{#var new_val;#}
{#if (origin_val === "") {#}
{# new_val = val;#}
{# } else { #}
{# new_val = origin_val + " " + val;#}
{# } #}
$("#asset_list_table_filter input").val(val);
{#$('#asset_list_table').DataTable().search(val).draw();#}
jumpserver.table.search(val).draw();
})
.on('click', '.btn_export', function () {
var $data_table = $('#asset_list_table').DataTable();

View File

@ -2,6 +2,8 @@
{% load static %}
{% load bootstrap3 %}
{% load i18n %}
{% load asset_tags %}
{% load common_tags %}
{% block custom_head_css_js_create %}
<link href="{% static "css/plugins/inputTags.css" %}" rel="stylesheet">
@ -33,6 +35,27 @@
<h3>{% trans 'Group' %}</h3>
{% bootstrap_field form.groups layout="horizontal" %}
<div class="hr-line-dashed"></div>
<h3>{% trans 'Labels' %}</h3>
<div class="form-group">
<label for="{{ form.labels.id_for_label }}" class="col-md-2 control-label">{% trans 'Label' %}</label>
<div class="col-md-9">
<select name="labels" class="select2 labels" data-placeholder="Select labels" style="width: 100%" multiple="" tabindex="4" id="{{ form.labels.id_for_label }}">
{% for name, labels in form.labels.field.queryset|group_labels %}
<optgroup label="{{ name }}">
{% for label in labels %}
{% if label in form.labels.initial %}
<option value="{{ label.id }}" selected>{{ label.value }}</option>
{% else %}
<option value="{{ label.id }}">{{ label.value }}</option>
{% endif %}
{% endfor %}
</optgroup>
{% endfor %}
</select>
</div>
</div>
<div class="hr-line-dashed"></div>
<h3>{% trans 'Configuration' %}</h3>
{% bootstrap_field form.number layout="horizontal" %}
@ -62,14 +85,18 @@
{% block custom_foot_js %}
<script>
$(document).ready(function () {
$('.select2').select2({
allowClear: true
});
$("#tags").select2({
tags: true,
maximumSelectionLength: 8 //最多能够选择的个数
});
})
function format(item) {
var group = item.element.parentElement.label;
return group + ':' + item.text;
}
$(document).ready(function () {
$('.select2').select2({
allowClear: true
});
$(".labels").select2({
allowClear: true,
templateSelection: format
});
})
</script>
{% endblock %}

View File

@ -0,0 +1,31 @@
{% extends '_base_create_update.html' %}
{% load static %}
{% load bootstrap3 %}
{% load i18n %}
{% block form %}
<form id="groupForm" method="post" class="form-horizontal">
{% csrf_token %}
{% bootstrap_field form.name layout="horizontal" %}
{% bootstrap_field form.value layout="horizontal" %}
{% bootstrap_field form.assets layout="horizontal" %}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-default" type="reset"> {% trans 'Reset' %}</button>
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
</div>
</div>
</form>
{% endblock %}
{% block custom_foot_js %}
<script type="text/javascript">
$(document).ready(function () {
$('.select2').select2({
closeOnSelect: false
});
});
</script>
{% endblock %}

View File

@ -0,0 +1,69 @@
{% extends '_base_list.html' %}
{% load i18n static %}
{% block table_search %}{% endblock %}
{% block table_container %}
<div class="uc pull-left m-r-5">
<a href="{% url 'assets:label-create' %}" class="btn btn-sm btn-primary"> {% trans "Create label" %} </a>
</div>
<table class="table table-striped table-bordered table-hover " id="label_list_table" >
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="check_all" class="ipt_check_all" >
</th>
<th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Value' %}</th>
<th class="text-center">{% trans 'Asset' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
function initTable() {
var options = {
ele: $('#label_list_table'),
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
{# var detail_btn = '<a href="{% url "assets:label-detail" pk=DEFAULT_PK %}">' + cellData + '</a>';#}
var detail_btn = '<a>' + cellData + '</a>';
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id));
}},
{targets: 4, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "assets:label-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_cluster_delete" data-uid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
$(td).html(update_btn + del_btn)
}}],
ajax_url: '{% url "api-assets:label-list" %}?sort=name',
columns: [
{data: "id"}, {data: "name" }, {data: "value" },
{data: "asset_count" }, {data: "id"}
],
op_html: $('#actions').html()
};
jumpserver.initDataTable(options);
}
$(document).ready(function(){
initTable();
})
.on('click', '.btn_cluster_delete', function () {
var $this = $(this);
var $data_table = $('#cluster_list_table').DataTable();
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
var uid = $this.data('uid');
var the_url = '{% url "api-assets:cluster-detail" pk=DEFAULT_PK %}'.replace('{{ DEFAULT_PK }}', uid);
objectDelete($this, name, the_url);
setTimeout( function () {
$data_table.ajax.reload();
}, 3000);
});
</script>
{% endblock %}

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
#

View File

@ -1,6 +1,12 @@
from collections import defaultdict
from django import template
from django.utils import timezone
from django.conf import settings
register = template.Library()
@register.filter
def group_labels(queryset):
grouped = defaultdict(list)
for label in queryset:
grouped[label.name].append(label)
return [(name, labels) for name, labels in grouped.items()]

View File

@ -12,6 +12,7 @@ router.register(r'v1/assets', api.AssetViewSet, 'asset')
router.register(r'v1/clusters', api.ClusterViewSet, 'cluster')
router.register(r'v1/admin-user', api.AdminUserViewSet, 'admin-user')
router.register(r'v1/system-user', api.SystemUserViewSet, 'system-user')
router.register(r'v1/labels', api.LabelViewSet, 'label')
urlpatterns = [
url(r'^v1/assets-bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'),

View File

@ -53,5 +53,8 @@ urlpatterns = [
# url(r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'),
url(r'^label/$', views.LabelListView.as_view(), name='label-list'),
url(r'^label/create/$', views.LabelCreateView.as_view(), name='label-create'),
url(r'^label/(?P<pk>[0-9a-zA-Z\-]{36})/update/$', views.LabelUpdateView.as_view(), name='label-update'),
]

View File

@ -1,8 +1,13 @@
# ~*~ coding: utf-8 ~*~
#
from collections import defaultdict
from functools import reduce
import operator
from django.db.models import Q
from common.utils import get_object_or_none
from .models import Asset, SystemUser
from .models import Asset, SystemUser, Label
def get_assets_by_id_list(id_list):
@ -27,3 +32,23 @@ def check_assets_have_system_user(assets, system_users):
if asset.cluster not in clusters:
errors[asset].append(system_user)
return errors
class LabelFilter:
def filter_queryset(self, queryset):
query_keys = self.request.query_params.keys()
all_label_keys = Label.objects.values_list('name', flat=True)
valid_keys = set(all_label_keys) & set(query_keys)
labels_query = {}
for key in valid_keys:
labels_query[key] = self.request.query_params.get(key)
conditions = []
for k, v in labels_query.items():
query = {'labels__name': k, 'labels__value': v}
conditions.append(query)
if conditions:
for kwargs in conditions:
queryset = queryset.filter(**kwargs)
return queryset

View File

@ -4,4 +4,5 @@ from .group import *
from .cluster import *
from .system_user import *
from .admin_user import *
from .label import *

View File

@ -27,7 +27,7 @@ from common.mixins import JSONResponseMixin
from common.utils import get_object_or_none, get_logger, is_uuid
from common.const import create_success_msg, update_success_msg
from .. import forms
from ..models import Asset, AssetGroup, AdminUser, Cluster, SystemUser
from ..models import Asset, AssetGroup, AdminUser, Cluster, SystemUser, Label
from ..hands import AdminUserRequiredMixin
@ -48,6 +48,7 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
'app': _('Assets'),
'action': _('Asset list'),
'system_users': SystemUser.objects.all(),
'labels': Label.objects.all().order_by('name'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -72,12 +73,13 @@ class AssetCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
template_name = 'assets/asset_create.html'
success_url = reverse_lazy('assets:asset-list')
def form_valid(self, form):
asset = form.save()
asset.created_by = self.request.user.username or 'Admin'
asset.date_created = timezone.now()
asset.save()
return super().form_valid(form)
# def form_valid(self, form):
# print("form valid")
# asset = form.save()
# asset.created_by = self.request.user.username or 'Admin'
# asset.date_created = timezone.now()
# asset.save()
# return super().form_valid(form)
def get_context_data(self, **kwargs):
context = {

View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
#
from django.views.generic import TemplateView, CreateView, \
UpdateView, DeleteView, DetailView
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse_lazy
from common.mixins import AdminUserRequiredMixin
from common.const import create_success_msg, update_success_msg
from ..models import Label
from ..forms import LabelForm
__all__ = (
"LabelListView", "LabelCreateView", "LabelUpdateView",
"LabelDetailView", "LabelDeleteView",
)
class LabelListView(AdminUserRequiredMixin, TemplateView):
template_name = 'assets/label_list.html'
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Label list'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
class LabelCreateView(AdminUserRequiredMixin, CreateView):
model = Label
template_name = 'assets/label_create_update.html'
form_class = LabelForm
success_url = reverse_lazy('assets:label-list')
success_message = create_success_msg
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Create label'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
class LabelUpdateView(AdminUserRequiredMixin, UpdateView):
model = Label
template_name = 'assets/label_create_update.html'
form_class = LabelForm
success_url = reverse_lazy('assets:label-list')
success_message = update_success_msg
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Update label'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
class LabelDetailView(AdminUserRequiredMixin, DetailView):
pass
class LabelDeleteView(AdminUserRequiredMixin, DeleteView):
pass

View File

@ -92,3 +92,8 @@ def is_bool_field(field):
return True
else:
return False
@register.filter
def to_dict(data):
return dict(data)

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Jumpserver 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-23 11:56+0800\n"
"POT-Creation-Date: 2018-01-26 15:43+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
@ -17,42 +17,44 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: assets/forms.py:23 assets/forms.py:53 assets/forms.py:99 perms/forms.py:37
#: assets/forms.py:22 assets/forms.py:69 assets/forms.py:125 perms/forms.py:37
#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:245
msgid "Select asset groups"
msgstr "选择资产组"
#: assets/forms.py:24 assets/templates/assets/admin_user_detail.html:92
#: assets/forms.py:25 assets/forms.py:72
#: assets/templates/assets/admin_user_detail.html:92
msgid "Select cluster"
msgstr "选择集群"
#: assets/forms.py:25
#: assets/forms.py:28 assets/forms.py:75
msgid "Select admin user"
msgstr "选择管理用户"
#: assets/forms.py:33 assets/forms.py:61
#: assets/forms.py:31 assets/forms.py:78
msgid "Select labels"
msgstr "选择标签"
#: assets/forms.py:40 assets/forms.py:87
msgid "Host level admin user, If not set using cluster admin user default"
msgstr "主机级别管理用户,如果没有设置则默认使用集群级别管理用户"
#: assets/forms.py:40 assets/forms.py:68
#: assets/forms.py:47 assets/forms.py:94
msgid "You need set a admin user if cluster not have"
msgstr "集群没有管理用户,你需要为集群设置管理用户或设置一个主机级别的管理用户"
#: assets/forms.py:54
msgid "Default using cluster admin user"
msgstr "默认使用管理用户"
#: assets/forms.py:76 assets/forms.py:81 assets/forms.py:127
#: assets/templates/assets/asset_group_detail.html:75 perms/forms.py:34
#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:242
#: assets/forms.py:105 assets/forms.py:109 assets/forms.py:154
#: assets/forms.py:413 assets/templates/assets/asset_group_detail.html:75
#: perms/forms.py:34 perms/templates/perms/asset_permission_asset.html:88
#: users/forms.py:242
msgid "Select assets"
msgstr "选择资产"
#: assets/forms.py:86 assets/models/asset.py:55
#: assets/forms.py:114 assets/models/asset.py:55
#: assets/templates/assets/admin_user_assets.html:61
#: assets/templates/assets/asset_detail.html:69
#: assets/templates/assets/asset_group_detail.html:52
#: assets/templates/assets/asset_list.html:32
#: assets/templates/assets/asset_list.html:40
#: assets/templates/assets/cluster_assets.html:53
#: assets/templates/assets/system_user_asset.html:54
#: assets/templates/assets/user_asset_list.html:21
@ -60,9 +62,10 @@ msgstr "选择资产"
msgid "Port"
msgstr "端口"
#: assets/forms.py:124 assets/models/asset.py:171
#: assets/forms.py:151 assets/forms.py:411 assets/models/asset.py:173
#: assets/templates/assets/admin_user_list.html:24
#: assets/templates/assets/asset_group_list.html:16
#: assets/templates/assets/label_list.html:16
#: assets/templates/assets/system_user_list.html:26 perms/models.py:17
#: perms/templates/perms/asset_permission_create_update.html:40
#: perms/templates/perms/asset_permission_list.html:28 templates/_nav.html:22
@ -76,28 +79,30 @@ msgstr "端口"
msgid "Asset"
msgstr "资产"
#: assets/forms.py:161 perms/forms.py:40
#: assets/forms.py:188 perms/forms.py:40
#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:248
msgid "Select system users"
msgstr "选择系统用户"
#: assets/forms.py:163
#: assets/forms.py:190
#: assets/templates/assets/_asset_group_bulk_update_modal.html:22
#: assets/templates/assets/cluster_list.html:22
msgid "System users"
msgstr "系统用户"
#: assets/forms.py:165
#: assets/forms.py:192
msgid "Selected system users will be create at cluster assets"
msgstr "选择的系统用户将会在该集群资产上创建"
#: assets/forms.py:173 assets/forms.py:248 assets/forms.py:308
#: assets/forms.py:200 assets/forms.py:275 assets/forms.py:335
#: assets/models/cluster.py:18 assets/models/group.py:20
#: assets/models/user.py:28 assets/templates/assets/admin_user_detail.html:56
#: assets/models/label.py:17 assets/models/user.py:28
#: assets/templates/assets/admin_user_detail.html:56
#: assets/templates/assets/admin_user_list.html:22
#: assets/templates/assets/asset_group_list.html:15
#: assets/templates/assets/cluster_detail.html:57
#: assets/templates/assets/cluster_list.html:19
#: assets/templates/assets/label_list.html:14
#: assets/templates/assets/system_user_detail.html:58
#: assets/templates/assets/system_user_list.html:24 common/models.py:26
#: common/templates/common/terminal_setting.html:62 ops/models.py:31
@ -110,7 +115,7 @@ msgstr "选择的系统用户将会在该集群资产上创建"
#: terminal/models.py:141 terminal/templates/terminal/terminal_detail.html:43
#: terminal/templates/terminal/terminal_list.html:29 users/models/group.py:14
#: users/models/user.py:35 users/templates/users/_select_user_modal.html:13
#: users/templates/users/user_detail.html:62
#: users/templates/users/user_detail.html:63
#: users/templates/users/user_granted_asset.html:81
#: users/templates/users/user_group_detail.html:55
#: users/templates/users/user_group_granted_asset.html:85
@ -121,15 +126,15 @@ msgstr "选择的系统用户将会在该集群资产上创建"
msgid "Name"
msgstr "名称"
#: assets/forms.py:179
#: assets/forms.py:206
msgid "Cluster level admin user"
msgstr "集群级别管理用户"
#: assets/forms.py:200
#: assets/forms.py:227
msgid "Password or private key password"
msgstr "密码或秘钥密码"
#: assets/forms.py:201 assets/forms.py:262 assets/models/user.py:30
#: assets/forms.py:228 assets/forms.py:289 assets/models/user.py:30
#: common/forms.py:113 users/forms.py:16 users/forms.py:24
#: users/templates/users/login.html:56
#: users/templates/users/reset_password.html:52
@ -140,19 +145,19 @@ msgstr "密码或秘钥密码"
msgid "Password"
msgstr "密码"
#: assets/forms.py:204 assets/forms.py:264 users/models/user.py:45
#: assets/forms.py:231 assets/forms.py:291 users/models/user.py:45
msgid "Private key"
msgstr "ssh私钥"
#: assets/forms.py:229 assets/forms.py:290 assets/forms.py:354
#: assets/forms.py:256 assets/forms.py:317 assets/forms.py:381
msgid "Invalid private key"
msgstr "ssh密钥不合法"
#: assets/forms.py:240
#: assets/forms.py:267
msgid "Password and private key file must be input one"
msgstr "密码和私钥, 必须输入一个"
#: assets/forms.py:249 assets/forms.py:309 assets/models/user.py:29
#: assets/forms.py:276 assets/forms.py:336 assets/models/user.py:29
#: assets/templates/assets/admin_user_detail.html:60
#: assets/templates/assets/admin_user_list.html:23
#: assets/templates/assets/system_user_detail.html:62
@ -162,29 +167,29 @@ msgstr "密码和私钥, 必须输入一个"
#: users/templates/users/_select_user_modal.html:14
#: users/templates/users/login.html:53
#: users/templates/users/login_log_list.html:49
#: users/templates/users/user_detail.html:66
#: users/templates/users/user_detail.html:67
#: users/templates/users/user_list.html:24
#: users/templates/users/user_profile.html:47
msgid "Username"
msgstr "用户名"
#: assets/forms.py:297 assets/forms.py:360
#: assets/forms.py:324 assets/forms.py:387
msgid "Auth info required, private_key or password"
msgstr "密钥和密码必须填写一个"
#: assets/forms.py:313
#: assets/forms.py:340
msgid " Select clusters"
msgstr "选择集群"
#: assets/forms.py:320
#: assets/forms.py:347
msgid "If auto push checked, system user will be create at cluster assets"
msgstr "如果选择了自动推送,系统用户将会创建在集群资产上"
#: assets/forms.py:321
#: assets/forms.py:348
msgid "Auto push system user to asset"
msgstr "自动推送系统用户到资产"
#: assets/forms.py:322
#: assets/forms.py:349
msgid ""
"High level will be using login asset as default, if user was granted more "
"than 2 system user"
@ -237,7 +242,7 @@ msgstr "测试环境"
#: assets/models/asset.py:53 assets/templates/assets/admin_user_assets.html:60
#: assets/templates/assets/asset_detail.html:61
#: assets/templates/assets/asset_group_detail.html:51
#: assets/templates/assets/asset_list.html:31
#: assets/templates/assets/asset_list.html:39
#: assets/templates/assets/cluster_assets.html:52
#: assets/templates/assets/system_user_asset.html:53
#: assets/templates/assets/user_asset_list.html:20 common/forms.py:140
@ -251,7 +256,7 @@ msgstr "IP"
#: assets/models/asset.py:54 assets/templates/assets/admin_user_assets.html:59
#: assets/templates/assets/asset_detail.html:57
#: assets/templates/assets/asset_group_detail.html:50
#: assets/templates/assets/asset_list.html:30
#: assets/templates/assets/asset_list.html:38
#: assets/templates/assets/cluster_assets.html:51
#: assets/templates/assets/system_user_asset.html:52
#: assets/templates/assets/user_asset_list.html:19 common/forms.py:139
@ -262,17 +267,18 @@ msgid "Hostname"
msgstr "主机名"
#: assets/models/asset.py:56 assets/templates/assets/asset_detail.html:213
#: assets/views/asset.py:218 assets/views/asset.py:258
#: assets/views/asset.py:220 assets/views/asset.py:260
msgid "Asset groups"
msgstr "资产组"
#: assets/models/asset.py:57 assets/models/cluster.py:40
#: assets/models/user.py:219 assets/templates/assets/asset_detail.html:85
#: assets/templates/assets/asset_list.html:33 templates/_nav.html:24
#: assets/templates/assets/asset_list.html:41 templates/_nav.html:24
msgid "Cluster"
msgstr "集群"
#: assets/models/asset.py:58 assets/templates/assets/asset_detail.html:129
#: assets/models/asset.py:58 assets/models/label.py:20
#: assets/templates/assets/asset_detail.html:129
msgid "Is active"
msgstr "激活"
@ -370,7 +376,15 @@ msgstr "系统架构"
msgid "Hostname raw"
msgstr "主机名原始"
#: assets/models/asset.py:91 assets/models/cluster.py:28
#: assets/models/asset.py:91 assets/templates/assets/asset_create.html:34
#: assets/templates/assets/asset_create.html:36
#: assets/templates/assets/asset_detail.html:250
#: assets/templates/assets/asset_update.html:39
#: assets/templates/assets/asset_update.html:41
msgid "Labels"
msgstr "标签管理"
#: assets/models/asset.py:93 assets/models/cluster.py:28
#: assets/models/group.py:21 assets/models/user.py:36
#: assets/templates/assets/admin_user_detail.html:68
#: assets/templates/assets/asset_detail.html:149
@ -378,12 +392,13 @@ msgstr "主机名原始"
#: assets/templates/assets/system_user_detail.html:96
#: ops/templates/ops/adhoc_detail.html:86 perms/models.py:22
#: perms/templates/perms/asset_permission_detail.html:94
#: users/models/user.py:50 users/templates/users/user_detail.html:98
#: users/models/user.py:50 users/templates/users/user_detail.html:99
msgid "Created by"
msgstr "创建者"
#: assets/models/asset.py:92 assets/models/cluster.py:26
#: assets/models/group.py:22 assets/templates/assets/admin_user_detail.html:64
#: assets/models/asset.py:94 assets/models/cluster.py:26
#: assets/models/group.py:22 assets/models/label.py:23
#: assets/templates/assets/admin_user_detail.html:64
#: assets/templates/assets/cluster_detail.html:89
#: assets/templates/assets/system_user_detail.html:92
#: ops/templates/ops/adhoc_detail.html:90 ops/templates/ops/task_detail.html:60
@ -393,8 +408,8 @@ msgstr "创建者"
msgid "Date created"
msgstr "创建日期"
#: assets/models/asset.py:93 assets/models/cluster.py:29
#: assets/models/group.py:23 assets/models/user.py:33
#: assets/models/asset.py:95 assets/models/cluster.py:29
#: assets/models/group.py:23 assets/models/label.py:21 assets/models/user.py:33
#: assets/templates/assets/admin_user_detail.html:72
#: assets/templates/assets/admin_user_list.html:28
#: assets/templates/assets/asset_detail.html:157
@ -405,7 +420,7 @@ msgstr "创建日期"
#: ops/models.py:37 perms/models.py:24
#: perms/templates/perms/asset_permission_detail.html:98 terminal/models.py:25
#: terminal/templates/terminal/terminal_detail.html:63 users/models/group.py:15
#: users/models/user.py:47 users/templates/users/user_detail.html:110
#: users/models/user.py:47 users/templates/users/user_detail.html:111
#: users/templates/users/user_group_detail.html:67
#: users/templates/users/user_group_list.html:14
#: users/templates/users/user_profile.html:118
@ -421,7 +436,7 @@ msgid "Contact"
msgstr "联系人"
#: assets/models/cluster.py:22 assets/templates/assets/cluster_detail.html:69
#: users/models/user.py:41 users/templates/users/user_detail.html:75
#: users/models/user.py:41 users/templates/users/user_detail.html:76
msgid "Phone"
msgstr "手机"
@ -445,7 +460,8 @@ msgstr "运营商"
msgid "Default"
msgstr "默认"
#: assets/models/cluster.py:36 users/models/user.py:258
#: assets/models/cluster.py:36 assets/models/label.py:13
#: users/models/user.py:258
msgid "System"
msgstr "系统"
@ -462,6 +478,28 @@ msgstr "资产组"
msgid "Default asset group"
msgstr "默认资产组"
#: assets/models/label.py:14 perms/forms.py:18 perms/models.py:15
#: perms/templates/perms/asset_permission_create_update.html:36
#: perms/templates/perms/asset_permission_list.html:26 templates/_nav.html:12
#: terminal/backends/command/models.py:10 terminal/models.py:115
#: terminal/templates/terminal/command_list.html:32
#: terminal/templates/terminal/command_list.html:72
#: terminal/templates/terminal/session_list.html:33
#: terminal/templates/terminal/session_list.html:71 users/forms.py:190
#: users/models/user.py:30 users/templates/users/user_group_detail.html:78
#: users/views/user.py:337
msgid "User"
msgstr "用户"
#: assets/models/label.py:18 assets/templates/assets/label_list.html:15
#: common/models.py:27
msgid "Value"
msgstr "值"
#: assets/models/label.py:19
msgid "Category"
msgstr "分类"
#: assets/models/user.py:31
msgid "SSH private key"
msgstr "ssh密钥"
@ -575,11 +613,12 @@ msgstr "仅修改你需要更新的字段"
#: assets/views/admin_user.py:29 assets/views/admin_user.py:47
#: assets/views/admin_user.py:63 assets/views/admin_user.py:79
#: assets/views/admin_user.py:106 assets/views/asset.py:48
#: assets/views/asset.py:61 assets/views/asset.py:84 assets/views/asset.py:144
#: assets/views/asset.py:161 assets/views/asset.py:185
#: assets/views/asset.py:62 assets/views/asset.py:86 assets/views/asset.py:146
#: assets/views/asset.py:163 assets/views/asset.py:187
#: assets/views/cluster.py:26 assets/views/cluster.py:80
#: assets/views/cluster.py:97 assets/views/group.py:34 assets/views/group.py:52
#: assets/views/group.py:69 assets/views/group.py:87
#: assets/views/group.py:69 assets/views/group.py:87 assets/views/label.py:26
#: assets/views/label.py:42 assets/views/label.py:58
#: assets/views/system_user.py:28 assets/views/system_user.py:44
#: assets/views/system_user.py:60 assets/views/system_user.py:75
#: templates/_nav.html:19
@ -627,15 +666,15 @@ msgid "Create system user"
msgstr "创建系统用户"
#: assets/templates/assets/_system_user.html:37
#: assets/templates/assets/asset_create.html:14
#: assets/templates/assets/asset_update.html:19
#: assets/templates/assets/asset_create.html:16
#: assets/templates/assets/asset_update.html:21
#: assets/templates/assets/cluster_create_update.html:35
msgid "Basic"
msgstr "基本"
#: assets/templates/assets/_system_user.html:45
#: assets/templates/assets/asset_create.html:24
#: assets/templates/assets/asset_update.html:29
#: assets/templates/assets/asset_create.html:26
#: assets/templates/assets/asset_update.html:31
#: assets/templates/assets/system_user_update.html:7
#: users/templates/users/user_create.html:9
#: users/templates/users/user_update.html:6
@ -647,8 +686,8 @@ msgid "Auto generate key"
msgstr "自动生成秘钥"
#: assets/templates/assets/_system_user.html:65
#: assets/templates/assets/asset_create.html:32
#: assets/templates/assets/asset_update.html:47
#: assets/templates/assets/asset_create.html:61
#: assets/templates/assets/asset_update.html:70
#: assets/templates/assets/cluster_create_update.html:46
#: perms/templates/perms/asset_permission_create_update.html:45
#: terminal/templates/terminal/terminal_update.html:41
@ -658,10 +697,11 @@ msgstr "其它"
#: assets/templates/assets/_system_user.html:71
#: assets/templates/assets/admin_user_create_update.html:45
#: assets/templates/assets/asset_bulk_update.html:23
#: assets/templates/assets/asset_create.html:40
#: assets/templates/assets/asset_create.html:68
#: assets/templates/assets/asset_group_create.html:16
#: assets/templates/assets/asset_update.html:55
#: assets/templates/assets/asset_update.html:78
#: assets/templates/assets/cluster_create_update.html:54
#: assets/templates/assets/label_create_update.html:16
#: common/templates/common/basic_setting.html:58
#: common/templates/common/email_setting.html:59
#: common/templates/common/ldap_setting.html:59
@ -681,11 +721,12 @@ msgstr "重置"
#: assets/templates/assets/_system_user.html:72
#: assets/templates/assets/admin_user_create_update.html:46
#: assets/templates/assets/asset_bulk_update.html:24
#: assets/templates/assets/asset_create.html:41
#: assets/templates/assets/asset_create.html:69
#: assets/templates/assets/asset_group_create.html:17
#: assets/templates/assets/asset_list.html:53
#: assets/templates/assets/asset_update.html:56
#: assets/templates/assets/asset_list.html:61
#: assets/templates/assets/asset_update.html:79
#: assets/templates/assets/cluster_create_update.html:55
#: assets/templates/assets/label_create_update.html:17
#: common/templates/common/basic_setting.html:59
#: common/templates/common/email_setting.html:60
#: common/templates/common/ldap_setting.html:60
@ -730,10 +771,11 @@ msgstr "资产列表"
#: assets/templates/assets/asset_group_detail.html:18
#: assets/templates/assets/asset_group_detail.html:177
#: assets/templates/assets/asset_group_list.html:38
#: assets/templates/assets/asset_list.html:98
#: assets/templates/assets/asset_list.html:106
#: assets/templates/assets/cluster_assets.html:170
#: assets/templates/assets/cluster_detail.html:25
#: assets/templates/assets/cluster_list.html:43
#: assets/templates/assets/label_list.html:38
#: assets/templates/assets/system_user_asset.html:25
#: assets/templates/assets/system_user_detail.html:26
#: assets/templates/assets/system_user_list.html:84
@ -754,16 +796,17 @@ msgstr "更新"
#: assets/templates/assets/asset_detail.html:28
#: assets/templates/assets/asset_group_detail.html:22
#: assets/templates/assets/asset_group_list.html:39
#: assets/templates/assets/asset_list.html:99
#: assets/templates/assets/asset_list.html:107
#: assets/templates/assets/cluster_detail.html:29
#: assets/templates/assets/cluster_list.html:44
#: assets/templates/assets/label_list.html:39
#: assets/templates/assets/system_user_detail.html:30
#: assets/templates/assets/system_user_list.html:85
#: ops/templates/ops/task_list.html:71
#: perms/templates/perms/asset_permission_detail.html:34
#: perms/templates/perms/asset_permission_list.html:74
#: terminal/templates/terminal/terminal_list.html:73
#: users/templates/users/user_detail.html:29
#: users/templates/users/user_detail.html:30
#: users/templates/users/user_group_detail.html:32
#: users/templates/users/user_group_list.html:41
#: users/templates/users/user_list.html:80
@ -788,8 +831,8 @@ msgstr "类型"
#: assets/templates/assets/admin_user_assets.html:63
#: assets/templates/assets/admin_user_list.html:25
#: assets/templates/assets/asset_detail.html:376
#: assets/templates/assets/asset_list.html:36
#: assets/templates/assets/asset_detail.html:403
#: assets/templates/assets/asset_list.html:44
#: assets/templates/assets/system_user_asset.html:55
#: assets/templates/assets/system_user_list.html:27
msgid "Reachable"
@ -831,15 +874,15 @@ msgstr "使用集群管理用户"
#: assets/templates/assets/admin_user_detail.html:101
#: assets/templates/assets/asset_detail.html:230
#: assets/templates/assets/asset_group_list.html:81
#: assets/templates/assets/asset_list.html:220
#: assets/templates/assets/asset_list.html:242
#: assets/templates/assets/cluster_assets.html:104
#: assets/templates/assets/cluster_list.html:89
#: assets/templates/assets/system_user_detail.html:164
#: assets/templates/assets/system_user_list.html:134 templates/_modal.html:16
#: terminal/templates/terminal/session_detail.html:108
#: users/templates/users/user_detail.html:338
#: users/templates/users/user_detail.html:363
#: users/templates/users/user_detail.html:386
#: users/templates/users/user_detail.html:339
#: users/templates/users/user_detail.html:364
#: users/templates/users/user_detail.html:387
#: users/templates/users/user_group_create_update.html:32
#: users/templates/users/user_group_list.html:82
#: users/templates/users/user_list.html:196
@ -862,9 +905,10 @@ msgstr "比例"
#: assets/templates/assets/admin_user_list.html:29
#: assets/templates/assets/asset_group_detail.html:55
#: assets/templates/assets/asset_group_list.html:18
#: assets/templates/assets/asset_list.html:37
#: assets/templates/assets/asset_list.html:45
#: assets/templates/assets/cluster_assets.html:56
#: assets/templates/assets/cluster_list.html:23
#: assets/templates/assets/label_list.html:17
#: assets/templates/assets/system_user_list.html:31
#: ops/templates/ops/adhoc_history.html:59 ops/templates/ops/task_adhoc.html:61
#: ops/templates/ops/task_history.html:62 ops/templates/ops/task_list.html:41
@ -876,12 +920,12 @@ msgstr "比例"
msgid "Action"
msgstr "动作"
#: assets/templates/assets/asset_create.html:28
#: assets/templates/assets/asset_update.html:33
#: assets/templates/assets/asset_create.html:30
#: assets/templates/assets/asset_update.html:35
msgid "Group"
msgstr "组"
#: assets/templates/assets/asset_detail.html:20 assets/views/asset.py:186
#: assets/templates/assets/asset_detail.html:20 assets/views/asset.py:188
#: assets/views/cluster.py:98
msgid "Asset detail"
msgstr "资产详情"
@ -899,26 +943,26 @@ msgid "Disk"
msgstr "硬盘"
#: assets/templates/assets/asset_detail.html:153
#: users/templates/users/user_detail.html:102
#: users/templates/users/user_detail.html:103
#: users/templates/users/user_profile.html:88
msgid "Date joined"
msgstr "创建日期"
#: assets/templates/assets/asset_detail.html:169
#: terminal/templates/terminal/session_detail.html:81
#: users/templates/users/user_detail.html:121
#: users/templates/users/user_detail.html:122
#: users/templates/users/user_profile.html:130
msgid "Quick modify"
msgstr "快速修改"
#: assets/templates/assets/asset_detail.html:175
#: assets/templates/assets/asset_list.html:35
#: assets/templates/assets/asset_list.html:43
#: assets/templates/assets/user_asset_list.html:25 perms/models.py:20
#: perms/templates/perms/asset_permission_create_update.html:47
#: perms/templates/perms/asset_permission_detail.html:116
#: terminal/templates/terminal/terminal_list.html:34
#: users/templates/users/_select_user_modal.html:18
#: users/templates/users/user_detail.html:127
#: users/templates/users/user_detail.html:128
#: users/templates/users/user_list.html:27
#: users/templates/users/user_profile.html:63
msgid "Active"
@ -936,8 +980,8 @@ msgstr "刷新"
msgid "Join asset groups"
msgstr "添加到资产组"
#: assets/templates/assets/asset_detail.html:318
#: users/templates/users/user_detail.html:272
#: assets/templates/assets/asset_detail.html:345
#: users/templates/users/user_detail.html:273
msgid "Update successfully!"
msgstr "更新成功"
@ -974,11 +1018,11 @@ msgid "Create asset group"
msgstr "创建资产组"
#: assets/templates/assets/asset_group_list.html:76
#: assets/templates/assets/asset_list.html:215
#: assets/templates/assets/asset_list.html:237
#: assets/templates/assets/cluster_list.html:84
#: assets/templates/assets/system_user_list.html:129
#: users/templates/users/user_detail.html:333
#: users/templates/users/user_detail.html:358
#: users/templates/users/user_detail.html:334
#: users/templates/users/user_detail.html:359
#: users/templates/users/user_group_list.html:77
#: users/templates/users/user_list.html:191
msgid "Are you sure?"
@ -1020,59 +1064,63 @@ msgstr "导入"
msgid "Export"
msgstr "导出"
#: assets/templates/assets/asset_list.html:25 assets/views/asset.py:85
#: assets/templates/assets/asset_list.html:25 assets/views/asset.py:87
msgid "Create asset"
msgstr "创建资产"
#: assets/templates/assets/asset_list.html:34
#: assets/templates/assets/asset_list.html:27 templates/_nav.html:27
msgid "Label"
msgstr "标签"
#: assets/templates/assets/asset_list.html:42
#: assets/templates/assets/user_asset_list.html:24
msgid "Hardware"
msgstr "硬件"
#: assets/templates/assets/asset_list.html:46
#: assets/templates/assets/asset_list.html:54
#: users/templates/users/user_list.html:37
msgid "Delete selected"
msgstr "批量删除"
#: assets/templates/assets/asset_list.html:47
#: assets/templates/assets/asset_list.html:55
#: users/templates/users/user_list.html:38
msgid "Update selected"
msgstr "批量更新"
#: assets/templates/assets/asset_list.html:48
#: assets/templates/assets/asset_list.html:56
#: users/templates/users/user_list.html:39
msgid "Deactive selected"
msgstr "禁用所选"
#: assets/templates/assets/asset_list.html:49
#: assets/templates/assets/asset_list.html:57
#: users/templates/users/user_list.html:40
msgid "Active selected"
msgstr "激活所选"
#: assets/templates/assets/asset_list.html:216
#: assets/templates/assets/asset_list.html:238
msgid "This will delete the selected assets !!!"
msgstr "删除选择资产"
# msgid "Deleted!"
# msgstr "删除"
#: assets/templates/assets/asset_list.html:224
#: assets/templates/assets/asset_list.html:246
msgid "Asset Deleted."
msgstr "已被删除"
#: assets/templates/assets/asset_list.html:225
#: assets/templates/assets/asset_list.html:230
#: assets/templates/assets/asset_list.html:247
#: assets/templates/assets/asset_list.html:252
msgid "Asset Delete"
msgstr "删除"
#: assets/templates/assets/asset_list.html:229
#: assets/templates/assets/asset_list.html:251
msgid "Asset Deleting failed."
msgstr "删除失败"
#: assets/templates/assets/asset_update.html:37
#: assets/templates/assets/asset_update.html:60
msgid "Configuration"
msgstr "配置"
#: assets/templates/assets/asset_update.html:42
#: assets/templates/assets/asset_update.html:65
msgid "Location"
msgstr "位置"
@ -1147,6 +1195,10 @@ msgstr "确认删除"
msgid "Are you sure delete"
msgstr "您确定删除吗?"
#: assets/templates/assets/label_list.html:6 assets/views/label.py:43
msgid "Create label"
msgstr "创建标签"
#: assets/templates/assets/system_user_asset.html:33
msgid "Assets of "
msgstr "资产"
@ -1220,19 +1272,19 @@ msgstr "更新管理用户"
msgid "Admin user detail"
msgstr "管理用户详情"
#: assets/views/asset.py:49 assets/views/asset.py:62
#: assets/views/asset.py:49 assets/views/asset.py:63
msgid "Asset list"
msgstr "资产列表"
#: assets/views/asset.py:145
#: assets/views/asset.py:147
msgid "Bulk update asset"
msgstr "批量更新资产"
#: assets/views/asset.py:162
#: assets/views/asset.py:164
msgid "Update asset"
msgstr "编辑资产"
#: assets/views/asset.py:298
#: assets/views/asset.py:300
msgid "already exists"
msgstr "已经存在"
@ -1261,6 +1313,14 @@ msgstr "资产组列表"
msgid "Asset group detail"
msgstr "资产组详情"
#: assets/views/label.py:27
msgid "Label list"
msgstr "标签列表"
#: assets/views/label.py:59
msgid "Update label"
msgstr "编辑标签"
#: assets/views/system_user.py:29
msgid "System user list"
msgstr "系统用户列表"
@ -1296,14 +1356,12 @@ msgid "<b>%(name)s</b> was updated successfully"
msgstr "<b>%(name)s</b> 更新成功"
#: common/fields.py:25
#, fuzzy
#| msgid "Not a valid ssh public key"
msgid "Not a valid json"
msgstr "ssh密钥不合法"
msgstr "不是合法json"
#: common/fields.py:27
msgid "Not a string type"
msgstr ""
msgstr "不是字符类型"
#: common/forms.py:70
msgid "Current SITE URL"
@ -1416,10 +1474,6 @@ msgstr ""
msgid "discard time"
msgstr ""
#: common/models.py:27
msgid "Value"
msgstr "值"
#: common/models.py:29
msgid "Enabled"
msgstr "启用"
@ -1459,7 +1513,7 @@ msgid "Test connection"
msgstr "测试连接"
#: common/views.py:20 common/views.py:46 common/views.py:72 common/views.py:101
#: templates/_nav.html:69
#: templates/_nav.html:68
msgid "Settings"
msgstr "系统设置"
@ -1735,19 +1789,6 @@ msgstr "执行历史"
msgid "Select users"
msgstr "选择用户"
#: perms/forms.py:18 perms/models.py:15
#: perms/templates/perms/asset_permission_create_update.html:36
#: perms/templates/perms/asset_permission_list.html:26 templates/_nav.html:12
#: terminal/backends/command/models.py:10 terminal/models.py:115
#: terminal/templates/terminal/command_list.html:32
#: terminal/templates/terminal/command_list.html:72
#: terminal/templates/terminal/session_list.html:33
#: terminal/templates/terminal/session_list.html:71 users/forms.py:190
#: users/models/user.py:30 users/templates/users/user_group_detail.html:78
#: users/views/user.py:337
msgid "User"
msgstr "用户"
#: perms/forms.py:31 perms/templates/perms/asset_permission_user.html:116
msgid "Select user groups"
msgstr "选择用户组"
@ -1772,13 +1813,13 @@ msgstr "资产 {}(组 {}) 所在集群 {} 不包含系统用户 [{}] 请检查\n
#: perms/models.py:16 perms/templates/perms/asset_permission_list.html:27
#: templates/_nav.html:13 users/models/user.py:37
#: users/templates/users/_select_user_modal.html:16
#: users/templates/users/user_detail.html:178
#: users/templates/users/user_detail.html:179
#: users/templates/users/user_list.html:26
msgid "User group"
msgstr "用户组"
#: perms/models.py:21 perms/templates/perms/asset_permission_detail.html:86
#: users/models/user.py:49 users/templates/users/user_detail.html:94
#: users/models/user.py:49 users/templates/users/user_detail.html:95
#: users/templates/users/user_profile.html:96
msgid "Date expired"
msgstr "失效日期"
@ -1804,7 +1845,7 @@ msgid "Add asset group to this permission"
msgstr "添加资产组"
#: perms/templates/perms/asset_permission_asset.html:125
#: users/templates/users/user_detail.html:195
#: users/templates/users/user_detail.html:196
msgid "Join"
msgstr "加入"
@ -1859,7 +1900,7 @@ msgid "Add user group to asset permission"
msgstr "添加用户组"
#: perms/views.py:28 perms/views.py:44 perms/views.py:60 perms/views.py:74
#: perms/views.py:111 perms/views.py:141 templates/_nav.html:30
#: perms/views.py:111 perms/views.py:141 templates/_nav.html:31
msgid "Perms"
msgstr "权限管理"
@ -1964,20 +2005,27 @@ msgstr "用户管理"
msgid "Login logs"
msgstr "登录日志"
#: templates/_nav.html:33
#: templates/_nav.html:34
msgid "Asset permission"
msgstr "资产授权"
#: templates/_nav.html:39
msgid "Job Center"
msgstr "作业中心"
#: templates/_nav.html:40
msgid "Sessions"
msgstr "会话"
#: templates/_nav.html:42
msgid "Task"
msgstr "任务"
#: templates/_nav.html:43
msgid "Session online"
msgstr "在线会话"
#: templates/_nav.html:47 templates/_nav.html:50
#: terminal/templates/terminal/session_list.html:75
#: templates/_nav.html:44
msgid "Session offline"
msgstr "离线会话"
#: templates/_nav.html:45
msgid "Commands"
msgstr "命令记录"
#: templates/_nav.html:46 terminal/templates/terminal/session_list.html:75
#: terminal/views/command.py:47 terminal/views/session.py:75
#: terminal/views/session.py:92 terminal/views/session.py:114
#: terminal/views/terminal.py:31 terminal/views/terminal.py:46
@ -1986,20 +2034,12 @@ msgid "Terminal"
msgstr "终端管理"
#: templates/_nav.html:51
msgid "Session online"
msgstr "在线会话"
msgid "Job Center"
msgstr "作业中心"
#: templates/_nav.html:52
msgid "Session offline"
msgstr "离线会话"
#: templates/_nav.html:53 terminal/models.py:122
#: terminal/templates/terminal/command_list.html:55
#: terminal/templates/terminal/command_list.html:71
#: terminal/templates/terminal/session_detail.html:48
#: terminal/templates/terminal/session_list.html:76
msgid "Command"
msgstr "命令"
#: templates/_nav.html:54
msgid "Task"
msgstr "任务"
#: templates/_nav_user.html:4
msgid "My assets"
@ -2031,6 +2071,7 @@ msgstr "输出"
#: terminal/backends/command/models.py:15
#: terminal/templates/terminal/command_list.html:75
#: terminal/templates/terminal/terminal_list.html:33
msgid "Session"
msgstr "会话"
@ -2091,6 +2132,13 @@ msgstr "远端地址"
msgid "Replay"
msgstr "回放"
#: terminal/models.py:122 terminal/templates/terminal/command_list.html:55
#: terminal/templates/terminal/command_list.html:71
#: terminal/templates/terminal/session_detail.html:48
#: terminal/templates/terminal/session_list.html:76
msgid "Command"
msgstr "命令"
#: terminal/models.py:125
msgid "Date end"
msgstr "结束日期"
@ -2169,10 +2217,6 @@ msgstr "HTTP端口"
msgid "Addr"
msgstr "地址"
#: terminal/templates/terminal/terminal_list.html:33
msgid "Sessions"
msgstr "会话"
#: terminal/templates/terminal/terminal_list.html:76
msgid "Accept"
msgstr "接受"
@ -2269,7 +2313,7 @@ msgstr ""
msgid "Invalid token or cache refreshed."
msgstr ""
#: users/forms.py:43 users/templates/users/user_detail.html:186
#: users/forms.py:43 users/templates/users/user_detail.html:187
msgid "Join user groups"
msgstr "添加到用户组"
@ -2345,13 +2389,13 @@ msgstr "管理员"
msgid "Application"
msgstr "应用程序"
#: users/models/user.py:36 users/templates/users/user_detail.html:70
#: users/models/user.py:36 users/templates/users/user_detail.html:71
#: users/templates/users/user_profile.html:59
msgid "Email"
msgstr "邮件"
#: users/models/user.py:38 users/templates/users/_select_user_modal.html:15
#: users/templates/users/user_detail.html:86
#: users/templates/users/user_detail.html:87
#: users/templates/users/user_list.html:25
#: users/templates/users/user_profile.html:55
msgid "Role"
@ -2361,7 +2405,7 @@ msgstr "角色"
msgid "Avatar"
msgstr "头像"
#: users/models/user.py:40 users/templates/users/user_detail.html:81
#: users/models/user.py:40 users/templates/users/user_detail.html:82
msgid "Wechat"
msgstr "微信"
@ -2464,7 +2508,7 @@ msgid "City"
msgstr "城市"
#: users/templates/users/reset_password.html:45
#: users/templates/users/user_detail.html:324
#: users/templates/users/user_detail.html:325
#: users/templates/users/user_profile.html:136 users/utils.py:68
msgid "Reset password"
msgstr "重置密码"
@ -2495,54 +2539,54 @@ msgstr "用户详情"
msgid "Asset granted"
msgstr "授权的资产"
#: users/templates/users/user_detail.html:106
#: users/templates/users/user_detail.html:107
#: users/templates/users/user_profile.html:92
msgid "Last login"
msgstr "最后登录"
#: users/templates/users/user_detail.html:156
#: users/templates/users/user_detail.html:157
msgid "Send reset password mail"
msgstr "发送重置密码邮件"
#: users/templates/users/user_detail.html:159
#: users/templates/users/user_detail.html:167
#: users/templates/users/user_detail.html:160
#: users/templates/users/user_detail.html:168
msgid "Send"
msgstr "发送"
#: users/templates/users/user_detail.html:164
#: users/templates/users/user_detail.html:165
msgid "Send reset ssh key mail"
msgstr "发送重置密钥邮件"
#: users/templates/users/user_detail.html:323
#: users/templates/users/user_detail.html:324
msgid "An e-mail has been sent to the user\\'s mailbox."
msgstr "已发送邮件到用户邮箱"
#: users/templates/users/user_detail.html:334
#: users/templates/users/user_detail.html:335
msgid "This will reset the user password and send a reset mail"
msgstr "将失效用户当前密码,并发送重设密码邮件到用户邮箱"
#: users/templates/users/user_detail.html:348
#: users/templates/users/user_detail.html:349
msgid ""
"The reset-ssh-public-key E-mail has been sent successfully. Please inform "
"the user to update his new ssh public key."
msgstr "重设秘钥邮件将会发送到用户邮箱"
#: users/templates/users/user_detail.html:349
#: users/templates/users/user_detail.html:350
#: users/templates/users/user_profile.html:144
msgid "Reset SSH public key"
msgstr "重置SSH密钥"
#: users/templates/users/user_detail.html:359
#: users/templates/users/user_detail.html:360
msgid "This will reset the user public key and send a reset mail"
msgstr "将会失效用户当前秘钥,并发送重置邮件到用户邮箱"
#: users/templates/users/user_detail.html:376
#: users/templates/users/user_detail.html:377
#: users/templates/users/user_profile.html:170
msgid "Successfully updated the SSH public key."
msgstr "更新ssh密钥成功"
#: users/templates/users/user_detail.html:377
#: users/templates/users/user_detail.html:381
#: users/templates/users/user_detail.html:378
#: users/templates/users/user_detail.html:382
#: users/templates/users/user_profile.html:171
#: users/templates/users/user_profile.html:176
msgid "User SSH public key update"
@ -2856,6 +2900,9 @@ msgstr "密码更新"
msgid "Public key update"
msgstr "秘钥更新"
#~ msgid "Default using cluster admin user"
#~ msgstr "默认使用管理用户"
#~ msgid "Add command storage"
#~ msgstr "添加命令存储"

View File

@ -338,4 +338,6 @@ div.dataTables_wrapper div.dataTables_filter {
.nav.nav-tabs li.active a {
border: none;
}
}

View File

@ -383,7 +383,22 @@ jumpserver.initServerSideDataTable = function (options) {
}
if (data.search !== null) {
var search_val = data.search.value;
data.search = search_val;
var search_list = search_val.split(" ");
var search_attr = {};
var search_raw = [];
search_list.map(function (val, index) {
var kv = val.split(":");
if (kv.length === 2) {
search_attr[kv[0]] = kv[1]
} else {
search_raw.push(kv)
}
});
data.search = search_raw.join("");
$.each(search_attr, function (k, v) {
data[k] = v
})
}
if (data.order !== null && data.order.length === 1) {
var col = data.order[0].column;
@ -446,6 +461,7 @@ jumpserver.initServerSideDataTable = function (options) {
}
});
jumpserver.table = table;
return table;
};

View File

@ -24,6 +24,7 @@
<li id="cluster"><a href="{% url 'assets:cluster-list' %}">{% trans 'Cluster' %}</a></li>
<li id="admin-user"><a href="{% url 'assets:admin-user-list' %}">{% trans 'Admin user' %}</a></li>
<li id="system-user"><a href="{% url 'assets:system-user-list' %}">{% trans 'System user' %}</a></li>
<li id="label"><a href="{% url 'assets:label-list' %}">{% trans 'Labels' %}</a></li>
</ul>
</li>
<li id="perms">
@ -36,13 +37,13 @@
</li>
<li id="terminal">
<a>
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Terminal' %}</span><span class="fa arrow"></span>
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Sessions' %}</span><span class="fa arrow"></span>
</a>
<ul class="nav nav-second-level">
<li id="terminal"><a href="{% url 'terminal:terminal-list' %}">{% trans 'Terminal' %}</a></li>
<li id="session-online"><a href="{% url 'terminal:session-online-list' %}">{% trans 'Session online' %}</a></li>
<li id="session-offline"><a href="{% url 'terminal:session-offline-list' %}">{% trans 'Session offline' %}</a></li>
<li id="command"><a href="{% url 'terminal:command-list' %}">{% trans 'Command' %}</a></li>
<li id="command"><a href="{% url 'terminal:command-list' %}">{% trans 'Commands' %}</a></li>
<li id="terminal"><a href="{% url 'terminal:terminal-list' %}">{% trans 'Terminal' %}</a></li>
</ul>
</li>
<li id="ops">

View File

@ -30,7 +30,7 @@
<th class="text-center">{% trans 'Addr' %}</th>
<th class="text-center">{% trans 'SSH port' %}</th>
<th class="text-center">{% trans 'Http port' %}</th>
<th class="text-center">{% trans 'Sessions' %}</th>
<th class="text-center">{% trans 'Session' %}</th>
<th class="text-center">{% trans 'Active' %}</th>
<th class="text-center">{% trans 'Alive' %}</th>
<th class="text-center">{% trans 'Action' %}</th>

View File

@ -129,7 +129,7 @@
<td><span class="pull-right">
<div class="switch">
<div class="onoffswitch">
<input type="checkbox" {% if user_object.is_active %} checked {% endif %} {% if request.user == user_object %} disabled="disabled" {% endif %} class="onoffswitch-checkbox disabled" id="is_active">
<input type="checkbox" {% if user_object.is_active %} checked {% endif %} {% if request.user == user_object %} disabled {% endif %} class="onoffswitch-checkbox" id="is_active">
<label class="onoffswitch-label" for="is_active">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>