diff --git a/apps/settings/api.py b/apps/settings/api.py index 9df77d036..82d483c5e 100644 --- a/apps/settings/api.py +++ b/apps/settings/api.py @@ -102,6 +102,7 @@ class LDAPUserListApi(generics.ListAPIView): if hasattr(self, 'swagger_fake_view'): return [] util = LDAPUtil() + try: users = util.search_user_items() except Exception as e: @@ -112,20 +113,6 @@ class LDAPUserListApi(generics.ListAPIView): user['id'] = user['username'] return users - def filter_queryset(self, queryset): - search = self.request.query_params.get('search') - if not search: - return queryset - search = search.lower() - queryset = [ - q for q in queryset - if - search in q['username'].lower() - or search in q['name'].lower() - or search in q['email'].lower() - ] - return queryset - def sort_queryset(self, queryset): order_by = self.request.query_params.get('order') if not order_by: @@ -139,7 +126,7 @@ class LDAPUserListApi(generics.ListAPIView): return queryset def list(self, request, *args, **kwargs): - queryset = self.filter_queryset(self.get_queryset()) + queryset = self.get_queryset() queryset = self.sort_queryset(queryset) page = self.paginate_queryset(queryset) if page is not None: diff --git a/apps/settings/utils.py b/apps/settings/utils.py index 657aa4600..fabdb3967 100644 --- a/apps/settings/utils.py +++ b/apps/settings/utils.py @@ -81,9 +81,12 @@ class LDAPUtil: user_item[attr] = value return user_item - def _search_user_items_ou(self, search_ou, cookie=None): + def _search_user_items_ou(self, search_ou, extra_filter=None, cookie=None): + search_filter = self.search_filter % {"user": "*"} + if extra_filter: + search_filter = '(&({})({}))'.format(search_filter, extra_filter) ok = self.connection.search( - search_ou, self.search_filter % ({"user": "*"}), + search_ou, search_filter, attributes=list(self.attr_map.values()), paged_size=self.paged_size, paged_cookie=cookie ) @@ -108,16 +111,21 @@ class LDAPUtil: cookie = self.connection.result['controls']['1.2.840.113556.1.4.319']['value']['cookie'] return cookie - def search_user_items(self): + def search_user_items(self, q=None): user_items = [] logger.info("Search user items") + extra_filter = '' + if q: + for attr in self.attr_map.values(): + extra_filter += '({}={})'.format(attr, q) + extra_filter = '(|{})'.format(extra_filter) for search_ou in str(self.search_ougroup).split("|"): logger.info("Search user search ou: {}".format(search_ou)) - _user_items = self._search_user_items_ou(search_ou) + _user_items = self._search_user_items_ou(search_ou, extra_filter=extra_filter) user_items.extend(_user_items) while self._cookie(): logger.info("Page Search user search ou: {}".format(search_ou)) - _user_items = self._search_user_items_ou(search_ou, self._cookie()) + _user_items = self._search_user_items_ou(search_ou, extra_filter, self._cookie()) user_items.extend(_user_items) logger.info("Search user items end") return user_items diff --git a/apps/terminal/templates/terminal/command_list.html b/apps/terminal/templates/terminal/command_list.html index 3580af03f..1fc6f1d76 100644 --- a/apps/terminal/templates/terminal/command_list.html +++ b/apps/terminal/templates/terminal/command_list.html @@ -164,11 +164,14 @@ $(document).ready(function () { detailRows.push(tr.attr('id')); } } -}) +}); function format(d) { var output = $("
"); + + output.append('$ ', d.input); + output.append('\r\n\r\n'); output.append(d.output); return output } @@ -187,6 +190,17 @@ function initTable() { $(td).addClass("toggle"); $(td).html(""); }}, + {targets: 1, createdCell: function (td, cellData) { + var data = htmlEscape(cellData); + var interHtml = $(""); + if (data.length > 40) { + interHtml.attr('title', data); + data = data.slice(0, 40); + data += ' ...'; + } + interHtml.html(data); + $(td).html(interHtml); + }}, {targets: 5, createdCell: function (td, cellData) { var data = '{% trans "Goto" %}' .replace('{{ DEFAULT_PK }}', cellData); @@ -200,7 +214,7 @@ function initTable() { toggle: true, ajax_url: commandListUrl, columns: [ - {data: "id"}, {data: "input", orderable: false}, {data: "user", orderable: false}, + {data: "id"}, {data: "input", orderable: false, width: "40%"}, {data: "user", orderable: false}, {data: "asset", orderable: false}, {data: "system_user", orderable: false}, {data: "session", orderable: false}, {data: "timestamp", width: "160px", orderable: false}, ], diff --git a/apps/terminal/templates/terminal/session_detail.html b/apps/terminal/templates/terminal/session_detail.html index b54eedec7..9edcaeccf 100644 --- a/apps/terminal/templates/terminal/session_detail.html +++ b/apps/terminal/templates/terminal/session_detail.html @@ -54,8 +54,12 @@ {% for command in object_list %}{{ command.output }}
+$ {{ command.input }} +
+{{ command.output }} +