Esempio n. 1
0
def reloaddir(request, repo_id, parent_dir):
    current_commit = get_commits(repo_id, 0, 1)[0]
    if not current_commit:
        return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
                         'Failed to get current commit of repo %s.' % repo_id)

    try:
        dir_id = seafserv_threaded_rpc.get_dirid_by_path(
            current_commit.id, parent_dir.encode('utf-8'))
    except SearpcError, e:
        return api_error(HTTP_520_OPERATION_FAILED,
                         "Failed to get dir id by path")
Esempio n. 2
0
def reloaddir(request, repo_id, parent_dir):
    current_commit = get_commits(repo_id, 0, 1)[0]
    if not current_commit:
        return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
                         'Failed to get current commit of repo %s.' % repo_id)

    try:
        dir_id = seafserv_threaded_rpc.get_dirid_by_path(current_commit.id,
                                                         parent_dir.encode('utf-8'))
    except SearpcError, e:
        return api_error(HTTP_520_OPERATION_FAILED,
                         "Failed to get dir id by path")
Esempio n. 3
0
def reloaddir_if_neccessary (request, repo_id, parent_dir):
    reloaddir = False
    s = request.GET.get('reloaddir', None)
    if s and s.lower() == 'true':
        reloaddir = True

    if not reloaddir:
        return HttpResponse(json.dumps('success'), status='200',
                            content_type=json_content_type)

    current_commit = get_commits(repo_id, 0, 1)[0]
    try:
        dir_id = seafserv_threaded_rpc.get_dirid_by_path(current_commit.id,
                                                         parent_dir.encode('utf-8'))
    except SearpcError, e:
        return api_error(request, "411", "SearpcError:" + e.msg)
Esempio n. 4
0
    def get(self, request, repo_id):
        repo = get_repo(repo_id)
        resp = check_repo_access_permission(request, repo)
        if resp:
            return resp

        current_commit = get_commits(repo_id, 0, 1)[0]
        path = request.GET.get('p', '/')
        if path[-1] != '/':
            path = path + '/'

        dir_id = None
        try:
            dir_id = seafserv_threaded_rpc.get_dirid_by_path(current_commit.id,
                                                             path.encode('utf-8'))
        except SearpcError, e:
            return api_error(request, "411", "SearpcError:" + e.msg)
Esempio n. 5
0
def reloaddir_if_neccessary (request, repo_id, parent_dir):
    reloaddir = False
    s = request.GET.get('reloaddir', None)
    if s and s.lower() == 'true':
        reloaddir = True

    if not reloaddir:
        return Response('success')

    current_commit = get_commits(repo_id, 0, 1)[0]
    if not current_commit:
        return api_error('422')

    try:
        dir_id = seafserv_threaded_rpc.get_dirid_by_path(current_commit.id,
                                                         parent_dir.encode('utf-8'))
    except SearpcError, e:
        return api_error("411", "SearpcError:" + e.msg)
Esempio n. 6
0
def user_info(request, email):
    owned_repos = seafile_api.get_owned_repo_list(email)

    org = ccnet_threaded_rpc.get_orgs_by_user(email)
    org_name = None
    if not org:
        space_usage = seafile_api.get_user_self_usage(email)
        space_quota = seafile_api.get_user_quota(email)
        if CALC_SHARE_USAGE:
            share_usage = seafile_api.get_user_share_usage(email)
            share_quota = seafile_api.get_user_share_quota(email)
        else:
            share_quota = share_usage = 0
    else:
        org_id = org[0].org_id
        org_name = org[0].org_name
        space_usage = seafserv_threaded_rpc.get_org_user_quota_usage(
            org_id, email)
        space_quota = seafserv_threaded_rpc.get_org_user_quota(org_id, email)
        share_usage = share_quota = 0

    # Repos that are share to user
    in_repos = seafile_api.get_share_in_repo_list(email, -1, -1)

    # get user profile
    profile = Profile.objects.get_profile_by_user(email)
    d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email)

    user_shared_links = []
    # download links
    p_fileshares = []
    fileshares = list(FileShare.objects.filter(username=email))
    for fs in fileshares:
        r = seafile_api.get_repo(fs.repo_id)
        if not r:
            fs.delete()
            continue

        if fs.is_file_share_link():
            if seafile_api.get_file_id_by_path(r.id, fs.path) is None:
                fs.delete()
                continue
            fs.filename = os.path.basename(fs.path)
            path = fs.path.rstrip('/')  # Normalize file path
            obj_id = seafile_api.get_file_id_by_path(r.id, path)
            fs.file_size = seafile_api.get_file_size(r.store_id, r.version,
                                                     obj_id)
        else:
            if seafile_api.get_dir_id_by_path(r.id, fs.path) is None:
                fs.delete()
                continue
            fs.filename = os.path.basename(fs.path.rstrip('/'))
            path = fs.path
            if path[-1] != '/':  # Normalize dir path
                path += '/'
            # get dir size
            dir_id = seafserv_threaded_rpc.get_dirid_by_path(
                r.id, r.head_cmmt_id, path)
            fs.dir_size = seafserv_threaded_rpc.get_dir_size(
                r.store_id, r.version, dir_id)

        fs.is_download = True
        p_fileshares.append(fs)
    p_fileshares.sort(key=lambda x: x.view_cnt, reverse=True)
    user_shared_links += p_fileshares

    # upload links
    uploadlinks = list(UploadLinkShare.objects.filter(username=email))
    p_uploadlinks = []
    for link in uploadlinks:
        r = seafile_api.get_repo(link.repo_id)
        if not r:
            link.delete()
            continue
        if seafile_api.get_dir_id_by_path(r.id, link.path) is None:
            link.delete()
            continue
        link.dir_name = os.path.basename(link.path.rstrip('/'))
        link.is_upload = True
        p_uploadlinks.append(link)
    p_uploadlinks.sort(key=lambda x: x.view_cnt, reverse=True)
    user_shared_links += p_uploadlinks

    return render_to_response('sysadmin/userinfo.html', {
        'owned_repos': owned_repos,
        'space_quota': space_quota,
        'space_usage': space_usage,
        'share_quota': share_quota,
        'share_usage': share_usage,
        'CALC_SHARE_USAGE': CALC_SHARE_USAGE,
        'in_repos': in_repos,
        'email': email,
        'profile': profile,
        'd_profile': d_profile,
        'org_name': org_name,
        'user_shared_links': user_shared_links,
    },
                              context_instance=RequestContext(request))
