def share_permission_admin(request): share_type = request.GET.get('share_type', '') content_type = 'application/json; charset=utf-8' form = RepoShareForm(request.POST) form.is_valid() email_or_group = form.cleaned_data['email_or_group'] repo_id = form.cleaned_data['repo_id'] permission = form.cleaned_data['permission'] from_email = request.user.username if share_type == 'personal': try: seafserv_threaded_rpc.set_share_permission(repo_id, from_email, email_or_group, permission) except: return HttpResponse(json.dumps({'success': False}), status=500, content_type=content_type) return HttpResponse(json.dumps({'success': True}), content_type=content_type) if share_type == 'group': try: seafserv_threaded_rpc.set_group_repo_permission(int(email_or_group), repo_id, permission) except: return HttpResponse(json.dumps({'success': False}), status=500, content_type=content_type) return HttpResponse(json.dumps({'success': True}), content_type=content_type) if share_type == 'public': try: seafserv_threaded_rpc.set_inner_pub_repo(repo_id, permission) except: return HttpResponse(json.dumps({'success': False}), status=500, content_type=content_type) return HttpResponse(json.dumps({'success': True}), content_type=content_type)
def share_repo(request): """ Handle POST method to share a repo to public/groups/users based on form data. Return to ``myhome`` page and notify user whether success or failure. """ next = request.META.get('HTTP_REFERER', None) if not next: next = SITE_ROOT form = RepoShareForm(request.POST) if not form.is_valid(): # TODO: may display error msg on form raise Http404 email_or_group = form.cleaned_data['email_or_group'] repo_id = form.cleaned_data['repo_id'] permission = form.cleaned_data['permission'] from_email = request.user.username repo = seafile_api.get_repo(repo_id) if not repo: raise Http404 # Test whether user is the repo owner. if not validate_owner(request, repo_id): msg = _(u'Only the owner of the library has permission to share it.') messages.error(request, msg) return HttpResponseRedirect(next) # Parsing input values. share_to_list = string2list(email_or_group) share_to_all, share_to_group_names, share_to_users = False, [], [] for share_to in share_to_list: if share_to == 'all': share_to_all = True elif share_to.find('@') == -1: share_to_group_names.append(share_to) else: share_to = share_to.lower() if is_valid_username(share_to): share_to_users.append(share_to) share_to_groups = [] # get all personal groups for group in request.user.joined_groups: # for every group that user joined, if group name matchs, # then has find the group if group.group_name in share_to_group_names: share_to_groups.append(group) if share_to_all and not CLOUD_MODE: share_to_public(request, repo, permission) if not check_user_share_quota(from_email, repo, users=share_to_users, groups=share_to_groups): messages.error(request, _('Failed to share "%s", no enough quota. <a href="http://seafile.com/">Upgrade account.</a>') % repo.name) return HttpResponseRedirect(next) for group in share_to_groups: share_to_group(request, repo, from_email, group, permission) for email in share_to_users: # Add email to contacts. mail_sended.send(sender=None, user=request.user.username, email=email) share_to_user(request, repo, from_email, email, permission) return HttpResponseRedirect(next)
def share_repo(request): """ Handle POST method to share a repo to public/groups/users based on form data. Return to ``myhome`` page and notify user whether success or failure. """ next = request.META.get('HTTP_REFERER', None) if not next: next = SITE_ROOT form = RepoShareForm(request.POST) if not form.is_valid(): # TODO: may display error msg on form raise Http404 email_or_group = form.cleaned_data['email_or_group'] repo_id = form.cleaned_data['repo_id'] permission = form.cleaned_data['permission'] from_email = request.user.username repo = seafile_api.get_repo(repo_id) if not repo: raise Http404 # Test whether user is the repo owner. if not validate_owner(request, repo_id): msg = _(u'Only the owner of the library has permission to share it.') messages.error(request, msg) return HttpResponseRedirect(next) # Parsing input values. share_to_list = string2list(email_or_group) share_to_all, share_to_group_names, share_to_users = False, [], [] for share_to in share_to_list: if share_to == 'all': share_to_all = True elif share_to.find('@') == -1: share_to_group_names.append(share_to) else: share_to_users.append(share_to.lower()) share_to_groups = [] # get all personal groups for group in seaserv.get_personal_groups_by_user(from_email): # for every group that user joined, if group name matchs, # then has find the group if group.group_name in share_to_group_names: share_to_groups.append(group) if share_to_all and not CLOUD_MODE: share_to_public(request, repo, permission) if not check_user_share_quota( from_email, repo, users=share_to_users, groups=share_to_groups): messages.error( request, _('Failed to share "%s", no enough quota. <a href="http://seafile.com/">Upgrade account.</a>' ) % repo.name) return HttpResponseRedirect(next) for group in share_to_groups: share_to_group(request, repo, from_email, group, permission) for email in share_to_users: # Add email to contacts. mail_sended.send(sender=None, user=request.user.username, email=email) share_to_user(request, repo, from_email, email, permission) return HttpResponseRedirect(next)
def share_repo(request): """ Handle repo share request """ if request.method != 'POST': raise Http404 form = RepoShareForm(request.POST) if not form.is_valid(): # TODO: may display error msg on form raise Http404 email_or_group = form.cleaned_data['email_or_group'] repo_id = form.cleaned_data['repo_id'] permission = form.cleaned_data['permission'] from_email = request.user.username repo = get_repo(repo_id) if not repo: raise Http404 is_encrypted = True if repo.encrypted else False # Test whether user is the repo owner. if not validate_owner(request, repo_id): return render_permission_error(request, _(u'Only the owner of the library has permission to share it.')) to_email_list = string2list(email_or_group) for to_email in to_email_list: if to_email == 'all': ''' Share to public ''' # ignore 'all' if we're running in cloud mode if not CLOUD_MODE: try: seafserv_threaded_rpc.set_inner_pub_repo(repo_id, permission) except: msg = _(u'Failed to share to all members') message.add_message(request, message.ERROR, msg) continue msg = _(u'Shared to all members successfully, go check it at <a href="%s">Share</a>.') % \ (reverse('share_admin')) messages.add_message(request, messages.INFO, msg) elif to_email.find('@') == -1: ''' Share repo to group ''' # TODO: if we know group id, then we can simplly call group_share_repo group_name = to_email # get all personal groups groups = get_personal_groups(-1, -1) find = False for group in groups: # for every group that user joined, if group name matchs, # then has find the group if group.props.group_name == group_name: from seahub.group.views import group_share_repo group_share_repo(request, repo_id, int(group.props.id), from_email, permission) find = True msg = _(u'Shared to %(group)s successfully,go check it at <a href="%(share)s">Share</a>.') % \ {'group':group_name, 'share':reverse('share_admin')} messages.add_message(request, messages.INFO, msg) break if not find: msg = _(u'Failed to share to %s,as it does not exists.') % group_name messages.add_message(request, messages.ERROR, msg) else: ''' Share repo to user ''' # Add email to contacts. mail_sended.send(sender=None, user=request.user.username, email=to_email) if not is_registered_user(to_email): # Generate shared link and send mail if user has not registered. # kwargs = {'repo_id': repo_id, # 'repo_owner': from_email, # 'anon_email': to_email, # 'is_encrypted': is_encrypted, # } # anonymous_share(request, **kwargs) msg = _(u'Failed to share to %s, as the email is not registered.') % to_email messages.add_message(request, messages.ERROR, msg) continue else: # Record share info to db. try: seafserv_threaded_rpc.add_share(repo_id, from_email, to_email, permission) except SearpcError, e: msg = _(u'Failed to share to %s .') % to_email messages.add_message(request, messages.ERROR, msg) continue msg = _(u'Shared to %(email)s successfully,go check it at <a href="%(share)s">Share</a>.') % \ {'email':to_email, 'share':reverse('share_admin')} messages.add_message(request, messages.INFO, msg)