mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
Merge branch 'master' into 12.0
This commit is contained in:
@@ -7,6 +7,7 @@ const propTypes = {
|
||||
customSelectorToggle: PropTypes.object,
|
||||
menuCustomClass: PropTypes.string,
|
||||
isDropdownToggleShown: PropTypes.bool,
|
||||
isDropdownToggleShown: PropTypes.bool,
|
||||
currentSelectedOption: PropTypes.object,
|
||||
options: PropTypes.array.isRequired,
|
||||
selectOption: PropTypes.func.isRequired,
|
||||
|
@@ -29,9 +29,6 @@ class CustomSharePermissionsView(APIView):
|
||||
"""List custom share permissions
|
||||
"""
|
||||
# permission check
|
||||
if not request.user.permissions.can_share_repo():
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||
|
||||
if not check_folder_permission(request, repo_id, '/'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
@@ -104,9 +101,6 @@ class CustomSharePermissionView(APIView):
|
||||
"""get a custom share permission
|
||||
"""
|
||||
# permission check
|
||||
if not request.user.permissions.can_share_repo():
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||
|
||||
if not check_folder_permission(request, repo_id, '/'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
@@ -202,9 +202,6 @@ class DirSharedItemsEndpoint(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
"""List shared items(shared to users/groups) for a folder/library.
|
||||
"""
|
||||
if not request.user.permissions.can_share_repo():
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||
|
||||
repo = seafile_api.get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library %s not found.' % repo_id)
|
||||
|
@@ -18,8 +18,10 @@ from seahub.api2.utils import api_error
|
||||
from seaserv import seafile_api
|
||||
|
||||
from seahub.utils.repo import get_available_repo_perms, get_repo_owner
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email
|
||||
from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE
|
||||
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.ocm.models import OCMShareReceived, OCMShare
|
||||
from seahub.ocm.settings import ENABLE_OCM, SUPPORTED_OCM_PROTOCOLS, \
|
||||
OCM_SEAFILE_PROTOCOL, OCM_RESOURCE_TYPE_LIBRARY, OCM_API_VERSION, \
|
||||
@@ -198,10 +200,11 @@ class OCMSharesView(APIView):
|
||||
else:
|
||||
permission = PERMISSION_READ
|
||||
|
||||
share_with_ccnet_email = Profile.objects.get_username_by_contact_email(share_with)
|
||||
OCMShareReceived.objects.add(
|
||||
shared_secret=shared_secret,
|
||||
from_user=sender,
|
||||
to_user=share_with,
|
||||
to_user=share_with_ccnet_email or share_with,
|
||||
from_server_url=from_server_url,
|
||||
repo_id=repo_id,
|
||||
repo_name=repo_name,
|
||||
@@ -364,16 +367,15 @@ class OCMSharesPrepareView(APIView):
|
||||
consumer_protocol = get_remote_protocol(to_server_url + OCM_PROTOCOL_URL)
|
||||
|
||||
shared_secret = gen_shared_secret()
|
||||
from_user = username
|
||||
post_data = {
|
||||
'shareWith': to_user,
|
||||
'name': repo.repo_name,
|
||||
'description': '',
|
||||
'providerId': OCM_PROVIDER_ID,
|
||||
'owner': repo_owner,
|
||||
'sender': from_user,
|
||||
'sender': email2contact_email(username),
|
||||
'ownerDisplayName': email2nickname(repo_owner),
|
||||
'senderDisplayName': email2nickname(from_user),
|
||||
'senderDisplayName': email2nickname(username),
|
||||
'shareType': consumer_protocol['resourceTypes']['shareTypes'][0], # currently only support user type
|
||||
'resourceType': consumer_protocol['resourceTypes']['name'], # currently only support repo
|
||||
'protocol': {
|
||||
|
@@ -16,7 +16,7 @@ from seahub.utils import IS_EMAIL_CONFIGURED, \
|
||||
is_valid_email, string2list, gen_shared_link, send_html_email, \
|
||||
get_site_name
|
||||
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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -84,11 +84,6 @@ class SendShareLinkView(APIView):
|
||||
'password': link.get_password(),
|
||||
}
|
||||
|
||||
if REPLACE_FROM_EMAIL:
|
||||
from_email = useremail
|
||||
else:
|
||||
from_email = None # use default from email
|
||||
|
||||
if ADD_REPLY_TO_HEADER:
|
||||
reply_to = useremail
|
||||
else:
|
||||
@@ -107,7 +102,7 @@ class SendShareLinkView(APIView):
|
||||
|
||||
# send email
|
||||
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)
|
||||
except Exception as 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, \
|
||||
get_site_name
|
||||
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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -83,11 +83,6 @@ class SendUploadLinkView(APIView):
|
||||
'password': link.get_password(),
|
||||
}
|
||||
|
||||
if REPLACE_FROM_EMAIL:
|
||||
from_email = useremail
|
||||
else:
|
||||
from_email = None # use default from email
|
||||
|
||||
if ADD_REPLY_TO_HEADER:
|
||||
reply_to = useremail
|
||||
else:
|
||||
@@ -99,7 +94,7 @@ class SendUploadLinkView(APIView):
|
||||
|
||||
# send email
|
||||
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)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
@@ -33,9 +33,6 @@ class SharedFolders(APIView):
|
||||
Permission checking:
|
||||
1. all authenticated user can perform this action.
|
||||
"""
|
||||
if not request.user.permissions.can_share_repo():
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||
|
||||
shared_repos = []
|
||||
username = request.user.username
|
||||
|
||||
|
@@ -38,9 +38,6 @@ class SharedRepos(APIView):
|
||||
Permission checking:
|
||||
1. all authenticated user can perform this action.
|
||||
"""
|
||||
if not request.user.permissions.can_share_repo():
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||
|
||||
shared_repos = []
|
||||
username = request.user.username
|
||||
try:
|
||||
|
@@ -924,7 +924,7 @@ class CustomLDAPBackend(object):
|
||||
continue
|
||||
try:
|
||||
result_data = admin_bind.search_s(base, ldap.SCOPE_SUBTREE, filterstr)
|
||||
if result_data is not None:
|
||||
if result_data:
|
||||
break
|
||||
except Exception as e:
|
||||
raise Exception('ldap user search failed: %s' % e)
|
||||
|
@@ -1,9 +1,9 @@
|
||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||
# encoding: utf-8
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.urls import reverse
|
||||
@@ -14,7 +14,6 @@ from django.utils.translation import gettext as _
|
||||
from seahub.avatar.templatetags.avatar_tags import avatar
|
||||
from seahub.avatar.util import get_default_avatar_url
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||
from seahub.constants import HASH_URLS
|
||||
from seahub.options.models import (
|
||||
UserOptions, KEY_FILE_UPDATES_EMAIL_INTERVAL,
|
||||
KEY_FILE_UPDATES_LAST_EMAILED_TIME
|
||||
@@ -27,34 +26,38 @@ from seahub.utils.timeutils import utc_to_local
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
########## Utility Functions ##########
|
||||
|
||||
# Utility Functions
|
||||
def td(con):
|
||||
return con
|
||||
# return '<td>%s</td>' % con
|
||||
|
||||
|
||||
def a_tag(con, href='#', style=''):
|
||||
return '<a href="%s" style="%s">%s</a>' % (href, style, e(con))
|
||||
|
||||
|
||||
def repo_url(repo_id, repo_name):
|
||||
p = reverse('lib_view', args=[repo_id, repo_name, ''])
|
||||
|
||||
return get_site_scheme_and_netloc() + p
|
||||
|
||||
|
||||
def file_url(repo_id, file_path):
|
||||
p = reverse('view_lib_file', args=[repo_id, file_path])
|
||||
return get_site_scheme_and_netloc() + p
|
||||
|
||||
|
||||
def dir_url(repo_id, repo_name, dir_path):
|
||||
p = reverse('lib_view', args=[repo_id, repo_name, dir_path.strip('/')])
|
||||
|
||||
return get_site_scheme_and_netloc() + p
|
||||
|
||||
|
||||
def user_info_url(username):
|
||||
p = reverse('user_profile', args=[username])
|
||||
return get_site_scheme_and_netloc() + p
|
||||
|
||||
#######################################
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Send Email notifications to user if he/she has '
|
||||
@@ -216,7 +219,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write('[%s] Set language code to %s for user: %s' % (
|
||||
str(datetime.now()), user_language, username))
|
||||
|
||||
# get last_emailed_time if any, defaults to today 00:00:00.0
|
||||
# get last_emailed_time if any, defaults to today 00:00:00
|
||||
last_emailed_time = user_last_emailed_time_dict.get(username, None)
|
||||
now = datetime.utcnow().replace(microsecond=0)
|
||||
if not last_emailed_time:
|
||||
@@ -226,16 +229,22 @@ class Command(BaseCommand):
|
||||
if (now - last_emailed_time).total_seconds() < interval_val:
|
||||
continue
|
||||
|
||||
# to avoid slow queries caused by retrieving too much data,
|
||||
# only get file changes within the past week.
|
||||
if (now - last_emailed_time).total_seconds() > 7 * 86400:
|
||||
last_emailed_time = now - timedelta(days=7)
|
||||
|
||||
# get file updates(from: last_emailed_time, to: now) for repos
|
||||
# user can access
|
||||
res = get_user_activities_by_timestamp(
|
||||
username, last_emailed_time, now)
|
||||
res = get_user_activities_by_timestamp(username, last_emailed_time, now)
|
||||
if not res:
|
||||
UserOptions.objects.set_file_updates_last_emailed_time(username, now)
|
||||
continue
|
||||
|
||||
# remove my activities
|
||||
res = [x for x in res if x.op_user != username]
|
||||
if not res:
|
||||
UserOptions.objects.set_file_updates_last_emailed_time(username, now)
|
||||
continue
|
||||
|
||||
# format mail content & send file updates email to user
|
||||
@@ -269,8 +278,7 @@ class Command(BaseCommand):
|
||||
'notifications/file_updates_email.html', c,
|
||||
None, [contact_email])
|
||||
# set new last_emailed_time
|
||||
UserOptions.objects.set_file_updates_last_emailed_time(
|
||||
username, now)
|
||||
UserOptions.objects.set_file_updates_last_emailed_time(username, now)
|
||||
self.stdout.write('[%s] Successful to send email to %s' %
|
||||
(str(datetime.now()), contact_email))
|
||||
except Exception as e:
|
||||
|
@@ -83,13 +83,15 @@ STATIC_ROOT = '%s/assets/' % MEDIA_ROOT
|
||||
STATIC_URL = '/media/assets/'
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
STATICFILES_DIRS = [
|
||||
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
'%s/static' % PROJECT_ROOT,
|
||||
'%s/frontend/build' % PROJECT_ROOT,
|
||||
)
|
||||
]
|
||||
# %s/frontend/build perhaps not exists
|
||||
if os.path.isdir('%s/frontend/build' % PROJECT_ROOT):
|
||||
STATICFILES_DIRS.append('%s/frontend/build' % PROJECT_ROOT)
|
||||
|
||||
WEBPACK_LOADER = {
|
||||
'DEFAULT': {
|
||||
@@ -829,9 +831,6 @@ SEADOC_SERVER_URL = 'http://127.0.0.1:7070'
|
||||
# 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 = 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 *
|
||||
|
||||
urlpatterns = [
|
||||
path('link/send/', send_shared_link, name='send_shared_link'),
|
||||
path('link/save/', save_shared_link, name='save_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/get-link-audit-code/', ajax_get_link_audit_code, name='ajax_get_link_audit_code'),
|
||||
]
|
||||
|
@@ -5,34 +5,27 @@ import json
|
||||
import logging
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404, \
|
||||
HttpResponseBadRequest
|
||||
from django.utils.translation import gettext as _, activate
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
from django.utils.translation import gettext as _
|
||||
from django.contrib import messages
|
||||
from django.utils.html import escape
|
||||
|
||||
import seaserv
|
||||
from seaserv import seafile_api
|
||||
from pysearpc import SearpcError
|
||||
|
||||
from seahub.share.forms import FileLinkShareForm, \
|
||||
UploadLinkShareForm
|
||||
from seahub.share.models import FileShare, UploadLinkShare
|
||||
from seahub.share.signals import share_repo_to_user_successful
|
||||
from seahub.auth.decorators import login_required, login_required_ajax
|
||||
from seahub.base.decorators import require_POST
|
||||
from seahub.contacts.signals import mail_sended
|
||||
from seahub.views import is_registered_user, check_folder_permission
|
||||
from seahub.utils import string2list, IS_EMAIL_CONFIGURED, check_filename_with_rename, \
|
||||
is_valid_username, is_valid_email, send_html_email, is_org_context, \
|
||||
gen_token, normalize_cache_key, get_site_name, gen_shared_link
|
||||
from seahub.utils import string2list, check_filename_with_rename, \
|
||||
is_valid_username, is_valid_email, is_org_context, \
|
||||
gen_token, normalize_cache_key, gen_shared_link
|
||||
from seahub.utils.mail import send_html_email_with_dj_template
|
||||
from seahub.utils.ms_excel import write_xls
|
||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||
from seahub.settings import SITE_ROOT, REPLACE_FROM_EMAIL, \
|
||||
ADD_REPLY_TO_HEADER, SHARE_LINK_EMAIL_LANGUAGE, \
|
||||
SHARE_LINK_AUDIT_CODE_TIMEOUT
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.settings import SITE_ROOT, SHARE_LINK_AUDIT_CODE_TIMEOUT
|
||||
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -123,95 +116,6 @@ def share_to_user(request, repo, to_user, permission):
|
||||
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
|
||||
def save_shared_link(request):
|
||||
"""Save public share link to one's library.
|
||||
@@ -335,78 +239,6 @@ def export_shared_link(request):
|
||||
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
|
||||
@require_POST
|
||||
def ajax_private_share_dir(request):
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#coding: UTF-8
|
||||
# coding: UTF-8
|
||||
import json
|
||||
from mock import patch
|
||||
from django.core import mail
|
||||
from django.urls import reverse
|
||||
from django.test import override_settings
|
||||
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
||||
from seahub.share.models import FileShare
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.profile.utils import refresh_cache
|
||||
@@ -16,7 +15,7 @@ class SendShareLinkApiTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
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
|
||||
mail.outbox = []
|
||||
@@ -47,7 +46,6 @@ class SendShareLinkApiTest(BaseTestCase):
|
||||
|
||||
@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.REPLACE_FROM_EMAIL', True)
|
||||
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
||||
def test_can_send_email_rewrite(self):
|
||||
self.login_as(self.user)
|
||||
@@ -63,17 +61,15 @@ class SendShareLinkApiTest(BaseTestCase):
|
||||
json_resp = json.loads(resp.content)
|
||||
assert json_resp['success'][0] == self.admin.email
|
||||
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
|
||||
|
||||
@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.REPLACE_FROM_EMAIL', True)
|
||||
@patch('seahub.api2.endpoints.send_share_link_email.ADD_REPLY_TO_HEADER', True)
|
||||
def test_can_send_email_rewrite_contact_email(self):
|
||||
self.login_as(self.user)
|
||||
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.contact_email = contact_email
|
||||
p.save()
|
||||
@@ -92,7 +88,6 @@ class SendShareLinkApiTest(BaseTestCase):
|
||||
json_resp = json.loads(resp.content)
|
||||
assert json_resp['success'][0] == self.admin.email
|
||||
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
|
||||
|
||||
@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#coding: UTF-8
|
||||
# coding: UTF-8
|
||||
import json
|
||||
from mock import patch
|
||||
from django.core import mail
|
||||
from django.urls import reverse
|
||||
from django.test import override_settings
|
||||
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
||||
from seahub.share.models import UploadLinkShare
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.profile.utils import refresh_cache
|
||||
@@ -16,7 +15,7 @@ class SendUploadLinkApiTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
uls = UploadLinkShare.objects.create_upload_link_share(self.user.username,
|
||||
self.repo.id, '/')
|
||||
self.repo.id, '/')
|
||||
self.token = uls.token
|
||||
|
||||
def tearDown(self):
|
||||
@@ -44,7 +43,6 @@ class SendUploadLinkApiTest(BaseTestCase):
|
||||
|
||||
@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.REPLACE_FROM_EMAIL', True)
|
||||
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
||||
def test_can_send_email_rewrite(self):
|
||||
self.login_as(self.user)
|
||||
@@ -59,17 +57,15 @@ class SendUploadLinkApiTest(BaseTestCase):
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
json_resp = json.loads(resp.content)
|
||||
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
|
||||
|
||||
@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.REPLACE_FROM_EMAIL', True)
|
||||
@patch('seahub.api2.endpoints.send_upload_link_email.ADD_REPLY_TO_HEADER', True)
|
||||
def test_can_send_email_rewrite_contact_email(self):
|
||||
self.login_as(self.user)
|
||||
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.contact_email = contact_email
|
||||
p.save()
|
||||
@@ -87,7 +83,6 @@ class SendUploadLinkApiTest(BaseTestCase):
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
json_resp = json.loads(resp.content)
|
||||
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
|
||||
|
||||
@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