def saved_update(self, request, **kwargs): self.method_check(request, allowed=['post']) req_data = request.POST query = req_data.get('query', '') timerange = req_data.get('time_range', '') sg = req_data.get('sourcegroup', '') sourcegroup = req_data.get('sourcegroupCn', '') if not sg == 'all' else 'all' filters = req_data.get('filters', '') name = req_data.get('name', '') savedsearch_id = kwargs['ssid'] dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: res = BackendRequest.update_saved_search({ "token": es_check["t"], "operator": es_check["u"], "id": savedsearch_id, "name": name, "query": query, "time_range": timerange, "source_groups": sourcegroup, "filters": filters }) if res["result"]: dummy_data["status"] = "1" else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp
def saved_update_fav(self, request, **kwargs): self.method_check(request, allowed=['post']) savedsearch_id = kwargs['ssid'] fav = 'yes' if kwargs['fav'] == '1' else 'no' post_data = request.POST print request rg_ids = post_data.get("rg_ids", "") dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: res = BackendRequest.update_saved_search({ "token": es_check["t"], 'operator': es_check['u'], "id": savedsearch_id, 'resource_group_ids': rg_ids, "like": fav }) if res["result"]: res_list = BackendRequest.get_all_saved_search({ "token": es_check["t"], 'operator': es_check['u'] }) saved_searches = [] if res_list['result']: for i in res_list['items']: anonymous = i.get('anonymous', False) if anonymous: continue saved_searches.append({ 'savedsearch_id': i['id'].encode('utf-8'), 'savedsearch_name': i['name'].encode('utf-8'), "related_alert_num": i.get('alert_count', 0), 'query': i['query'].encode('utf-8'), "sourcegroup": i['source_groups'].encode('utf-8'), "owner": i.get('owner_name', "").encode('utf-8'), "timerange": i.get('time_range', "").encode('utf-8'), "filters": i.get('filters', "").encode('utf-8'), "fav": 'yes' if i.get('like', True) else 'no' }) dummy_data["status"] = "1" dummy_data["fav"] = fav dummy_data["list"] = saved_searches else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp