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) group = get_group(group_id) if not group: return json_error(_(u'Failed to create: the group does not exist.')) # Check whether user belongs to the group. username = request.user.username if not is_group_user(group_id, 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(str(form.errors.values()[0])) # Form is valid, create group repo repo_name = form.cleaned_data['repo_name'] repo_desc = form.cleaned_data['repo_desc'] permission = form.cleaned_data['permission'] encryption = int(form.cleaned_data['encryption']) uuid = form.cleaned_data['uuid'] magic_str = form.cleaned_data['magic_str'] encrypted_file_key = form.cleaned_data['encrypted_file_key'] if is_org_context(request): org_id = request.user.org.org_id try: if encryption: repo_id = seafile_api.create_org_enc_repo(uuid, repo_name, repo_desc, username, magic_str, encrypted_file_key, enc_version=2, org_id=org_id) else: repo_id = seafile_api.create_org_repo(repo_name, repo_desc, username, None, org_id) except SearpcError, e: logger.error(e) return json_error(_(u'Failed to create')) try: seafile_api.add_org_group_repo(repo_id, org_id, group.id, username, permission) except SearpcError, e: logger.error(e) return json_error(_(u'Failed to create: internal error.'))
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:
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) group = get_group(group_id) if not group: return json_error(_(u'Failed to create: the group does not exist.')) # Check whether user belongs to the group. username = request.user.username if not is_group_user(group_id, 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(str(form.errors.values()[0])) # Form is valid, create group repo repo_name = form.cleaned_data['repo_name'] repo_desc = form.cleaned_data['repo_desc'] permission = form.cleaned_data['permission'] encryption = int(form.cleaned_data['encryption']) uuid = form.cleaned_data['uuid'] magic_str = form.cleaned_data['magic_str'] encrypted_file_key = form.cleaned_data['encrypted_file_key'] if is_org_context(request): org_id = request.user.org.org_id try: if encryption: repo_id = seafile_api.create_org_enc_repo( uuid, repo_name, repo_desc, username, magic_str, encrypted_file_key, enc_version=2, org_id=org_id) else: repo_id = seafile_api.create_org_repo(repo_name, repo_desc, username, None, org_id) except SearpcError, e: logger.error(e) return json_error(_(u'Failed to create')) try: seafile_api.add_org_group_repo(repo_id, org_id, group.id, username, permission) except SearpcError, e: logger.error(e) return json_error(_(u'Failed to create: internal error.'))
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)