def gen_private_file_share(request, repo_id): emails = request.POST.getlist('emails', '') s_type = request.POST.get('s_type', '') path = request.POST.get('path', '') perm = request.POST.get('perm', 'r') file_or_dir = os.path.basename(path.rstrip('/')) username = request.user.username for email in [e.strip() for e in emails if e.strip()]: if not is_valid_username(email): continue if not is_registered_user(email): messages.error(request, _('Failed to share to "%s", user not found.') % email) continue if s_type == 'f': pfds = PrivateFileDirShare.objects.add_read_only_priv_file_share( username, email, repo_id, path) elif s_type == 'd': pfds = PrivateFileDirShare.objects.add_private_dir_share( username, email, repo_id, path, perm) else: continue # send a signal when sharing file successful share_file_to_user_successful.send(sender=None, priv_share_obj=pfds) messages.success(request, _('Successfully shared %s.') % file_or_dir) next = request.META.get('HTTP_REFERER', None) if not next: next = SITE_ROOT return HttpResponseRedirect(next)
def gen_private_file_share(request, repo_id): emails = request.POST.getlist('emails', '') s_type = request.POST.get('s_type', '') path = request.POST.get('path', '') perm = request.POST.get('perm', 'r') file_or_dir = os.path.basename(path.rstrip('/')) username = request.user.username for email in [e.strip() for e in emails if e.strip()]: if not is_valid_username(email): continue if not is_registered_user(email): messages.error( request, _('Failed to share to "%s", user not found.') % email) continue if s_type == 'f': pfds = PrivateFileDirShare.objects.add_read_only_priv_file_share( username, email, repo_id, path) elif s_type == 'd': pfds = PrivateFileDirShare.objects.add_private_dir_share( username, email, repo_id, path, perm) else: continue # send a signal when sharing file successful share_file_to_user_successful.send(sender=None, priv_share_obj=pfds) messages.success(request, _('Successfully shared %s.') % file_or_dir) next = request.META.get('HTTP_REFERER', None) if not next: next = SITE_ROOT return HttpResponseRedirect(next)