mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-26 07:22:34 +00:00
rm REPLACE_FROM_EMAIL and other unused code (#6339)
* rm REPLACE_FROM_EMAIL and other unused code * update * update
This commit is contained in:
@@ -16,7 +16,7 @@ from seahub.utils import IS_EMAIL_CONFIGURED, \
|
|||||||
is_valid_email, string2list, gen_shared_link, send_html_email, \
|
is_valid_email, string2list, gen_shared_link, send_html_email, \
|
||||||
get_site_name
|
get_site_name
|
||||||
from seahub.share.models import FileShare
|
from seahub.share.models import FileShare
|
||||||
from seahub.settings import REPLACE_FROM_EMAIL, ADD_REPLY_TO_HEADER
|
from seahub.settings import ADD_REPLY_TO_HEADER
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -84,11 +84,6 @@ class SendShareLinkView(APIView):
|
|||||||
'password': link.get_password(),
|
'password': link.get_password(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if REPLACE_FROM_EMAIL:
|
|
||||||
from_email = useremail
|
|
||||||
else:
|
|
||||||
from_email = None # use default from email
|
|
||||||
|
|
||||||
if ADD_REPLY_TO_HEADER:
|
if ADD_REPLY_TO_HEADER:
|
||||||
reply_to = useremail
|
reply_to = useremail
|
||||||
else:
|
else:
|
||||||
@@ -107,7 +102,7 @@ class SendShareLinkView(APIView):
|
|||||||
|
|
||||||
# send email
|
# send email
|
||||||
try:
|
try:
|
||||||
send_html_email(title, template, c, from_email, [to_email], reply_to=reply_to)
|
send_html_email(title, template, c, None, [to_email], reply_to=reply_to)
|
||||||
result['success'].append(to_email)
|
result['success'].append(to_email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
@@ -15,7 +15,7 @@ from seahub.utils import IS_EMAIL_CONFIGURED, \
|
|||||||
is_valid_email, string2list, gen_shared_upload_link, send_html_email, \
|
is_valid_email, string2list, gen_shared_upload_link, send_html_email, \
|
||||||
get_site_name
|
get_site_name
|
||||||
from seahub.share.models import UploadLinkShare
|
from seahub.share.models import UploadLinkShare
|
||||||
from seahub.settings import REPLACE_FROM_EMAIL, ADD_REPLY_TO_HEADER
|
from seahub.settings import ADD_REPLY_TO_HEADER
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -83,11 +83,6 @@ class SendUploadLinkView(APIView):
|
|||||||
'password': link.get_password(),
|
'password': link.get_password(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if REPLACE_FROM_EMAIL:
|
|
||||||
from_email = useremail
|
|
||||||
else:
|
|
||||||
from_email = None # use default from email
|
|
||||||
|
|
||||||
if ADD_REPLY_TO_HEADER:
|
if ADD_REPLY_TO_HEADER:
|
||||||
reply_to = useremail
|
reply_to = useremail
|
||||||
else:
|
else:
|
||||||
@@ -99,7 +94,7 @@ class SendUploadLinkView(APIView):
|
|||||||
|
|
||||||
# send email
|
# send email
|
||||||
try:
|
try:
|
||||||
send_html_email(title, template, c, from_email, [to_email], reply_to=reply_to)
|
send_html_email(title, template, c, None, [to_email], reply_to=reply_to)
|
||||||
result['success'].append(to_email)
|
result['success'].append(to_email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
@@ -823,9 +823,6 @@ SEADOC_SERVER_URL = 'http://127.0.0.1:7070'
|
|||||||
# Settings for Seahub Priv #
|
# Settings for Seahub Priv #
|
||||||
############################
|
############################
|
||||||
|
|
||||||
# Replace from email to current user instead of email sender.
|
|
||||||
REPLACE_FROM_EMAIL = False
|
|
||||||
|
|
||||||
# Add ``Reply-to`` header, see RFC #822.
|
# Add ``Reply-to`` header, see RFC #822.
|
||||||
ADD_REPLY_TO_HEADER = False
|
ADD_REPLY_TO_HEADER = False
|
||||||
|
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
|
||||||
from django import forms
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class RepoShareForm(forms.Form):
|
|
||||||
"""
|
|
||||||
Form for sharing repo to user or group.
|
|
||||||
"""
|
|
||||||
|
|
||||||
email_or_group = forms.CharField(max_length=512)
|
|
||||||
repo_id = forms.CharField(max_length=36)
|
|
||||||
permission = forms.ChoiceField(choices=(('rw', 'read-write'), ('r', 'read-only')))
|
|
||||||
|
|
||||||
class FileLinkShareForm(forms.Form):
|
|
||||||
"""
|
|
||||||
Form for sharing file shared link to emails.
|
|
||||||
"""
|
|
||||||
|
|
||||||
email = forms.CharField(max_length=512, error_messages={
|
|
||||||
'required': _("Email is required"),
|
|
||||||
'max_length': _("Email is not longer than 512 characters"),
|
|
||||||
})
|
|
||||||
file_shared_link = forms.CharField()
|
|
||||||
extra_msg = forms.CharField(required=False)
|
|
||||||
file_shared_name = forms.CharField()
|
|
||||||
file_shared_type = forms.CharField()
|
|
||||||
|
|
||||||
class UploadLinkShareForm(forms.Form):
|
|
||||||
"""
|
|
||||||
Form for sharing upload link to emails.
|
|
||||||
"""
|
|
||||||
email = forms.CharField(max_length=512, error_messages={
|
|
||||||
'required': _("Email is required"),
|
|
||||||
'max_length': _("Email is not longer than 512 characters"),
|
|
||||||
})
|
|
||||||
shared_upload_link = forms.CharField()
|
|
||||||
extra_msg = forms.CharField(required=False)
|
|
@@ -4,10 +4,8 @@ from django.urls import path
|
|||||||
from .views import *
|
from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('link/send/', send_shared_link, name='send_shared_link'),
|
|
||||||
path('link/save/', save_shared_link, name='save_shared_link'),
|
path('link/save/', save_shared_link, name='save_shared_link'),
|
||||||
path('link/export-excel/', export_shared_link, name='export_shared_link'),
|
path('link/export-excel/', export_shared_link, name='export_shared_link'),
|
||||||
path('upload_link/send/', send_shared_upload_link, name='send_shared_upload_link'),
|
|
||||||
path('ajax/private-share-dir/', ajax_private_share_dir, name='ajax_private_share_dir'),
|
path('ajax/private-share-dir/', ajax_private_share_dir, name='ajax_private_share_dir'),
|
||||||
path('ajax/get-link-audit-code/', ajax_get_link_audit_code, name='ajax_get_link_audit_code'),
|
path('ajax/get-link-audit-code/', ajax_get_link_audit_code, name='ajax_get_link_audit_code'),
|
||||||
]
|
]
|
||||||
|
@@ -5,34 +5,27 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpResponse, HttpResponseRedirect, Http404, \
|
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||||
HttpResponseBadRequest
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext as _, activate
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.html import escape
|
|
||||||
|
|
||||||
import seaserv
|
import seaserv
|
||||||
from seaserv import seafile_api
|
from seaserv import seafile_api
|
||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
|
|
||||||
from seahub.share.forms import FileLinkShareForm, \
|
|
||||||
UploadLinkShareForm
|
|
||||||
from seahub.share.models import FileShare, UploadLinkShare
|
from seahub.share.models import FileShare, UploadLinkShare
|
||||||
from seahub.share.signals import share_repo_to_user_successful
|
from seahub.share.signals import share_repo_to_user_successful
|
||||||
from seahub.auth.decorators import login_required, login_required_ajax
|
from seahub.auth.decorators import login_required, login_required_ajax
|
||||||
from seahub.base.decorators import require_POST
|
from seahub.base.decorators import require_POST
|
||||||
from seahub.contacts.signals import mail_sended
|
from seahub.contacts.signals import mail_sended
|
||||||
from seahub.views import is_registered_user, check_folder_permission
|
from seahub.views import is_registered_user, check_folder_permission
|
||||||
from seahub.utils import string2list, IS_EMAIL_CONFIGURED, check_filename_with_rename, \
|
from seahub.utils import string2list, check_filename_with_rename, \
|
||||||
is_valid_username, is_valid_email, send_html_email, is_org_context, \
|
is_valid_username, is_valid_email, is_org_context, \
|
||||||
gen_token, normalize_cache_key, get_site_name, gen_shared_link
|
gen_token, normalize_cache_key, gen_shared_link
|
||||||
from seahub.utils.mail import send_html_email_with_dj_template
|
from seahub.utils.mail import send_html_email_with_dj_template
|
||||||
from seahub.utils.ms_excel import write_xls
|
from seahub.utils.ms_excel import write_xls
|
||||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||||
from seahub.settings import SITE_ROOT, REPLACE_FROM_EMAIL, \
|
from seahub.settings import SITE_ROOT, SHARE_LINK_AUDIT_CODE_TIMEOUT
|
||||||
ADD_REPLY_TO_HEADER, SHARE_LINK_EMAIL_LANGUAGE, \
|
|
||||||
SHARE_LINK_AUDIT_CODE_TIMEOUT
|
|
||||||
from seahub.profile.models import Profile
|
|
||||||
|
|
||||||
# Get an instance of a logger
|
# Get an instance of a logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -123,95 +116,6 @@ def share_to_user(request, repo, to_user, permission):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# share link
|
|
||||||
@login_required_ajax
|
|
||||||
def send_shared_link(request):
|
|
||||||
"""
|
|
||||||
Handle ajax post request to send file shared link.
|
|
||||||
"""
|
|
||||||
if not request.method == 'POST':
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
|
||||||
|
|
||||||
if not IS_EMAIL_CONFIGURED:
|
|
||||||
data = json.dumps({'error': _('Failed to send email, email service is not properly configured, please contact administrator.')})
|
|
||||||
return HttpResponse(data, status=500, content_type=content_type)
|
|
||||||
|
|
||||||
form = FileLinkShareForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
email = form.cleaned_data['email']
|
|
||||||
file_shared_link = form.cleaned_data['file_shared_link']
|
|
||||||
file_shared_name = form.cleaned_data['file_shared_name']
|
|
||||||
file_shared_type = form.cleaned_data['file_shared_type']
|
|
||||||
extra_msg = escape(form.cleaned_data['extra_msg'])
|
|
||||||
|
|
||||||
to_email_list = string2list(email)
|
|
||||||
send_success, send_failed = [], []
|
|
||||||
# use contact_email, if present
|
|
||||||
username = Profile.objects.get_contact_email_by_user(request.user.username)
|
|
||||||
for to_email in to_email_list:
|
|
||||||
if not is_valid_email(to_email):
|
|
||||||
send_failed.append(to_email)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if SHARE_LINK_EMAIL_LANGUAGE:
|
|
||||||
activate(SHARE_LINK_EMAIL_LANGUAGE)
|
|
||||||
|
|
||||||
# Add email to contacts.
|
|
||||||
mail_sended.send(sender=None, user=request.user.username,
|
|
||||||
email=to_email)
|
|
||||||
|
|
||||||
c = {
|
|
||||||
'email': request.user.username,
|
|
||||||
'to_email': to_email,
|
|
||||||
'file_shared_link': file_shared_link,
|
|
||||||
'file_shared_name': file_shared_name,
|
|
||||||
}
|
|
||||||
|
|
||||||
if extra_msg:
|
|
||||||
c['extra_msg'] = extra_msg
|
|
||||||
|
|
||||||
if REPLACE_FROM_EMAIL:
|
|
||||||
from_email = username
|
|
||||||
else:
|
|
||||||
from_email = None # use default from email
|
|
||||||
|
|
||||||
if ADD_REPLY_TO_HEADER:
|
|
||||||
reply_to = username
|
|
||||||
else:
|
|
||||||
reply_to = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
if file_shared_type == 'f':
|
|
||||||
c['file_shared_type'] = _("file")
|
|
||||||
send_html_email(_('A file is shared to you on %s') % get_site_name(),
|
|
||||||
'shared_link_email.html',
|
|
||||||
c, from_email, [to_email],
|
|
||||||
reply_to=reply_to
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
c['file_shared_type'] = _("directory")
|
|
||||||
send_html_email(_('A directory is shared to you on %s') % get_site_name(),
|
|
||||||
'shared_link_email.html',
|
|
||||||
c, from_email, [to_email],
|
|
||||||
reply_to=reply_to)
|
|
||||||
|
|
||||||
send_success.append(to_email)
|
|
||||||
except Exception:
|
|
||||||
send_failed.append(to_email)
|
|
||||||
|
|
||||||
if len(send_success) > 0:
|
|
||||||
data = json.dumps({"send_success": send_success, "send_failed": send_failed})
|
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
|
||||||
else:
|
|
||||||
data = json.dumps({"error": _("Internal server error, or please check the email(s) you entered")})
|
|
||||||
return HttpResponse(data, status=400, content_type=content_type)
|
|
||||||
else:
|
|
||||||
return HttpResponseBadRequest(json.dumps(form.errors),
|
|
||||||
content_type=content_type)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def save_shared_link(request):
|
def save_shared_link(request):
|
||||||
"""Save public share link to one's library.
|
"""Save public share link to one's library.
|
||||||
@@ -335,78 +239,6 @@ def export_shared_link(request):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@login_required_ajax
|
|
||||||
def send_shared_upload_link(request):
|
|
||||||
"""
|
|
||||||
Handle ajax post request to send shared upload link.
|
|
||||||
"""
|
|
||||||
if not request.method == 'POST':
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
|
||||||
|
|
||||||
if not IS_EMAIL_CONFIGURED:
|
|
||||||
data = json.dumps({'error': _('Failed to send email, email service is not properly configured, please contact administrator.')})
|
|
||||||
return HttpResponse(data, status=500, content_type=content_type)
|
|
||||||
|
|
||||||
form = UploadLinkShareForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
email = form.cleaned_data['email']
|
|
||||||
shared_upload_link = form.cleaned_data['shared_upload_link']
|
|
||||||
extra_msg = escape(form.cleaned_data['extra_msg'])
|
|
||||||
|
|
||||||
to_email_list = string2list(email)
|
|
||||||
send_success, send_failed = [], []
|
|
||||||
# use contact_email, if present
|
|
||||||
username = Profile.objects.get_contact_email_by_user(request.user.username)
|
|
||||||
for to_email in to_email_list:
|
|
||||||
if not is_valid_email(to_email):
|
|
||||||
send_failed.append(to_email)
|
|
||||||
continue
|
|
||||||
# Add email to contacts.
|
|
||||||
mail_sended.send(sender=None, user=request.user.username,
|
|
||||||
email=to_email)
|
|
||||||
|
|
||||||
c = {
|
|
||||||
'email': request.user.username,
|
|
||||||
'to_email': to_email,
|
|
||||||
'shared_upload_link': shared_upload_link,
|
|
||||||
}
|
|
||||||
|
|
||||||
if extra_msg:
|
|
||||||
c['extra_msg'] = extra_msg
|
|
||||||
|
|
||||||
if REPLACE_FROM_EMAIL:
|
|
||||||
from_email = username
|
|
||||||
else:
|
|
||||||
from_email = None # use default from email
|
|
||||||
|
|
||||||
if ADD_REPLY_TO_HEADER:
|
|
||||||
reply_to = username
|
|
||||||
else:
|
|
||||||
reply_to = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
send_html_email(_('An upload link is shared to you on %s') % get_site_name(),
|
|
||||||
'shared_upload_link_email.html',
|
|
||||||
c, from_email, [to_email],
|
|
||||||
reply_to=reply_to)
|
|
||||||
|
|
||||||
send_success.append(to_email)
|
|
||||||
except Exception:
|
|
||||||
send_failed.append(to_email)
|
|
||||||
|
|
||||||
if len(send_success) > 0:
|
|
||||||
data = json.dumps({"send_success": send_success, "send_failed": send_failed})
|
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
|
||||||
else:
|
|
||||||
data = json.dumps({"error": _("Internal server error, or please check the email(s) you entered")})
|
|
||||||
return HttpResponse(data, status=400, content_type=content_type)
|
|
||||||
else:
|
|
||||||
return HttpResponseBadRequest(json.dumps(form.errors),
|
|
||||||
content_type=content_type)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required_ajax
|
@login_required_ajax
|
||||||
@require_POST
|
@require_POST
|
||||||
def ajax_private_share_dir(request):
|
def ajax_private_share_dir(request):
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
#coding: UTF-8
|
# coding: UTF-8
|
||||||
import json
|
import json
|
||||||
from mock import patch
|
from mock import patch
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
|
||||||
from seahub.share.models import FileShare
|
from seahub.share.models import FileShare
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
from seahub.profile.utils import refresh_cache
|
from seahub.profile.utils import refresh_cache
|
||||||
@@ -16,7 +15,7 @@ class SendShareLinkApiTest(BaseTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
fs = FileShare.objects.create_file_link(self.user.username,
|
fs = FileShare.objects.create_file_link(self.user.username,
|
||||||
self.repo.id, self.file, None)
|
self.repo.id, self.file, None)
|
||||||
|
|
||||||
self.token = fs.token
|
self.token = fs.token
|
||||||
mail.outbox = []
|
mail.outbox = []
|
||||||
@@ -47,7 +46,6 @@ class SendShareLinkApiTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
||||||
def test_can_send_email_rewrite(self):
|
def test_can_send_email_rewrite(self):
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
@@ -63,17 +61,15 @@ class SendShareLinkApiTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['success'][0] == self.admin.email
|
assert json_resp['success'][0] == self.admin.email
|
||||||
assert 'test.txt' in mail.outbox[0].body
|
assert 'test.txt' in mail.outbox[0].body
|
||||||
assert mail.outbox[0].from_email == self.user.email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
||||||
def test_can_send_email_rewrite_contact_email(self):
|
def test_can_send_email_rewrite_contact_email(self):
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
nickname = 'Testuser'
|
nickname = 'Testuser'
|
||||||
contact_email= 'contact_email@test.com'
|
contact_email = 'contact_email@test.com'
|
||||||
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
||||||
p.contact_email = contact_email
|
p.contact_email = contact_email
|
||||||
p.save()
|
p.save()
|
||||||
@@ -92,7 +88,6 @@ class SendShareLinkApiTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['success'][0] == self.admin.email
|
assert json_resp['success'][0] == self.admin.email
|
||||||
assert 'test.txt' in mail.outbox[0].body
|
assert 'test.txt' in mail.outbox[0].body
|
||||||
assert mail.outbox[0].from_email == contact_email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
#coding: UTF-8
|
# coding: UTF-8
|
||||||
import json
|
import json
|
||||||
from mock import patch
|
from mock import patch
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
|
||||||
from seahub.share.models import UploadLinkShare
|
from seahub.share.models import UploadLinkShare
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
from seahub.profile.utils import refresh_cache
|
from seahub.profile.utils import refresh_cache
|
||||||
@@ -16,7 +15,7 @@ class SendUploadLinkApiTest(BaseTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
uls = UploadLinkShare.objects.create_upload_link_share(self.user.username,
|
uls = UploadLinkShare.objects.create_upload_link_share(self.user.username,
|
||||||
self.repo.id, '/')
|
self.repo.id, '/')
|
||||||
self.token = uls.token
|
self.token = uls.token
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@@ -44,7 +43,6 @@ class SendUploadLinkApiTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.api2.endpoints.send_upload_link_email.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
||||||
def test_can_send_email_rewrite(self):
|
def test_can_send_email_rewrite(self):
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
@@ -59,17 +57,15 @@ class SendUploadLinkApiTest(BaseTestCase):
|
|||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['success'][0] == self.admin.email
|
assert json_resp['success'][0] == self.admin.email
|
||||||
assert mail.outbox[0].from_email == self.user.email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.IS_EMAIL_CONFIGURED', True)
|
@patch('seahub.api2.endpoints.send_upload_link_email.IS_EMAIL_CONFIGURED', True)
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
||||||
def test_can_send_email_rewrite_contact_email(self):
|
def test_can_send_email_rewrite_contact_email(self):
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
nickname = 'Testuser'
|
nickname = 'Testuser'
|
||||||
contact_email= 'contact_email@test.com'
|
contact_email = 'contact_email@test.com'
|
||||||
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
||||||
p.contact_email = contact_email
|
p.contact_email = contact_email
|
||||||
p.save()
|
p.save()
|
||||||
@@ -87,7 +83,6 @@ class SendUploadLinkApiTest(BaseTestCase):
|
|||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['success'][0] == self.admin.email
|
assert json_resp['success'][0] == self.admin.email
|
||||||
assert mail.outbox[0].from_email == contact_email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
||||||
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
|
@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
|
||||||
|
@@ -1,80 +0,0 @@
|
|||||||
from mock import patch
|
|
||||||
from django.core import mail
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.test import override_settings
|
|
||||||
|
|
||||||
from seahub.profile.models import Profile
|
|
||||||
from seahub.profile.utils import refresh_cache
|
|
||||||
from seahub.test_utils import BaseTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class SendSharedLinkTest(BaseTestCase):
|
|
||||||
def setUp(self):
|
|
||||||
mail.outbox = []
|
|
||||||
|
|
||||||
@override_settings(DEFAULT_FROM_EMAIL='from_noreply@seafile.com')
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'file_shared_link': 'http://xxx',
|
|
||||||
'file_shared_name': 'xxx',
|
|
||||||
'file_shared_type': 'd',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == 'from_noreply@seafile.com'
|
|
||||||
|
|
||||||
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send_from_replyto_rewrite(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'file_shared_link': 'http://xxx',
|
|
||||||
'file_shared_name': 'xxx',
|
|
||||||
'file_shared_type': 'd',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == self.user.email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
|
||||||
|
|
||||||
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send_from_replyto_rewrite_contact_email(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
nickname = 'Testuser'
|
|
||||||
contact_email= 'contact_email@test.com'
|
|
||||||
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
|
||||||
p.contact_email = contact_email
|
|
||||||
p.save()
|
|
||||||
|
|
||||||
refresh_cache(self.user.email)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'file_shared_link': 'http://xxx',
|
|
||||||
'file_shared_name': 'xxx',
|
|
||||||
'file_shared_type': 'd',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == contact_email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
|
@@ -1,74 +0,0 @@
|
|||||||
from mock import patch
|
|
||||||
from django.core import mail
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.test import override_settings
|
|
||||||
|
|
||||||
from seahub.profile.models import Profile
|
|
||||||
from seahub.profile.utils import refresh_cache
|
|
||||||
from seahub.test_utils import BaseTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class SendSharedUploadLinkTest(BaseTestCase):
|
|
||||||
def setUp(self):
|
|
||||||
mail.outbox = []
|
|
||||||
|
|
||||||
@override_settings(DEFAULT_FROM_EMAIL='from_noreply@seafile.com')
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_upload_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'shared_upload_link': 'http://xxx',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == 'from_noreply@seafile.com'
|
|
||||||
|
|
||||||
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send_from_replyto_rewrite(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_upload_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'shared_upload_link': 'http://xxx',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == self.user.email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
|
|
||||||
|
|
||||||
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
|
|
||||||
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
|
|
||||||
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
|
|
||||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
|
|
||||||
def test_can_send_from_replyto_rewrite_contact_email(self):
|
|
||||||
self.login_as(self.user)
|
|
||||||
nickname = 'Testuser'
|
|
||||||
contact_email= 'contact_email@test.com'
|
|
||||||
p = Profile.objects.add_or_update(self.user.email, nickname=nickname)
|
|
||||||
p.contact_email = contact_email
|
|
||||||
p.save()
|
|
||||||
|
|
||||||
refresh_cache(self.user.email)
|
|
||||||
|
|
||||||
resp = self.client.post(reverse('send_shared_upload_link'), {
|
|
||||||
'email': self.user.email,
|
|
||||||
'shared_upload_link': 'http://xxx',
|
|
||||||
'extra_msg': ''
|
|
||||||
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
|
||||||
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
|
|
||||||
assert mail.outbox[0].from_email == contact_email
|
|
||||||
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
|
|
Reference in New Issue
Block a user