Commit 2268fc5b authored by BaiJiangJie's avatar BaiJiangJie

[Feature] 应用授权: DatabasePermission 添加用户页面Database ViewAPI

parent 57a805e0
# coding: utf-8
#
from rest_framework import serializers
from common.serializers import AdaptedBulkListSerializer
from orgs.mixins import BulkOrgResourceModelSerializer
from ..models import Database
......@@ -9,6 +11,9 @@ __all__ = ['DatabaseSerializer']
class DatabaseSerializer(BulkOrgResourceModelSerializer):
type_display = serializers.ReadOnlyField(source='get_type_display')
login_mode_display = serializers.ReadOnlyField(source='get_login_mode_display')
class Meta:
model = Database
list_serializer_class = AdaptedBulkListSerializer
......@@ -16,6 +21,7 @@ class DatabaseSerializer(BulkOrgResourceModelSerializer):
'id', 'name', 'login_mode', 'type', 'host', 'port', 'user',
'password', 'database', 'created_by', 'date_created',
'date_updated', 'comment',
'type_display', 'login_mode_display'
]
read_only_fields = [
......
......@@ -55,11 +55,11 @@
</tr>
<tr>
<td>{% trans 'Login mode' %}:</td>
<td><b>{{ database.login_mode }}</b></td>
<td><b>{{ database.get_login_mode_display }}</b></td>
</tr>
<tr>
<td>{% trans 'Type' %}:</td>
<td><b>{{ database.type }}</b></td>
<td><b>{{ database.get_type_display }}</b></td>
</tr>
<tr>
<td>{% trans 'Host' %}:</td>
......
......@@ -39,6 +39,28 @@ function initTable() {
var detail_btn = '<a href="{{ the_url }}">' + cellData + '</a>';
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id));
}},
{targets: 2, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.login_mode_display)
}},
{targets: 3, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.type_display)
}},
{targets: 4, createdCell: function (td, cellData, rowData) {
var host = htmlEscape(cellData);
$(td).html(host);
}},
{targets: 6, createdCell: function (td, cellData, rowData) {
var user = htmlEscape(cellData);
$(td).html(user);
}},
{targets: 7, createdCell: function (td, cellData, rowData) {
var database = htmlEscape(cellData);
$(td).html(database);
}},
{targets: 8, createdCell: function (td, cellData, rowData) {
var comment = htmlEscape(cellData);
$(td).html(comment);
}},
{targets: 9, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "applications:database-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-delete" data-rid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
......@@ -55,8 +77,8 @@ function initTable() {
{data: "port"},
{data: "user"},
{data: "database"},
{data: "comment"},
{data: "id"}
{data: "comment", orderable: false},
{data: "id", orderable: false}
],
op_html: $('#actions').html()
};
......
{% extends 'base.html' %}
{% load i18n static %}
{% block custom_head_css_js %}
<script src="{% static 'js/jquery.form.min.js' %}"></script>
{% endblock %}
{% block content %}
<div class="mail-box-header">
<table class="table table-striped table-bordered table-hover " id="database_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 'Login mode' %}</th>
<th class="text-center">{% trans 'Type' %}</th>
<th class="text-center">{% trans 'Host' %}</th>
<th class="text-center">{% trans 'Port' %}</th>
<th class="text-center">{% trans 'User' %}</th>
<th class="text-center">{% trans 'Database' %}</th>
<th class="text-center">{% trans 'Comment' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
var inited = false;
var database_table, url;
function initTable() {
if (inited){
return
} else {
inited = true;
}
url = '{% url "api-perms:my-databases" %}';
var options = {
ele: $('#database_list_table'),
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var name = htmlEscape(cellData);
$(td).html(name)
}},
{targets: 2, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.login_mode_display)
}},
{targets: 3, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.type_display)
}},
{targets: 4, createdCell: function (td, cellData, rowData) {
var host = htmlEscape(cellData);
$(td).html(host);
}},
{targets: 6, createdCell: function (td, cellData, rowData) {
var user = htmlEscape(cellData);
$(td).html(user);
}},
{targets: 7, createdCell: function (td, cellData, rowData) {
var database = htmlEscape(cellData);
$(td).html(database);
}},
{targets: 8, createdCell: function (td, cellData, rowData) {
var comment = htmlEscape(cellData);
$(td).html(comment);
}},
{targets: 9, createdCell: function (td, cellData, rowData) {
var conn_btn = '<a href="{% url "luna-view" %}?login_to=' + cellData +'" class="btn btn-xs btn-primary">{% trans "Connect" %}</a>'.replace("{{ DEFAULT_PK }}", cellData);
$(td).html(conn_btn)
}}
],
ajax_url: url,
columns: [
{data: "id"},
{data: "name"},
{data: "login_mode"},
{data: "type"},
{data: "host"},
{data: "port"},
{data: "user"},
{data: "database"},
{data: "comment", orderable: false},
{data: "id", orderable: false}
]
};
database_table = jumpserver.initServerSideDataTable(options);
return database_table
}
$(document).ready(function(){
initTable();
})
</script>
{% endblock %}
......@@ -16,6 +16,11 @@
<i class="" style="width: 14px"></i><span class="nav-label">{% trans 'RemoteApp' %}</span><span class="label label-info pull-right"></span>
</a>
</li>
<li id="user-database">
<a href="{% url 'applications:user-database-list' %}">
<i class="" style="width: 14px"></i><span class="nav-label">{% trans 'Database' %}</span><span class="label label-info pull-right"></span>
</a>
</li>
</ul>
</li>
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment