Example #1
0
def list_share_out_repos(request):
    shared_repos = []

    # repos shared from this user
    shared_repos += get_share_out_repo_list(request)

    # 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

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

    return shared_repos
Example #2
0
def group_add(request, gid):
    group_id_int = int(gid)  # Checked by URL Conf

    if not check_group_staff(group_id_int, request.user.username):
        raise Http404

    group = ccnet_threaded_rpc.get_group(group_id_int)
    if not group:
        return HttpResponseRedirect(reverse('group_list', args=[]))

    # change navigator when user in diffent context
    org, base_template = check_and_get_org_by_group(group_id_int,
                                                    request.user.username)

    form = GroupAvatarForm(request.POST or None, request.FILES or None)

    if request.method == 'POST' and 'avatar' in request.FILES:
        if form.is_valid():
            image_file = request.FILES['avatar']
            avatar = GroupAvatar()
            avatar.group_id = gid
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            # invalidate group avatar cache
            invalidate_group_cache(gid)

            messages.success(request,
                             _("Successfully uploaded a new group avatar."))
        else:
            messages.error(request, form.errors['avatar'])

        return HttpResponseRedirect(_get_next(request))
    else:
        # Only allow post request to change group avatar.
        raise Http404
Example #3
0
def list_share_out_repos(request):
    shared_repos = []

    # repos shared from this user
    shared_repos += get_share_out_repo_list(request)

    # 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

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

    return shared_repos
Example #4
0
def group_add(request, gid):
    group_id_int = int(gid)     # Checked by URL Conf

    if not check_group_staff(group_id_int, request.user):
        raise Http404

    group = ccnet_threaded_rpc.get_group(group_id_int)
    if not group:
        return HttpResponseRedirect(reverse('group_list', args=[]))

    # change navigator when user in diffent context
    org, base_template = check_and_get_org_by_group(group_id_int,
                                                    request.user.username)
    
    form = GroupAvatarForm(request.POST or None, request.FILES or None)

    if request.method == 'POST' and 'avatar' in request.FILES:
        if form.is_valid():
            image_file = request.FILES['avatar']
            avatar = GroupAvatar()
            avatar.group_id = gid
            avatar.avatar.save(image_file.name, image_file)
            avatar.save()
            # invalidate group avatar cache
            invalidate_group_cache(gid)

            messages.success(request, _("Successfully uploaded a new group avatar."))
        else:
            messages.error(request, form.errors['avatar'])

        return HttpResponseRedirect(_get_next(request))
    else:
        # Only allow post request to change group avatar.
         raise Http404   
Example #5
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))
Example #6
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))
Example #7
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))
Example #8
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))
Example #9
0
 def create_group(self, **kwargs):
     group_name = kwargs['group_name']
     username = kwargs['username']
     group_id = ccnet_threaded_rpc.create_group(group_name, username)
     return ccnet_threaded_rpc.get_group(group_id)
Example #10
0
 def create_group(self, **kwargs):
     group_name = kwargs['group_name']
     username = kwargs['username']
     group_id = ccnet_threaded_rpc.create_group(group_name, username)
     return ccnet_threaded_rpc.get_group(group_id)
Example #11
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))
Example #12
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))
Example #13
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),
    )
Example #14
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))