Exemple #1
0
def list_shared_links(request):
    """List shared links, and remove invalid links(file/dir is deleted or moved).
    """
    username = request.user.username
    
    # download links
    fileshares = FileShare.objects.filter(username=username)
    p_fileshares = []           # personal file share
    for fs in fileshares:
        if is_personal_repo(fs.repo_id):  # only list files in personal repos
            r = seafile_api.get_repo(fs.repo_id)
            if not r:
                fs.delete()
                continue

            if fs.s_type == 'f':
                if seafile_api.get_file_id_by_path(r.id, fs.path) is None:
                    fs.delete()
                    continue
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_file_share_link(fs.token) 
            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('/'))
                fs.shared_link = gen_dir_share_link(fs.token)
            fs.repo = r
            p_fileshares.append(fs)

    # upload links
    uploadlinks = UploadLinkShare.objects.filter(username=username)
    p_uploadlinks = []
    for link in uploadlinks:
        if is_personal_repo(link.repo_id):
            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.shared_link = gen_shared_upload_link(link.token)
            link.repo = r
            p_uploadlinks.append(link)

    
    return render_to_response('share/links.html', {
            "fileshares": p_fileshares,
            "uploadlinks": p_uploadlinks,
            }, context_instance=RequestContext(request))
Exemple #2
0
def list_shared_links(request):
    """List shared links, and remove invalid links(file/dir is deleted or moved).
    """
    username = request.user.username

    # download links
    fileshares = FileShare.objects.filter(username=username)
    p_fileshares = []  # personal file share
    for fs in fileshares:
        if is_personal_repo(fs.repo_id):  # only list files in personal repos
            r = seafile_api.get_repo(fs.repo_id)
            if not r:
                fs.delete()
                continue

            if fs.s_type == 'f':
                if seafile_api.get_file_id_by_path(r.id, fs.path) is None:
                    fs.delete()
                    continue
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_file_share_link(fs.token)
            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('/'))
                fs.shared_link = gen_dir_share_link(fs.token)
            fs.repo = r
            p_fileshares.append(fs)

    # upload links
    uploadlinks = UploadLinkShare.objects.filter(username=username)
    p_uploadlinks = []
    for link in uploadlinks:
        if is_personal_repo(link.repo_id):
            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.shared_link = gen_shared_upload_link(link.token)
            link.repo = r
            p_uploadlinks.append(link)

    return render_to_response('share/links.html', {
        "fileshares": p_fileshares,
        "uploadlinks": p_uploadlinks,
    },
                              context_instance=RequestContext(request))
Exemple #3
0
def list_shared_links(request):
    """List share links, and remove invalid links(file/dir is deleted or moved).
    """
    username = request.user.username

    fileshares = FileShare.objects.filter(username=username)
    p_fileshares = []           # personal file share
    for fs in fileshares:
        if is_personal_repo(fs.repo_id):  # only list files in personal repos
            r = wingufile_api.get_repo(fs.repo_id)
            if not r:
                fs.delete()
                continue

            if fs.s_type == 'f':
                if wingufile_api.get_file_id_by_path(r.id, fs.path) is None:
                    fs.delete()
                    continue
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_file_share_link(fs.token) 
            else:
                if wingufile_api.get_dir_id_by_path(r.id, fs.path) is None:
                    fs.delete()
                    continue
                fs.filename = os.path.basename(fs.path.rstrip('/'))
                fs.shared_link = gen_dir_share_link(fs.token)
            fs.repo = r
            p_fileshares.append(fs)
    
    return render_to_response('repo/shared_links.html', {
            "fileshares": p_fileshares,
            }, context_instance=RequestContext(request))
Exemple #4
0
def list_shared_upload_links(request):
    """List upload links, and remove invalid links(dir is deleted or moved).
    """
    username = request.user.username

    uploadlinks = UploadLinkShare.objects.filter(username=username)
    p_uploadlinks = []
    for link in uploadlinks:
        if is_personal_repo(link.repo_id):
            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.shared_link = gen_shared_upload_link(link.token)
            link.repo = r
            p_uploadlinks.append(link)

    return render_to_response('repo/shared_upload_links.html', {
            "uploadlinks": p_uploadlinks,
            }, context_instance=RequestContext(request))
