mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-19 15:38:38 +00:00
Send message when upload files to shared folder
This commit is contained in:
parent
fa42277b28
commit
7138e65691
@ -7,6 +7,7 @@ from django.db import models
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.utils.http import urlquote
|
||||||
|
|
||||||
from seahub.base.fields import LowerCaseCharField
|
from seahub.base.fields import LowerCaseCharField
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class UserMsgAttachment(models.Model):
|
|||||||
### handle signals
|
### handle signals
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from seahub.signals import share_file_to_user_successful
|
from seahub.signals import share_file_to_user_successful, upload_file_successful
|
||||||
from seahub.share.signals import share_repo_to_user_successful
|
from seahub.share.signals import share_repo_to_user_successful
|
||||||
|
|
||||||
@receiver(share_repo_to_user_successful)
|
@receiver(share_repo_to_user_successful)
|
||||||
@ -122,4 +123,30 @@ def add_share_file_msg(sender, **kwargs):
|
|||||||
UserMessage.objects.add_unread_message(priv_share.from_user,
|
UserMessage.objects.add_unread_message(priv_share.from_user,
|
||||||
priv_share.to_user, msg)
|
priv_share.to_user, msg)
|
||||||
|
|
||||||
|
@receiver(upload_file_successful)
|
||||||
|
def add_upload_file_msg(sender, **kwargs):
|
||||||
|
"""
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- `sender`:
|
||||||
|
- `**kwargs)`:
|
||||||
|
"""
|
||||||
|
repo_id = kwargs.get('repo_id', None)
|
||||||
|
file_path = kwargs.get('file_path', None)
|
||||||
|
owner = kwargs.get('owner', None)
|
||||||
|
|
||||||
|
assert repo_id and file_path and owner is not None, 'Arguments error'
|
||||||
|
|
||||||
|
# message body
|
||||||
|
filename = os.path.basename(file_path)
|
||||||
|
folder_path = os.path.dirname(file_path)
|
||||||
|
folder_name = os.path.basename(folder_path)
|
||||||
|
|
||||||
|
msg = u"(System) A file named <a href='%(file_link)s'>%(file_name)s</a> is uploaded to your folder <a href='%(folder_link)s'>%(folder)s</a>" % {
|
||||||
|
'file_link': reverse('repo_view_file', args=[repo_id]) + '?p=' + urlquote(file_path),
|
||||||
|
'file_name': filename,
|
||||||
|
'folder_link': reverse('repo', args=[repo_id]) + '?p=' + urlquote(folder_path),
|
||||||
|
'folder': folder_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
UserMessage.objects.add_unread_message("system@system.com", owner, msg)
|
||||||
|
@ -5,3 +5,5 @@ repo_created = django.dispatch.Signal(providing_args=["org_id", "creator", "repo
|
|||||||
repo_deleted = django.dispatch.Signal(providing_args=["org_id", "usernames", "repo_owner", "repo_id", "repo_name"])
|
repo_deleted = django.dispatch.Signal(providing_args=["org_id", "usernames", "repo_owner", "repo_id", "repo_name"])
|
||||||
|
|
||||||
share_file_to_user_successful = django.dispatch.Signal(providing_args=["priv_share_obj"])
|
share_file_to_user_successful = django.dispatch.Signal(providing_args=["priv_share_obj"])
|
||||||
|
|
||||||
|
upload_file_successful = django.dispatch.Signal(providing_args=["repo_id", "file_path", "owner"])
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% extends base_template %}
|
{% extends "myhome_base.html" %}
|
||||||
|
|
||||||
{% load seahub_tags i18n upload_tags avatar_tags %}
|
{% load seahub_tags i18n upload_tags avatar_tags %}
|
||||||
{% load url from future %}
|
{% load url from future %}
|
||||||
@ -96,10 +96,15 @@ form.fileupload({
|
|||||||
})
|
})
|
||||||
.bind('fileuploaddone', function(e, data) {
|
.bind('fileuploaddone', function(e, data) {
|
||||||
if (data.textStatus == 'success') {
|
if (data.textStatus == 'success') {
|
||||||
|
var filename = "";
|
||||||
$.each(data.files, function(index, file) {
|
$.each(data.files, function(index, file) {
|
||||||
|
filename = file.name;
|
||||||
$('#uploaded-files-list').append(
|
$('#uploaded-files-list').append(
|
||||||
'<tr><td></td><td>' + file.name +'</td><td>' + filesizeformat(file.size) + '</td></tr>');
|
'<tr><td></td><td>' + filename +'</td><td>' + filesizeformat(file.size) + '</td></tr>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var uploaded_done_link = "{% url "upload_file_done" %}" + "?fn=" + encodeURIComponent(filename) + "&repo_id={{repo.id}}" + "&p={{path}}";
|
||||||
|
$.get(uploaded_done_link);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ urlpatterns = patterns('',
|
|||||||
url(r'^ajax/group/(?P<group_id>\d+)/repos/$', get_group_repos, name='get_group_repos'),
|
url(r'^ajax/group/(?P<group_id>\d+)/repos/$', get_group_repos, name='get_group_repos'),
|
||||||
url(r'^ajax/my-unenc-repos/$', get_my_unenc_repos, name='get_my_unenc_repos'),
|
url(r'^ajax/my-unenc-repos/$', get_my_unenc_repos, name='get_my_unenc_repos'),
|
||||||
url(r'^ajax/contacts/$', get_contacts, name='get_contacts'),
|
url(r'^ajax/contacts/$', get_contacts, name='get_contacts'),
|
||||||
|
url(r'^ajax/upload-file-done/$', upload_file_done, name='upload_file_done'),
|
||||||
|
|
||||||
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/$', list_dir, name='repo_dir_data'),
|
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/$', list_dir, name='repo_dir_data'),
|
||||||
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/more/$', list_dir_more, name='list_dir_more'),
|
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/more/$', list_dir_more, name='list_dir_more'),
|
||||||
|
@ -19,6 +19,7 @@ from seahub.auth.decorators import login_required
|
|||||||
from seahub.contacts.models import Contact
|
from seahub.contacts.models import Contact
|
||||||
from seahub.forms import RepoNewDirentForm, RepoRenameDirentForm
|
from seahub.forms import RepoNewDirentForm, RepoRenameDirentForm
|
||||||
from seahub.options.models import UserOptions, CryptoOptionNotSetError
|
from seahub.options.models import UserOptions, CryptoOptionNotSetError
|
||||||
|
from seahub.signals import upload_file_successful
|
||||||
from seahub.views import get_repo_dirents
|
from seahub.views import get_repo_dirents
|
||||||
from seahub.views.repo import get_nav_path, get_fileshare, get_dir_share_link, \
|
from seahub.views.repo import get_nav_path, get_fileshare, get_dir_share_link, \
|
||||||
get_uploadlink, get_dir_shared_upload_link
|
get_uploadlink, get_dir_shared_upload_link
|
||||||
@ -1000,3 +1001,49 @@ def download_enc_file(request, repo_id, file_id):
|
|||||||
'url':url,
|
'url':url,
|
||||||
}
|
}
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||||
|
|
||||||
|
def upload_file_done(request):
|
||||||
|
"""Send a message when a file is uploaded.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- `request`:
|
||||||
|
"""
|
||||||
|
ct = 'application/json; charset=utf-8'
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
filename = request.GET.get('fn', '')
|
||||||
|
if not filename:
|
||||||
|
result['error'] = _('Argument missing')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
repo_id = request.GET.get('repo_id', '')
|
||||||
|
if not repo_id:
|
||||||
|
result['error'] = _('Argument missing')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
path = request.GET.get('p', '')
|
||||||
|
if not path:
|
||||||
|
result['error'] = _('Argument missing')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
|
||||||
|
# a few checkings
|
||||||
|
if not seafile_api.get_repo(repo_id):
|
||||||
|
result['error'] = _('Wrong repo id')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
|
||||||
|
owner = seafile_api.get_repo_owner(repo_id)
|
||||||
|
if not owner:
|
||||||
|
result['error'] = _('Wrong repo id')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
|
||||||
|
file_path = path.rstrip('/') + '/' + filename
|
||||||
|
if seafile_api.get_file_id_by_path(repo_id, file_path) is None:
|
||||||
|
result['error'] = _('File does not exist')
|
||||||
|
return HttpResponse(json.dumps(result), status=400, content_type=ct)
|
||||||
|
|
||||||
|
# send singal
|
||||||
|
upload_file_successful.send(sender=None,
|
||||||
|
repo_id=repo_id,
|
||||||
|
file_path=file_path,
|
||||||
|
owner=owner)
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps({'success': True}), content_type=ct)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user