Пример #1
0
def react_fake_view(request, **kwargs):

    username = request.user.username

    if resolve(request.path).url_name == 'lib_view':

        repo_id = kwargs.get('repo_id', '')
        path = kwargs.get('path', '')

        if repo_id and path and \
                not check_folder_permission(request, repo_id, path):

            converted_repo_path = seafile_api.convert_repo_path(
                repo_id, path, username)
            if not converted_repo_path:
                error_msg = 'Permission denied.'
                return render_error(request, error_msg)

            repo_path_dict = json.loads(converted_repo_path)

            converted_repo_id = repo_path_dict['repo_id']
            converted_repo = seafile_api.get_repo(converted_repo_id)
            if not converted_repo:
                error_msg = 'Library %s not found.' % converted_repo_id
                return render_error(request, error_msg)

            converted_path = repo_path_dict['path']
            if not seafile_api.get_dirent_by_path(converted_repo_id,
                                                  converted_path):
                error_msg = 'Dirent %s not found.' % converted_path
                return render_error(request, error_msg)

            if not check_folder_permission(request, converted_repo_id,
                                           converted_path):
                error_msg = 'Permission denied.'
                return render_error(request, error_msg)

            next_url = reverse('lib_view',
                               args=[
                                   converted_repo_id, converted_repo.repo_name,
                                   converted_path.strip('/')
                               ])
            return HttpResponseRedirect(next_url)

    guide_enabled = UserOptions.objects.is_user_guide_enabled(username)
    if guide_enabled:
        create_default_library(request)

    try:
        expire_days = seafile_api.get_server_config_int(
            'library_trash', 'expire_days')
    except Exception as e:
        logger.error(e)
        expire_days = -1

    folder_perm_enabled = True if is_pro_version(
    ) and ENABLE_FOLDER_PERM else False

    try:
        max_upload_file_size = seafile_api.get_server_config_int(
            'fileserver', 'max_upload_size')
    except Exception as e:
        logger.error(e)
        max_upload_file_size = -1

    return render(
        request, "react_app.html", {
            "onlyoffice_desktop_editors_portal_login":
            ONLYOFFICE_DESKTOP_EDITORS_PORTAL_LOGIN,
            "guide_enabled": guide_enabled,
            'trash_repos_expire_days': expire_days if expire_days > 0 else 30,
            'dtable_web_server': DTABLE_WEB_SERVER,
            'max_upload_file_size': max_upload_file_size,
            'seafile_collab_server': SEAFILE_COLLAB_SERVER,
            'storages': get_library_storages(request),
            'library_templates': list(LIBRARY_TEMPLATES.keys()),
            'enable_repo_snapshot_label': settings.ENABLE_REPO_SNAPSHOT_LABEL,
            'resumable_upload_file_block_size':
            settings.RESUMABLE_UPLOAD_FILE_BLOCK_SIZE,
            'max_number_of_files_for_fileupload':
            settings.MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD,
            'share_link_expire_days_default': SHARE_LINK_EXPIRE_DAYS_DEFAULT,
            'share_link_expire_days_min': SHARE_LINK_EXPIRE_DAYS_MIN,
            'share_link_expire_days_max': SHARE_LINK_EXPIRE_DAYS_MAX,
            'upload_link_expire_days_default': UPLOAD_LINK_EXPIRE_DAYS_DEFAULT,
            'upload_link_expire_days_min': UPLOAD_LINK_EXPIRE_DAYS_MIN,
            'upload_link_expire_days_max': UPLOAD_LINK_EXPIRE_DAYS_MAX,
            'enable_encrypted_library': config.ENABLE_ENCRYPTED_LIBRARY,
            'enable_repo_history_setting': config.ENABLE_REPO_HISTORY_SETTING,
            'enable_reset_encrypted_repo_password':
            ENABLE_RESET_ENCRYPTED_REPO_PASSWORD,
            'enableFileComment': settings.ENABLE_FILE_COMMENT,
            'is_email_configured': IS_EMAIL_CONFIGURED,
            'can_add_public_repo':
            request.user.permissions.can_add_public_repo(),
            'folder_perm_enabled': folder_perm_enabled,
            'file_audit_enabled': FILE_AUDIT_ENABLED,
            'custom_nav_items': json.dumps(CUSTOM_NAV_ITEMS),
            'enable_show_contact_email_when_search_user':
            settings.ENABLE_SHOW_CONTACT_EMAIL_WHEN_SEARCH_USER,
            'additional_share_dialog_note': ADDITIONAL_SHARE_DIALOG_NOTE,
            'additional_app_bottom_links': ADDITIONAL_APP_BOTTOM_LINKS,
            'additional_about_dialog_links': ADDITIONAL_ABOUT_DIALOG_LINKS,
            'enable_ocm': ENABLE_OCM,
            'ocm_remote_servers': OCM_REMOTE_SERVERS,
            'enable_share_to_department': settings.ENABLE_SHARE_TO_DEPARTMENT,
            'enable_video_thumbnail': settings.ENABLE_VIDEO_THUMBNAIL,
            'group_import_members_extra_msg': GROUP_IMPORT_MEMBERS_EXTRA_MSG,
        })
Пример #2
0
def convert_repo_path_when_can_not_view_folder(request, repo_id, path):

    content_type = 'application/json; charset=utf-8'

    path = normalize_dir_path(path)
    username = request.user.username
    converted_repo_path = seafile_api.convert_repo_path(
        repo_id, path, username)
    if not converted_repo_path:
        err_msg = _('Permission denied.')
        return HttpResponse(json.dumps({'error': err_msg}),
                            status=403,
                            content_type=content_type)

    converted_repo_path = json.loads(converted_repo_path)

    repo_id = converted_repo_path['repo_id']
    repo = seafile_api.get_repo(repo_id)
    if not repo:
        err_msg = 'Library not found.'
        return HttpResponse(json.dumps({'error': err_msg}),
                            status=404,
                            content_type=content_type)

    path = converted_repo_path['path']
    path = normalize_dir_path(path)
    dir_id = seafile_api.get_dir_id_by_path(repo.id, path)
    if not dir_id:
        err_msg = 'Folder not found.'
        return HttpResponse(json.dumps({'error': err_msg}),
                            status=404,
                            content_type=content_type)

    group_id = ''
    if 'group_id' in converted_repo_path:
        group_id = converted_repo_path['group_id']
        if not ccnet_api.get_group(group_id):
            err_msg = 'Group not found.'
            return HttpResponse(json.dumps({'error': err_msg}),
                                status=404,
                                content_type=content_type)

        if not is_group_member(group_id, username):
            err_msg = _('Permission denied.')
            return HttpResponse(json.dumps({'error': err_msg}),
                                status=403,
                                content_type=content_type)

    user_perm = check_folder_permission(request, repo_id, path)
    if not user_perm:
        err_msg = _('Permission denied.')
        return HttpResponse(json.dumps({'error': err_msg}),
                            status=403,
                            content_type=content_type)

    if not group_id:
        next_url = '#shared-libs/lib/%s/%s' % (repo_id, path.strip('/'))
    else:
        next_url = '#group/%s/lib/%s/%s' % (group_id, repo_id, path.strip('/'))

    return HttpResponse(json.dumps({'next_url': next_url}),
                        content_type=content_type)