Exemple #5
0
def share_admin(request):
    """
    List personal shared repos and shared links.
    """
    username = request.user.username

    shared_repos = []

    # personal repos shared by this user
    shared_repos += seafserv_threaded_rpc.list_share_repos(username, 'from_email',
                                                           -1, -1)

    # repos shared to groups
    group_repos = seafserv_threaded_rpc.get_group_repos_by_owner(username)
    for repo in group_repos:
        group = ccnet_threaded_rpc.get_group(int(repo.group_id))
        if not group:
            repo.props.user = ''
            continue
        repo.props.user = group.props.group_name
        repo.props.user_info = repo.group_id
    shared_repos += group_repos

    if not CLOUD_MODE:
        # public repos shared by this user
        pub_repos = seafserv_threaded_rpc.list_inner_pub_repos_by_owner(username)
        for repo in pub_repos:
            repo.props.user = _(u'all members')
            repo.props.user_info = 'all'
        shared_repos += pub_repos

    for repo in shared_repos:
        if repo.props.permission == 'rw':
            repo.share_permission = _(u'Read-Write')
        elif repo.props.permission == 'r':
            repo.share_permission = _(u'Read-Only')
        else:
            repo.share_permission = ''

        if repo.props.share_type == 'personal':
            repo.props.user_info = repo.props.user

    shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))

    # Repo anonymous share links
    # out_links = AnonymousShare.objects.filter(repo_owner=request.user.username)
    # for link in out_links:
    #     repo = get_repo(link.repo_id)
    #     link.repo_name = repo.name
    #     link.remain_time = anon_share_token_generator.get_remain_time(link.token)        

    # Shared links
    fileshares = FileShare.objects.filter(username=username)
    p_fileshares = []           # personal file share
    for fs in fileshares:
        if is_personal_repo(fs.repo_id):  # only list files in personal repos
            if fs.s_type == 'f':
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_shared_link(request, fs.token, 'f') 
            else:
                fs.filename = os.path.basename(fs.path[:-1])
                fs.shared_link = gen_shared_link(request, fs.token, 'd')
            r = get_repo(fs.repo_id)
            if not r:           # get_repo may returns None
                continue
            fs.repo = r
            p_fileshares.append(fs)
        
    return render_to_response('repo/share_admin.html', {
            "org": None,
            "shared_repos": shared_repos,
            # "out_links": out_links,
            "fileshares": p_fileshares,
            }, context_instance=RequestContext(request))
Exemple #6
0
def share_admin(request):
    """
    List personal shared repos and shared links.
    """
    username = request.user.username

    shared_repos = []

    # personal repos shared by this user
    shared_repos += list_share_repos(username, 'from_email', -1, -1)

    # repos shared to groups
    group_repos = get_group_repos_by_owner(username)
    for repo in group_repos:
        group = ccnet_threaded_rpc.get_group(int(repo.group_id))
        if not group:
            repo.props.user = ''
            continue
        repo.props.user = group.props.group_name
        repo.props.user_info = repo.group_id
    shared_repos += group_repos

    if not CLOUD_MODE:
        # public repos shared by this user
        pub_repos = list_inner_pub_repos_by_owner(username)
        for repo in pub_repos:
            repo.props.user = _(u'all members')
            repo.props.user_info = 'all'
        shared_repos += pub_repos

    for repo in shared_repos:
        if repo.props.permission == 'rw':
            repo.share_permission = _(u'Read-Write')
        elif repo.props.permission == 'r':
            repo.share_permission = _(u'Read-Only')
        else:
            repo.share_permission = ''

        if repo.props.share_type == 'personal':
            repo.props.user_info = repo.props.user

    shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))

    # Repo anonymous share links
    # out_links = AnonymousShare.objects.filter(repo_owner=request.user.username)
    # for link in out_links:
    #     repo = get_repo(link.repo_id)
    #     link.repo_name = repo.name
    #     link.remain_time = anon_share_token_generator.get_remain_time(link.token)

    # Shared links
    fileshares = FileShare.objects.filter(username=username)
    p_fileshares = []  # personal file share
    for fs in fileshares:
        if is_personal_repo(fs.repo_id):  # only list files in personal repos
            if fs.s_type == 'f':
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_shared_link(request, fs.token, 'f')
            else:
                fs.filename = os.path.basename(fs.path[:-1])
                fs.shared_link = gen_shared_link(request, fs.token, 'd')
            r = get_repo(fs.repo_id)
            if not r:  # get_repo may returns None
                continue
            fs.repo = r
            p_fileshares.append(fs)

    return render_to_response(
        'repo/share_admin.html',
        {
            "org": None,
            "shared_repos": shared_repos,
            # "out_links": out_links,
            "fileshares": p_fileshares,
        },
        context_instance=RequestContext(request))
