Esempio n. 1
0
def org_repo_create(request, url_prefix):
    """
    Handle ajax post to create org repo, this repo is only accessiable by owner.
    """
    if not request.is_ajax() or request.method != "POST":
        return Http404

    result = {}
    content_type = "application/json; charset=utf-8"

    form = RepoCreateForm(request.POST)
    if form.is_valid():
        repo_name = form.cleaned_data["repo_name"]
        repo_desc = form.cleaned_data["repo_desc"]
        encrypted = form.cleaned_data["encryption"]
        passwd = form.cleaned_data["passwd"]
        passwd_again = form.cleaned_data["passwd_again"]

        user = request.user.username
        org = get_user_current_org(request.user.username, url_prefix)
        if not org:
            return HttpResponse(
                json.dumps(_(u"Failed to create: you has not joined this organization")), content_type=content_type
            )

        repo_id = create_org_repo(repo_name, repo_desc, user, passwd, org.org_id)
        if not repo_id:
            result["error"] = _(u"Failed to create")
        else:
            result["success"] = True
            repo_created.send(sender=None, org_id=org.org_id, creator=user, repo_id=repo_id, repo_name=repo_name)
        return HttpResponse(json.dumps(result), content_type=content_type)
    else:
        return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)
Esempio n. 2
0
def create_group_repo(request, group_id):
    """Create a repo and share it to current group"""

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

    def json_error(err_msg):
        result = {'error': [err_msg]}
        return HttpResponseBadRequest(json.dumps(result),
                                      content_type=content_type)
    group_id = int(group_id)
    if not get_group(group_id):
        return json_error(_(u'Failed to create: the group does not exist.'))

    # Check whether user belongs to the group.
    if not is_group_user(group_id, request.user.username):
        return json_error(_(u'Failed to create: you are not in the group.'))

    form = SharedRepoCreateForm(request.POST)
    if not form.is_valid():
        return json_error(form.errors)
    else:
        repo_name = form.cleaned_data['repo_name']
        repo_desc = form.cleaned_data['repo_desc']
        permission = form.cleaned_data['permission']
        encrypted = form.cleaned_data['encryption']
        passwd = form.cleaned_data['passwd']
        user = request.user.username

        org, base_template = check_and_get_org_by_group(group_id, user)
        if org:
            # create group repo in org context
            try:
                repo_id = create_org_repo(repo_name, repo_desc, user, passwd,
                                          org.org_id)
            except:
                repo_id = None
            if not repo_id:
                return json_error(_(u'Failed to create'))

            try:
                status = seafserv_threaded_rpc.add_org_group_repo(repo_id,
                                                                  org.org_id,
                                                                  group_id,
                                                                  user,
                                                                  permission)
            except SearpcError, e:
                status = -1
                
            # if share failed, remove the newly created repo
            if status != 0:
                seafserv_threaded_rpc.remove_repo(repo_id)
                return json_error(_(u'Failed to create: internal error.'))
            else:
                result = {'success': True}
                return HttpResponse(json.dumps(result),
                                    content_type=content_type)
        else:
Esempio n. 3
0
def org_inner_pub_repo_create(request, url_prefix):
    """
    Handle ajax post to create org inner pub repo, this repo is accessiable by
    all org members.
    """    
    if not request.is_ajax() or request.method != 'POST':
        return Http404

    result = {}
    content_type = 'application/json; charset=utf-8'

    form = SharedRepoCreateForm(request.POST)
    if form.is_valid():
        repo_name = form.cleaned_data['repo_name']
        repo_desc = form.cleaned_data['repo_desc']
        permission = form.cleaned_data['permission']
        passwd = form.cleaned_data['passwd']
        user = request.user.username
        org = get_user_current_org(request.user.username, url_prefix)
        if not org:
            return HttpResponse(json.dumps(_(u'Failed to create the library: you has not joined this organizatioin.')),
                                content_type=content_type)
        
        try:
            # create a org repo 
            repo_id = create_org_repo(repo_name, repo_desc, user, passwd,
                                      org.org_id)
            # set org inner pub
            seafserv_threaded_rpc.set_org_inner_pub_repo(org.org_id, repo_id, permission)
        except:
            repo_id = None
        if not repo_id:
            result['error'] = _(u"Failed to create.")
        else:
            result['success'] = True
            repo_created.send(sender=None,
                              org_id=org.org_id,
                              creator=user,
                              repo_id=repo_id,
                              repo_name=repo_name)
        return HttpResponse(json.dumps(result), content_type=content_type)
    else:
        return HttpResponseBadRequest(json.dumps(form.errors),
                                      content_type=content_type)