Esempio n. 7
0
def user_info(request, email):
    owned_repos = seafile_api.get_owned_repo_list(email)

    org = ccnet_threaded_rpc.get_orgs_by_user(email)
    org_name = None
    if not org:
        space_usage = seafile_api.get_user_self_usage(email)
        space_quota = seafile_api.get_user_quota(email)
        if CALC_SHARE_USAGE:
            share_usage = seafile_api.get_user_share_usage(email)
            share_quota = seafile_api.get_user_share_quota(email)
        else:
            share_quota = share_usage = 0
    else:
        org_id = org[0].org_id
        org_name = org[0].org_name
        space_usage = seafserv_threaded_rpc.get_org_user_quota_usage(org_id,
                                                                     email)
        space_quota = seafserv_threaded_rpc.get_org_user_quota(org_id, email)
        share_usage = share_quota = 0

    # Repos that are share to user
    in_repos = seafile_api.get_share_in_repo_list(email, -1, -1)

    # get user profile
    profile = Profile.objects.get_profile_by_user(email)
    d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email)

    user_shared_links = []
    # download links
    p_fileshares = []
    fileshares = list(FileShare.objects.filter(username=email))
    for fs in fileshares:
        r = seafile_api.get_repo(fs.repo_id)
        if not r:
            fs.delete()
            continue

        if fs.is_file_share_link():
            if seafile_api.get_file_id_by_path(r.id, fs.path) is None:
                fs.delete()
                continue
            fs.filename = os.path.basename(fs.path)
            path = fs.path.rstrip('/') # Normalize file path
            obj_id = seafile_api.get_file_id_by_path(r.id, path)
            fs.file_size = seafile_api.get_file_size(r.store_id, r.version,
                                                     obj_id)
        else:
            if seafile_api.get_dir_id_by_path(r.id, fs.path) is None:
                fs.delete()
                continue
            fs.filename = os.path.basename(fs.path.rstrip('/'))
            path = fs.path
            if path[-1] != '/':         # Normalize dir path
                path += '/'
            # get dir size
            dir_id = seafserv_threaded_rpc.get_dirid_by_path(r.id,
                                                             r.head_cmmt_id,
                                                             path)
            fs.dir_size = seafserv_threaded_rpc.get_dir_size(r.store_id,
                                                             r.version,
                                                             dir_id)

        fs.is_download = True
        p_fileshares.append(fs)
    p_fileshares.sort(key=lambda x: x.view_cnt, reverse=True)
    user_shared_links += p_fileshares

    # upload links
    uploadlinks = list(UploadLinkShare.objects.filter(username=email))
    p_uploadlinks = []
    for link in uploadlinks:
        r = seafile_api.get_repo(link.repo_id)
        if not r:
            link.delete()
            continue
        if seafile_api.get_dir_id_by_path(r.id, link.path) is None:
            link.delete()
            continue
        link.dir_name = os.path.basename(link.path.rstrip('/'))
        link.is_upload = True
        p_uploadlinks.append(link)
    p_uploadlinks.sort(key=lambda x: x.view_cnt, reverse=True)
    user_shared_links += p_uploadlinks

    return render_to_response(
        'sysadmin/userinfo.html', {
            'owned_repos': owned_repos,
            'space_quota': space_quota,
            'space_usage': space_usage,
            'share_quota': share_quota,
            'share_usage': share_usage,
            'CALC_SHARE_USAGE': CALC_SHARE_USAGE,
            'in_repos': in_repos,
            'email': email,
            'profile': profile,
            'd_profile': d_profile,
            'org_name': org_name,
            'user_shared_links': user_shared_links,
        }, context_instance=RequestContext(request))
Esempio n. 8
0
            fs.filename = os.path.basename(fs.path)
            path = fs.path.rstrip('/') # Normalize file path 
            obj_id = seafile_api.get_file_id_by_path(r.id, path)
            fs.file_size = seafile_api.get_file_size(r.store_id, r.version,
                                                     obj_id)
        else:
            if seafile_api.get_dir_id_by_path(r.id, fs.path) is None:
                fs.delete()
                continue
            fs.filename = os.path.basename(fs.path.rstrip('/'))
            path = fs.path
            if path[-1] != '/':         # Normalize dir path
                path += '/'
            # get dir size
            dir_id = seafserv_threaded_rpc.get_dirid_by_path(r.id,
                                                             r.head_cmmt_id,
                                                             path)
            fs.dir_size = seafserv_threaded_rpc.get_dir_size(r.store_id,
                                                             r.version,
                                                             dir_id)

        fs.is_download = True
        p_fileshares.append(fs)
    p_fileshares.sort(key=lambda x: x.view_cnt, reverse=True)
    user_shared_links += p_fileshares

    # upload links
    uploadlinks = list(UploadLinkShare.objects.filter(username=email))
    p_uploadlinks = []
    for link in uploadlinks:
        r = seafile_api.get_repo(link.repo_id)