Exemple #7
0
def org_shareadmin(request, url_prefix):
    """
    List org shared repos and org shared links.
    """
    username = request.user.username

    org = get_user_current_org(request.user.username, url_prefix)
    if not org:
        return HttpResponseRedirect(reverse(myhome))

    shared_repos = []

    # org repos shared by this user
    shared_repos += seafserv_threaded_rpc.list_org_share_repos(org.org_id, username, "from_email", -1, -1)

    # repos shared to groups
    group_repos = seafserv_threaded_rpc.get_org_group_repos_by_owner(org.org_id, username)
    for repo in group_repos:
        group = ccnet_threaded_rpc.get_group(int(repo.group_id))
        if not group:
            repo.props.user = ""
            continue
        repo.props.user = group.props.group_name
        repo.props.user_info = repo.group_id
    shared_repos += group_repos

    # public repos shared by this user
    pub_repos = seafserv_threaded_rpc.list_org_inner_pub_repos_by_owner(org.org_id, username)
    for repo in pub_repos:
        repo.props.user = _(u"all members")
        repo.props.user_info = "all"
    shared_repos += pub_repos

    for repo in shared_repos:
        if repo.props.permission == "rw":
            repo.share_permission = _(u"Read-Write")
        elif repo.props.permission == "r":
            repo.share_permission = _(u"Read-Only")
        else:
            repo.share_permission = ""

        if repo.props.share_type == "personal":
            repo.props.user_info = repo.props.user

    shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))

    # shared links
    fileshares = FileShare.objects.filter(username=request.user.username)
    o_fileshares = []  # shared links in org repos
    for fs in fileshares:
        if not is_personal_repo(fs.repo_id):  # only list links in org repos
            if fs.s_type == "f":
                fs.filename = os.path.basename(fs.path)
                fs.shared_link = gen_shared_link(request, fs.token, "f")
            else:
                fs.filename = os.path.basename(fs.path[:-1])
                fs.shared_link = gen_shared_link(request, fs.token, "d")
            r = get_repo(fs.repo_id)  # get_repo may returns None
            if not r:
                continue
            fs.repo = r
            o_fileshares.append(fs)

    # use org base template
    request.base_template = "org_base.html"

    return render_to_response(
        "repo/share_admin.html",
        {
            "org": org,
            "shared_repos": shared_repos,
            "fileshares": o_fileshares,
            "protocol": request.is_secure() and "https" or "http",
            "domain": RequestSite(request).domain,
        },
        context_instance=RequestContext(request),
    )
Exemple #8
0
def org_shareadmin(request, url_prefix):
    """
    List personal repos I share to others, include groups and users.
    """
    username = request.user.username

    org = get_user_current_org(request.user.username, url_prefix)
    if not org:
        return HttpResponseRedirect(reverse(myhome))
    
    shared_repos = []

    # personal repos shared by this user
    shared_repos += seafserv_threaded_rpc.list_org_share_repos(org.org_id,
                                                               username,
                                                               'from_email',
                                                               -1, -1)

    # repos shared to groups
    group_repos = seafserv_threaded_rpc.get_org_group_repos_by_owner(org.org_id,
                                                                      username)
    for repo in group_repos:
        group = ccnet_threaded_rpc.get_group(int(repo.group_id))
        if not group:
            repo.props.user = ''
            continue
        repo.props.user = group.props.group_name
        repo.props.user_info = repo.group_id
    shared_repos += group_repos

    # public repos shared by this user
    pub_repos = seafserv_threaded_rpc.list_org_inner_pub_repos_by_owner(org.org_id,
                                                                        username)
    for repo in pub_repos:
        repo.props.user = _(u'all members')
        repo.props.user_info = 'all'
    shared_repos += pub_repos

    for repo in shared_repos:
        if repo.props.permission == 'rw':
            repo.share_permission = _(u'Read-Write')
        elif repo.props.permission == 'r':
            repo.share_permission = _(u'Read-Only')
        else:
            repo.share_permission = ''

        if repo.props.share_type == 'personal':
            repo.props.user_info = repo.props.user

    shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))

    # File shared links
    fileshares = FileShare.objects.filter(username=request.user.username)
    o_fileshares = []           # shared files in org repos
    for fs in fileshares:
        if not is_personal_repo(fs.repo_id):
            # only list files in org repos
            fs.filename = os.path.basename(fs.path)
            fs.repo = get_repo(fs.repo_id)
            o_fileshares.append(fs)

    request.base_template = 'org_base.html'
    
    return render_to_response('repo/share_admin.html', {
            "org": org,
            "shared_repos": shared_repos,
            "fileshares": o_fileshares,
            "protocol": request.is_secure() and 'https' or 'http',
            "domain": RequestSite(request).domain,
            }, context_instance=RequestContext(request))