def upload_file(): # check if the post request has the file part if 'file' not in request.files or request.files['file'] is None: return json_response_with_status({ 'error': 'NO_FILE_UPLOADED' }, 500) uploaded_file = request.files['file'] if uploaded_file.filename == '': return json_response_with_status({ 'error': 'EMPTY_FILE_NAME' }, 500) if allowed_file(uploaded_file.filename): now = datetime.datetime.now() appended_file_name = os.path.join(str(now.year) + str(now.month), str(random.randint(100000, 999999)) + "__" + uploaded_file.filename) path = os.path.abspath(os.path.join(settings.FILE_UPLOAD_FOLDER, appended_file_name)) parent_dir = os.path.dirname(path) if not os.path.exists(parent_dir): os.makedirs(parent_dir) uploaded_file.save(path) return json_response({"status": "OK", "url": appended_file_name}) else: return json_response_with_status({ 'error': 'NOT_ALLOWED_EXTENSIONS' }, 500)
def login(): login_info = request.get_json(True) user = models.User.get_by_email(login_info["email"]) if user and not user.is_disabled and user.verify_password( login_info['password']): login_user(user, remember=("remember" in login_info and login_info["remember"])) return json_response({'status': 'OK'}) else: return json_response_with_status({'error': 'LOGIN_FAILED'}, 401)
def setup(): # local proxy needs to use != to check None if current_org != None: return json_response_with_status({'error': 'SETUP_NOT_ALLOWED'}, 403) setup_info = request.get_json(True) default_org, user = create_org(setup_info["org_name"], setup_info["name"], setup_info["email"], setup_info["password"]) g.org = default_org login_user(user) return json_response({'status': 'OK'})
def session(): user = { 'profile_image_url': current_user.profile_image_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } return json_response({ 'user': user, 'messages': __messages(), 'org_slug': current_org.slug, 'client_config': client_config() })
def organization_status(): counters = { 'users': models.User.all(current_org).count(), 'alerts': models.Alert.all(group_ids=current_user.group_ids).count(), 'data_sources': models.DataSource.all(current_org, group_ids=current_user.group_ids).count(), 'queries': models.Query.all_queries(current_user.group_ids, current_user.id, include_drafts=True).count(), 'dashboards': models.Dashboard.query.filter( models.Dashboard.org == current_org, models.Dashboard.is_archived == False).count(), } return json_response(dict(object_counters=counters))
def upload_image(): # check if the post request has the file part if 'file' not in request.files or request.files['file'] is None: return json_response_with_status({'error': 'NO_FILE_UPLOADED'}, 500) uploaded_file = request.files['file'] if uploaded_file.filename == '': return json_response_with_status({'error': 'EMPTY_FILE_NAME'}, 500) if allowed_file(uploaded_file.filename): now = datetime.datetime.now() appended_file_name = os.path.join( str(now.year) + str(now.month), str(random.randint(100000, 999999)) + "__" + uploaded_file.filename) path = os.path.abspath( os.path.join(settings.IMAGE_UPLOAD_FOLDER, appended_file_name)) parent_dir = os.path.dirname(path) print(parent_dir) if not os.path.exists(parent_dir): os.makedirs(parent_dir) uploaded_file.save(path) print(path) # print("1111111111") # with open(r'///opt/redash/image_uploads/{}'.format(appended_file_name),'rb') as f: # image=f.read() # resp = Response(image, mimetype="image/jpg") # print(image) # print(resp) # return resp return json_response({"status": "OK", "url": appended_file_name}) else: return json_response_with_status({'error': 'NOT_ALLOWED_EXTENSIONS'}, 500)
def logout(): logout_user() return json_response({'status': 'OK'})
def config(): return json_response({ 'org_slug': current_org.slug, 'client_config': client_config() })