Commit 367ebebf authored by ibuler's avatar ibuler

Merge branch 'dev' into api_key

parents fe2840ed 74ae8636
......@@ -14,13 +14,14 @@ __all__ = [
class NodeSerializer(BulkOrgResourceModelSerializer):
assets_amount = serializers.IntegerField(read_only=True)
name = serializers.ReadOnlyField(source='value')
class Meta:
model = Node
only_fields = ['id', 'key', 'value', 'org_id']
fields = only_fields + ['assets_amount']
fields = only_fields + ['name', 'assets_amount']
read_only_fields = [
'key', 'assets_amount', 'org_id',
'key', 'name', 'assets_amount', 'org_id',
]
def validate_value(self, data):
......
......@@ -51,8 +51,7 @@ function initAssetUserTable() {
} else {
innerHtml = '<i class="fa fa-circle text-warning"></i>'
}
var date = new Date(cellData.datetime);
var dateManual = date.toLocaleString();
var dateManual = toSafeLocalDateStr(cellData.datetime);
var dataContent = testDatetime + dateManual;
innerHtml = "<a data-toggle='popover' data-content='" + dataContent + "'" + 'data-placement="auto bottom"' + ">" + innerHtml + "</a>";
$(td).html(innerHtml);
......@@ -60,7 +59,7 @@ function initAssetUserTable() {
},
{
targets: 6, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData);
var data = toSafeLocalDateStr(cellData);
$(td).html(data);
},
},
......
......@@ -159,8 +159,7 @@ function initTable() {
} else {
innerHtml = '<i class="fa fa-circle text-warning"></i>'
}
var date = new Date(cellData.datetime);
var dateManual = date.toLocaleString();
var dateManual = toSafeLocalDateStr(cellData.datetime);
var dataContent = testDatetime + dateManual;
innerHtml = "<a data-toggle='popover' data-content='" + dataContent + "'" + 'data-placement="auto bottom"' + ">" + innerHtml + "</a>";
$(td).html(innerHtml);
......
......@@ -23,7 +23,7 @@
<script>
var treeUrl = "{% url 'api-perms:my-nodes-as-tree' %}?&cache_policy=1";
var assetTableUrl = "{% url 'api-perms:my-assets' %}?cache_policy=1";
var selectUrl = '{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var showAssetHref = false; // Need input default true
var actions = {
targets: 4, createdCell: function (td, cellData) {
......
......@@ -82,7 +82,7 @@ function initTable() {
select: [],
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var d = new Date(cellData);
var d = toSafeLocalDateStr(cellData);
$(td).html(d);
}},
{targets: 2, createdCell: function (td, cellData) {
......
......@@ -109,8 +109,8 @@ $(document).ready(function () {
}
}},
{targets: 6, createdCell: function (td, cellData) {
var d = new Date(cellData);
$(td).html(d.toLocaleString())
var d = toSafeLocalDateStr(cellData);
$(td).html(d)
}},
{targets: 7, createdCell: function (td, cellData, rowData) {
var detail_btn = '<a class="btn btn-xs btn-primary m-l-xs btn-run" href="{% url 'ops:adhoc-detail' pk=DEFAULT_PK %}">{% trans "Detail" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
......
......@@ -88,8 +88,9 @@ function initTable() {
select: [],
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var d = new Date(cellData);
$(td).html(d.toLocaleString());
var d = toSafeLocalDateStr(cellData);
$(td).html(d);
}},
{targets: 2, createdCell: function (td, cellData) {
var total = "<span>" + cellData.total + "</span>";
......
......@@ -88,13 +88,18 @@ class UserGrantedNodeAssetsApi(UserPermissionCacheMixin, GrantAssetsMixin, ListA
def get_queryset(self):
user = self.get_object()
query_all = self.request.query_params.get("all", "0") == "1"
self.util = AssetPermissionUtil(user, cache_policy=self.cache_policy)
key = self.get_node_key()
nodes_items = self.util.get_nodes_with_assets()
assets_system_users = {}
if query_all:
k = "all_assets"
else:
k = "assets"
for item in nodes_items:
if item["key"] == key:
assets_system_users = item["assets"]
assets_system_users = item[k]
break
assets = []
for asset_id, system_users in assets_system_users.items():
......
......@@ -103,9 +103,9 @@ class Migration(migrations.Migration):
name='nodes',
field=models.ManyToManyField(blank=True, related_name='granted_by_permissions', to='assets.Node', verbose_name='Nodes'),
),
migrations.RunPython(
code=migrate_node_permissions,
),
# migrations.RunPython(
# code=migrate_node_permissions,
# ),
migrations.RunPython(
code=migrate_system_assets_relation,
),
......
......@@ -44,7 +44,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
model = Asset
only_fields = [
"id", "hostname", "ip", "protocols", "os", 'domain',
"platform", "org_id",
"platform", "comment", "org_id",
]
fields = only_fields + ['system_users_granted', 'system_users_join', "org_name"]
read_only_fields = fields
......
......@@ -203,14 +203,16 @@ class GenerateTree:
nodes = []
for key, values in nodes_with_assets_amount.items():
assets = {asset_id: self.assets.get(asset_id) for asset_id in values["assets"]}
all_assets = {asset_id: self.assets.get(asset_id) for asset_id in values["all_assets"]}
nodes.append({
"key": key, "assets": assets,
"key": key, "assets": assets, "all_assets": all_assets,
"assets_amount": values["assets_amount"]
})
# 如果返回空节点,页面构造授权资产树报错
if not nodes:
nodes.append({
"key": const.EMPTY_NODE_KEY, "assets": {}, "assets_amount": 0
"key": const.EMPTY_NODE_KEY, "assets": {}, "assets_amount": 0,
"all_assets": {},
})
nodes.sort(key=lambda n: self.key_sort(n["key"]))
self._nodes_with_assets = nodes
......
......@@ -40,8 +40,8 @@ class BaseForm(forms.Form):
field = self.fields[name]
if isinstance(field.widget, forms.PasswordInput) and not value:
continue
if value == getattr(settings, name):
continue
# if value == getattr(settings, name):
# continue
encrypted = True if isinstance(field, FormEncryptMixin) else False
try:
......
......@@ -305,7 +305,6 @@ function requestApi(props) {
toastr.error(msg);
}
if (typeof props.error === 'function') {
console.log(jqXHR);
return props.error(jqXHR.responseText, jqXHR.status);
}
});
......@@ -610,7 +609,6 @@ jumpserver.initServerSideDataTable = function (options) {
if (kv.length === 2) {
var value = kv[1];
value = value.replace("+", " ");
console.log(value);
search_attr[kv[0]] = value
} else {
search_raw.push(kv)
......@@ -654,8 +652,6 @@ jumpserver.initServerSideDataTable = function (options) {
$.each(rows, function (id, row) {
table.selected_rows.push(row);
if (row.id && $.inArray(row.id, table.selected) === -1){
console.log(table)
console.log(table.selected);
table.selected.push(row.id)
}
})
......@@ -1095,7 +1091,7 @@ function objectAttrsIsList(obj, attrs) {
function objectAttrsIsDatetime(obj, attrs) {
attrs.forEach(function (attr) {
obj[attr] = new Date(obj[attr]).toISOString();
obj[attr] = toSafeDateISOStr(obj[attr]);
})
}
......@@ -1109,21 +1105,38 @@ function objectAttrsIsBool(obj, attrs) {
})
}
function cleanDate(d) {
if (typeof d === 'number'){return d}
for (var i=0; i<2; i++) {
if (isNaN(Date.parse(d))) {
d = d.split('+')[0].trimRight();
} else {
return d
function cleanDateStr(d) {
for (var i=0;i<3;i++) {
if (!isNaN(Date.parse(d))){
return d;
}
if (!isNaN(Number(d))) {
return d;
}
switch (i) {
case 0:
d = d.replaceAll('-', '/');
break;
case 1:
d = d.split('+')[0].trimRight();
break;
}
}
return ''
return null;
}
function safeDate(s) {
s = cleanDateStr(s);
return new Date(s)
}
function toSafeDateISOStr(s) {
var d = safeDate(s);
return d.toISOString();
}
function formatDateAsCN(d) {
d = cleanDate(d);
var date = new Date(d);
function toSafeLocalDateStr(d) {
var date = safeDate(d);
var date_s = date.toLocaleString(navigator.language, {hour12: false});
return date_s.split("/").join('-')
}
......@@ -1144,17 +1157,15 @@ function getTimeUnits(u) {
"m": "分",
"s": "秒",
};
if (navigator.language || "zh-CN") {
if (navigator.language === "zh-CN") {
return units[u]
}
return u
}
function timeOffset(a, b) {
a = cleanDate(a);
b = cleanDate(b);
var start = new Date(a);
var end = new Date(b);
var start = safeDate(a);
var end = safeDate(b);
var offset = (end - start)/1000;
var days = offset / 3600 / 24;
......@@ -1179,7 +1190,6 @@ function readFile(ref) {
var hasFile = files && files.length > 0;
if (hasFile) {
var reader = new FileReader();//新建一个FileReader
console.log(typeof files[0]);
reader.readAsText(files[0], "UTF-8");//读取文件
reader.onload = function(evt){ //读取完文件之后会回来这里
ref.trigger("onload", evt.target.result);
......
......@@ -7,7 +7,7 @@
<script src="{% static "js/plugins/toastr/toastr.min.js" %}"></script>
<script src="{% static "js/inspinia.js" %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script src="{% static "js/jumpserver.js" %}?v=1"></script>
<script src="{% static "js/jumpserver.js" %}?v=2"></script>
<script>
activeNav();
$(document).ready(function(){
......
......@@ -89,14 +89,16 @@ $(document).ready(function () {
language: navigator.language || "en",
};
dateFromRef.datepicker(options).on("changeDate", function () {
var date = new Date($(this).val() + ' 0:0:0');
var value = $(this).val() + ' 0:0:0';
var date = safeDate(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_from", date.getTime()/1000);
table.ajax.url(url);
table.ajax.reload();
});
dateToRef.datepicker(options).on("changeDate", function () {
var date = new Date($(this).val() + ' 23:59:59');
var value = $(this).val() + ' 23:59:59';
var date = safeDate(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_to", date.getTime()/1000);
table.ajax.url(url);
......@@ -191,7 +193,7 @@ function initTable() {
$(td).html(data);
}},
{targets: 6, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData*1000);
var data = toSafeLocalDateStr(cellData*1000);
$(td).html(data);
}},
],
......
......@@ -104,8 +104,8 @@ var dateFrom = "{{ date_from.timestamp }}";
var dateTo = "{{ date_to.timestamp }}";
function initTable() {
dateFrom = new Date(dateFrom * 1000).toISOString();
dateTo = new Date(dateTo * 1000).toISOString();
dateFrom = toSafeDateISOStr(dateFrom * 1000);
dateTo = toSafeDateISOStr(dateTo * 1000);
sessionListUrl = setUrlParam(sessionListUrl, "date_from", dateFrom);
sessionListUrl = setUrlParam(sessionListUrl, "date_to", dateTo);
var options = {
......@@ -121,7 +121,7 @@ function initTable() {
$(td).html(data);
}},
{targets: 9, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData);
var data = toSafeLocalDateStr(cellData);
$(td).html(data);
}},
{targets: 10, createdCell: function (td, cellData, rowData) {
......@@ -201,9 +201,9 @@ $(document).ready(function() {
return
}
var value = $(this).val() + ' 0:0:0';
var date = new Date(value);
var date = toSafeDateISOStr(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_from", date.toISOString());
url = setUrlParam(url, "date_from", date);
table.ajax.url(url);
table.ajax.reload();
});
......@@ -212,9 +212,9 @@ $(document).ready(function() {
return
}
var value = $(this).val() + ' 23:59:59';
var date = new Date(value);
var date = toSafeDateISOStr(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_to", date.toISOString());
url = setUrlParam(url, "date_to", date);
table.ajax.url(url);
table.ajax.reload();
});
......
......@@ -33,7 +33,7 @@
{% block custom_foot_js %}
<script>
var assetTableUrl = "{% url 'api-perms:user-assets' pk=object.id %}?cache_policy=1";
var selectUrl = '{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var treeUrl = "{% url 'api-perms:user-nodes-as-tree' pk=object.id %}?&cache_policy=1";
$(document).ready(function () {
......
......@@ -35,7 +35,7 @@
<script>
var treeUrl = "{% url 'api-perms:user-group-nodes-as-tree' pk=object.id %}?cache_policy=1";
var assetTableUrl = "{% url 'api-perms:user-group-assets' pk=object.id %}?cache_policy=1";
var selectUrl = '{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var showAssetHref = true; // Need input default true
......
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