mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 16:10:26 +00:00
Fixed sending file shared link bug
This commit is contained in:
7
forms.py
7
forms.py
@@ -45,8 +45,11 @@ class FileLinkShareForm(forms.Form):
|
|||||||
Form for sharing file shared link to emails.
|
Form for sharing file shared link to emails.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
email = forms.CharField(max_length=512)
|
email = forms.CharField(max_length=512, error_messages={
|
||||||
file_shared_link = forms.CharField(max_length=40)
|
'required': '输入不能为空',
|
||||||
|
'max_length': '邮箱太长,不超过512个字符'
|
||||||
|
})
|
||||||
|
file_shared_link = forms.CharField()
|
||||||
|
|
||||||
class FileCommentForm(forms.Form):
|
class FileCommentForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
|
@@ -267,7 +267,7 @@ function apply_form_error(formid, error_msg) {
|
|||||||
var form_err = $("#" + formid + " .error"),
|
var form_err = $("#" + formid + " .error"),
|
||||||
container = $("#simplemodal-container");
|
container = $("#simplemodal-container");
|
||||||
|
|
||||||
form_err.html(error_msg).attr('class', 'error');
|
form_err.html(error_msg).attr('class', 'error').removeClass('hide');
|
||||||
container.css('height', $('#'+formid).height());
|
container.css('height', $('#'+formid).height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -77,10 +77,9 @@
|
|||||||
<label>邮箱(多个邮箱以,分隔):</label><br />
|
<label>邮箱(多个邮箱以,分隔):</label><br />
|
||||||
<textarea id="email" name="email"></textarea><br />
|
<textarea id="email" name="email"></textarea><br />
|
||||||
<input type="hidden" name="file_shared_link" value="{{ file_shared_link }}" />
|
<input type="hidden" name="file_shared_link" value="{{ file_shared_link }}" />
|
||||||
<p id="error" class="hide">输入不能为空。</p>
|
|
||||||
<input type="submit" value="提交" class="submit" />
|
<input type="submit" value="提交" class="submit" />
|
||||||
<p id="sending" class="hide">发送中...</p>
|
<p class="error hide"></p>
|
||||||
<p id="success" class="hide"></p>
|
<p id="sending" class="hide">发送中...</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div id="open-local-feedback" class="hide">
|
<div id="open-local-feedback" class="hide">
|
||||||
@@ -233,42 +232,36 @@ $('#send-shared-link').click(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#link-send-form").submit(function(event) {
|
$("#link-send-form").submit(function(event) {
|
||||||
$('#error, #sending, #success').attr('class', 'hide');
|
$('#link-send-form .error').addClass('hide');
|
||||||
|
$('#sending').removeClass('hide');
|
||||||
|
|
||||||
var form = $(this),
|
var form = $(this),
|
||||||
file_shared_link = form.children('input[name="file_shared_link"]').val(),
|
file_shared_link = form.children('input[name="file_shared_link"]').val(),
|
||||||
email = $.trim(form.children('textarea[name="email"]').val());
|
email = $.trim(form.children('textarea[name="email"]').val());
|
||||||
|
|
||||||
if (!email) {
|
|
||||||
$('#error').attr('class', 'error');
|
|
||||||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#sending').removeClass('hide');
|
|
||||||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
|
||||||
|
|
||||||
if (email.length <= 512) {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "{{ SITE_ROOT }}sharedlink/send/",
|
url: "{% url 'seahub.views.send_shared_link' %}",
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
beforeSend: prepareCSRFToken,
|
beforeSend: prepareCSRFToken,
|
||||||
data: {file_shared_link: file_shared_link, email: email},
|
data: {file_shared_link: file_shared_link, email: email},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#sending').attr('class', 'hide');
|
location.reload(true);
|
||||||
$('#success').html(data[0]['msg']).removeClass('hide');
|
|
||||||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
|
||||||
},
|
},
|
||||||
error: function(xhr, ajaxOptions, thrownError) {
|
error: function(data, textStatus, jqXHR) {
|
||||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
$('#sending').addClass('hide');
|
||||||
$('#sending').attr('class', 'hide');
|
var errors = $.parseJSON(data.responseText);
|
||||||
$('#error').html(jsonVal[0]['error']).attr('class','error');
|
$.each(errors, function(index, value) {
|
||||||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
if (index == 'error') {
|
||||||
|
apply_form_error('link-send-form', value);
|
||||||
|
} else {
|
||||||
|
apply_form_error('link-send-form', value[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
63
views.py
63
views.py
@@ -2213,47 +2213,46 @@ def remove_shared_link(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def send_shared_link(request):
|
def send_shared_link(request):
|
||||||
"""
|
"""
|
||||||
Handle ajax post request to share file shared link.
|
Handle ajax post request to send file shared link.
|
||||||
"""
|
"""
|
||||||
if not request.is_ajax() and not request.method == 'POST':
|
if not request.is_ajax() and not request.method == 'POST':
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
|
result = {}
|
||||||
content_type = 'application/json; charset=utf-8'
|
content_type = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
form = FileLinkShareForm(request.POST)
|
form = FileLinkShareForm(request.POST)
|
||||||
if not form.is_valid():
|
if form.is_valid():
|
||||||
err = '发送失败'
|
email = form.cleaned_data['email']
|
||||||
data = json.dumps([{'error':err}])
|
file_shared_link = form.cleaned_data['file_shared_link']
|
||||||
return HttpResponse(data, status=400, content_type=content_type)
|
|
||||||
|
|
||||||
email = form.cleaned_data['email']
|
t = loader.get_template('shared_link_email.html')
|
||||||
file_shared_link = form.cleaned_data['file_shared_link']
|
to_email_list = string2list(email)
|
||||||
|
for to_email in to_email_list:
|
||||||
|
# Add email to contacts.
|
||||||
|
mail_sended.send(sender=None, user=request.user.username,
|
||||||
|
email=to_email)
|
||||||
|
|
||||||
t = loader.get_template('shared_link_email.html')
|
c = {
|
||||||
to_email_list = string2list(email)
|
'email': request.user.username,
|
||||||
for to_email in to_email_list:
|
'to_email': to_email,
|
||||||
# Add email to contacts
|
'file_shared_link': file_shared_link,
|
||||||
mail_sended.send(sender=None, user=request.user.username,
|
}
|
||||||
email=to_email)
|
|
||||||
|
|
||||||
c = {
|
try:
|
||||||
'email': request.user.username,
|
send_mail('您的好友通过SeaCloud分享了一个文件给您',
|
||||||
'to_email': to_email,
|
t.render(Context(c)), None, [to_email],
|
||||||
'file_shared_link': file_shared_link,
|
fail_silently=False)
|
||||||
}
|
except:
|
||||||
|
data = json.dumps({'error':u'发送失败'})
|
||||||
try:
|
return HttpResponse(data, status=500, content_type=content_type)
|
||||||
send_mail('您的好友通过SeaCloud分享了一个文件给您',
|
|
||||||
t.render(Context(c)), None, [to_email],
|
data = json.dumps("success")
|
||||||
fail_silently=False)
|
messages.add_message(request, messages.INFO, u'发送成功')
|
||||||
except:
|
return HttpResponse(data, status=200, content_type=content_type)
|
||||||
err = '发送失败'
|
else:
|
||||||
data = json.dumps([{'error':err}])
|
return HttpResponseBadRequest(json.dumps(form.errors),
|
||||||
return HttpResponse(data, status=500, content_type=content_type)
|
content_type=content_type)
|
||||||
|
|
||||||
msg = '发送成功。'
|
|
||||||
data = json.dumps([{'msg': msg}])
|
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
|
||||||
|
|
||||||
def document_prepare(raw_path, obj_id, doctype):
|
def document_prepare(raw_path, obj_id, doctype):
|
||||||
curl = DOCUMENT_CONVERTOR_ROOT + 'convert'
|
curl = DOCUMENT_CONVERTOR_ROOT + 'convert'
|
||||||
|
Reference in New Issue
Block a user