Esempio n. 1
0
def list_share_out_repos(request):
    shared_repos = []
    username = request.user.username

    # repos shared from this user
    shared_repos += seafile_api.get_share_out_repo_list(username, -1, -1)

    # repos shared to groups
    group_repos = get_group_repos_by_owner(request)
    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

    # pub repos
    pub_repos = get_inner_pub_repo_list(request)
    for repo in pub_repos:
        repo.props.user = _(u'all members')
        repo.props.user_info = 'all'
    shared_repos += pub_repos

    return shared_repos
Esempio n. 2
0
def list_share_out_repos(request):
    shared_repos = []
    username = request.user.username

    # repos shared from this user
    shared_repos += seafile_api.get_share_out_repo_list(username, -1, -1)

    # repos shared to groups
    group_repos = get_group_repos_by_owner(request)
    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

    # pub repos
    pub_repos = get_inner_pub_repo_list(request)
    for repo in pub_repos:
        repo.props.user = _(u'all members')
        repo.props.user_info = 'all'
    shared_repos += pub_repos

    return shared_repos
Esempio n. 3
0
def get_group_repos_by_owner(request):
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return get_org_group_repos_by_owner(org_id, username)
    else:
        return seaserv.get_group_repos_by_owner(username)
Esempio n. 4
0
def get_group_repos_by_owner(request):
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return get_org_group_repos_by_owner(org_id, username)
    else:
        return seaserv.get_group_repos_by_owner(username)
Esempio n. 5
0
    def get(self, request, format=None):
        username = request.user.username
        shared_repos = []
        
        shared_repos += list_share_repos(username, 'from_email', -1, -1)
        shared_repos += get_group_repos_by_owner(username)
        if not CLOUD_MODE:
            shared_repos += list_inner_pub_repos_by_owner(username)

        return HttpResponse(json.dumps(shared_repos, cls=SearpcObjEncoder),
                            status=200, content_type=json_content_type)
Esempio n. 6
0
    def get(self, request, format=None):
        username = request.user.username
        shared_repos = []
        
        shared_repos += list_share_repos(username, 'from_email', -1, -1)
        shared_repos += get_group_repos_by_owner(username)
        if not CLOUD_MODE:
            shared_repos += list_inner_pub_repos_by_owner(username)

        return HttpResponse(json.dumps(shared_repos, cls=SearpcObjEncoder),
                            status=200, content_type=json_content_type)
Esempio n. 7
0
def list_priv_shared_folders(request):
    """List private shared folders.
    
    Arguments:
    - `request`:
    """
    username = request.user.username

    shared_repos = []

    # personal repos shared from this user
    shared_repos += seafile_api.get_share_out_repo_list(username, -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

    shared_folders = []
    for repo in shared_repos:
        if not repo.is_virtual:  # skip non-virtual repos
            continue

        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_folders.append(repo)

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

    return render_to_response('share/list_priv_shared_folders.html', {
        'shared_folders': shared_folders,
    },
                              context_instance=RequestContext(request))
Esempio n. 8
0
def get_group_repos_by_owner(request):
    """List repos that @user share to groups.

    Returns:
        A list of repos.
    """
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return get_org_group_repos_by_owner(org_id, username)
    else:
        return seaserv.get_group_repos_by_owner(username)
Esempio n. 9
0
def get_group_repos_by_owner(request):
    """List repos that @user share to groups.

    Returns:
        A list of repos.
    """
    username = request.user.username
    if is_org_context(request):
        org_id = request.user.org.org_id
        return get_org_group_repos_by_owner(org_id, username)
    else:
        return seaserv.get_group_repos_by_owner(username)
Esempio n. 10
0
def list_priv_shared_folders(request):
    """List private shared folders.

    Arguments:
    - `request`:
    """
    username = request.user.username

    shared_repos = []

    # personal repos shared from this user
    shared_repos += seafile_api.get_share_out_repo_list(username, -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

    shared_folders = []
    for repo in shared_repos:
        if not repo.is_virtual:     # skip non-virtual repos
            continue

        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_folders.append(repo)

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

    return render_to_response('share/list_priv_shared_folders.html', {
            'shared_folders': shared_folders,
            }, context_instance=RequestContext(request))
Esempio n. 11
0
def list_shared_repos(request):
    """
    List personal shared repos.
    """
    username = request.user.username

    out_repos = []

    # personal repos shared from this user
    out_repos += seafile_api.get_share_out_repo_list(username, -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
    out_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'
        out_repos += pub_repos

    for repo in out_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

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

    return render_to_response('share/repos.html', {
        "out_repos": out_repos,
    },
                              context_instance=RequestContext(request))
Esempio n. 12
0
def list_shared_repos(request):
    """
    List personal shared repos.
    """
    username = request.user.username

    out_repos = []

    # personal repos shared from this user
    out_repos += seafile_api.get_share_out_repo_list(username, -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
    out_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'
        out_repos += pub_repos

    for repo in out_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

    out_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))
    
    return render_to_response('share/repos.html', {
            "out_repos": out_repos,
            }, context_instance=RequestContext(request))
Esempio n. 13
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))
Esempio n. 14
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))