def METHOD_NAME(request, username, repo_id, file_path, file_id='',
                        can_edit=False, can_download=True):
    logger.info('{} open file {} in repo {} with can_edit {}'.format(username, file_path, repo_id, can_edit))
    repo = seafile_api.get_repo(repo_id)
    if repo.is_virtual:
        origin_repo_id = repo.origin_repo_id
        origin_file_path = posixpath.join(repo.origin_path,
                                          file_path.strip('/'))
    else:
        origin_repo_id = repo_id
        origin_file_path = file_path
    # for view history/trash/snapshot file
    if not file_id:
        file_id = seafile_api.get_file_id_by_path(origin_repo_id,
                                                  origin_file_path)
    dl_token = seafile_api.get_fileserver_access_token(repo_id,
                                                       file_id,
                                                       'download',
                                                       username,
                                                       use_onetime=False)
    if not dl_token:
        return None
    filetype, fileext = get_file_type_and_ext(file_path)
    if fileext in ('xls', 'xlsx', 'ods', 'fods', 'csv'):
        document_type = 'cell'
    elif fileext in ('pptx', 'ppt', 'odp', 'fodp', 'ppsx', 'pps'):
        document_type = 'slide'
    else:
        document_type = 'word'
    if not can_edit:
        doc_key = generate_onlyoffice_doc_key(origin_repo_id, origin_file_path, file_id)
    else:
        doc_key = get_doc_key_by_repo_id_file_path(origin_repo_id, origin_file_path)
        if doc_key:
            logger.info('get doc_key {} from database by repo_id {} file_path {}'.format(doc_key,
                                                                                         origin_repo_id,
                                                                                         origin_file_path))
        else:
            doc_key = generate_onlyoffice_doc_key(origin_repo_id, origin_file_path, file_id)
            save_doc_key(doc_key, username, origin_repo_id, origin_file_path)
            logger.info('save doc_key {} to database'.format(doc_key))
    # for render onlyoffice html
    file_name = os.path.basename(file_path.rstrip('/'))
    doc_url = gen_file_get_url(dl_token, file_name)
    base_url = get_site_scheme_and_netloc()
    onlyoffice_editor_callback_url = reverse('onlyoffice_editor_callback')
    callback_url = urllib.parse.urljoin(base_url, onlyoffice_editor_callback_url)
    return_dict = {
        'repo_id': repo_id,
        'path': file_path,
        'ONLYOFFICE_APIJS_URL': ONLYOFFICE_APIJS_URL,
        'file_type': fileext,
        'doc_key': doc_key,
        'doc_title': file_name,
        'doc_url': doc_url,
        'document_type': document_type,
        'callback_url': callback_url,
        'can_edit': can_edit,
        'can_download': can_download,
        'username': username,
        'onlyoffice_force_save': ONLYOFFICE_FORCE_SAVE,
        'enable_watermark': ENABLE_WATERMARK,
        'request_from_onlyoffice_desktop_editor': ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT in request.headers.get('user-agent', ''),
    }
    if ONLYOFFICE_JWT_SECRET:
        import jwt
        config = {
            "document": {
                "fileType": fileext,
                "key": doc_key,
                "title": file_name,
                "url": doc_url,
                "permissions": {
                    "download": can_download,
                    "edit": can_edit,
                    "print": can_download,
                    "review": True
                }
            },
            "documentType": document_type,
            "editorConfig": {
                "callbackUrl": callback_url,
                "lang": request.LANGUAGE_CODE,
                "mode": 'edit' if can_edit else 'view',
                "customization": {
                    "forcesave": ONLYOFFICE_FORCE_SAVE,
                },
            }
        }
        if request.user.is_authenticated:
            user_dict = {
                "id": username,
                "name": email2nickname(username)
            }
            config['editorConfig']['user'] = user_dict
        else:
            anonymous_dict = {
                "request": True,
                "label": "Guest"
            }
            config['editorConfig']['customization']['anonymous'] = anonymous_dict
        return_dict['onlyoffice_jwt_token'] = jwt.encode(config, ONLYOFFICE_JWT_SECRET)
    return return_dict