mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-14 14:21:23 +00:00
Remove unused APIs
Group messages and personal messages related API is no longer used
This commit is contained in:
@@ -63,14 +63,9 @@ urlpatterns = patterns('',
|
|||||||
url(r'^f/(?P<token>[a-f0-9]{10})/detail/$', SharedFileDetailView.as_view()),
|
url(r'^f/(?P<token>[a-f0-9]{10})/detail/$', SharedFileDetailView.as_view()),
|
||||||
url(r'^d/(?P<token>[a-f0-9]{10})/dir/$', SharedDirView.as_view()),
|
url(r'^d/(?P<token>[a-f0-9]{10})/dir/$', SharedDirView.as_view()),
|
||||||
|
|
||||||
url(r'^groupandcontacts/$', GroupAndContacts.as_view()),
|
|
||||||
url(r'^events/$', EventsView.as_view()),
|
url(r'^events/$', EventsView.as_view()),
|
||||||
url(r'^repo_history_changes/(?P<repo_id>[-0-9a-f]{36})/$', RepoHistoryChange.as_view()),
|
url(r'^repo_history_changes/(?P<repo_id>[-0-9a-f]{36})/$', RepoHistoryChange.as_view()),
|
||||||
url(r'^unseen_messages/$', UnseenMessagesCountView.as_view()),
|
url(r'^unseen_messages/$', UnseenMessagesCountView.as_view()),
|
||||||
url(r'^group/msgs/(?P<group_id>\d+)/$', GroupMsgsView.as_view()),
|
|
||||||
url(r'^group/(?P<group_id>\d+)/msg/(?P<msg_id>\d+)/$', GroupMsgView.as_view()),
|
|
||||||
url(r'^user/msgs/(?P<id_or_email>[^/]+)/$', UserMsgsView.as_view()),
|
|
||||||
url(r'^new_replies/$', NewRepliesView.as_view()),
|
|
||||||
|
|
||||||
url(r'^avatars/user/(?P<user>\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/resized/(?P<size>[0-9]+)/$', UserAvatarView.as_view()),
|
url(r'^avatars/user/(?P<user>\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/resized/(?P<size>[0-9]+)/$', UserAvatarView.as_view()),
|
||||||
url(r'^avatars/group/(?P<group_id>\d+)/resized/(?P<size>[0-9]+)/$', GroupAvatarView.as_view()),
|
url(r'^avatars/group/(?P<group_id>\d+)/resized/(?P<size>[0-9]+)/$', GroupAvatarView.as_view()),
|
||||||
@@ -78,31 +73,12 @@ urlpatterns = patterns('',
|
|||||||
url(r'^groups/$', Groups.as_view()),
|
url(r'^groups/$', Groups.as_view()),
|
||||||
url(r'^groups/(?P<group_id>\d+)/$', Groups.as_view()),
|
url(r'^groups/(?P<group_id>\d+)/$', Groups.as_view()),
|
||||||
url(r'^groups/(?P<group_id>\d+)/members/$', GroupMembers.as_view()),
|
url(r'^groups/(?P<group_id>\d+)/members/$', GroupMembers.as_view()),
|
||||||
url(r'^groups/(?P<group_id>\d+)/changes/$', GroupChanges.as_view(), name="api2-group-changes"),
|
|
||||||
url(r'^groups/(?P<group_id>\d+)/repos/$', GroupRepos.as_view(), name="api2-grouprepos"),
|
url(r'^groups/(?P<group_id>\d+)/repos/$', GroupRepos.as_view(), name="api2-grouprepos"),
|
||||||
url(r'^groups/(?P<group_id>\d+)/repos/(?P<repo_id>[-0-9a-f]{36})/$', GroupRepo.as_view(), name="api2-grouprepo"),
|
url(r'^groups/(?P<group_id>\d+)/repos/(?P<repo_id>[-0-9a-f]{36})/$', GroupRepo.as_view(), name="api2-grouprepo"),
|
||||||
|
|
||||||
url(r'^html/events/$', EventsHtml.as_view()),
|
url(r'^html/events/$', EventsHtml.as_view()),
|
||||||
url(r'^html/more_events/$', AjaxEvents.as_view(), name="more_events"),
|
url(r'^html/more_events/$', AjaxEvents.as_view(), name="more_events"),
|
||||||
url(r'^html/repo_history_changes/(?P<repo_id>[-0-9a-f]{36})/$', RepoHistoryChangeHtml.as_view(), name='api_repo_history_changes'),
|
url(r'^html/repo_history_changes/(?P<repo_id>[-0-9a-f]{36})/$', RepoHistoryChangeHtml.as_view(), name='api_repo_history_changes'),
|
||||||
url(r'^html/discussions/(?P<group_id>\d+)/$', DiscussionsHtml.as_view(), name="api_discussions"),
|
|
||||||
url(r'^html/discussion/(?P<msg_id>\d+)/$', DiscussionHtml.as_view(), name="api_discussion"),
|
|
||||||
url(r'^html/more_discussions/(?P<group_id>\d+)/$', AjaxDiscussions.as_view(), name="more_discussions"),
|
|
||||||
url(r'^html/newreply/$', NewReplyHtml.as_view()),
|
|
||||||
url(r'^html/usermsgs/(?P<id_or_email>[^/]+)/$', UserMsgsHtml.as_view()),
|
|
||||||
url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', AjaxUserMsgs.as_view(), name="api_more_usermsgs"),
|
|
||||||
|
|
||||||
# Folowing is only for debug, will be removed
|
|
||||||
#url(r'^html/newreply2/$', api_new_replies),
|
|
||||||
#url(r'^html/events2/$', activity2),
|
|
||||||
#url(r'^html/more_events/$', events2, name="more_events"),
|
|
||||||
#url(r'^html/repo_history_changes/(?P<repo_id>[-0-9a-f]{36})/$', api_repo_history_changes, name='api_repo_history_changes'),
|
|
||||||
|
|
||||||
#url(r'^html/discussions2/(?P<group_id>\d+)/$', discussions2, name="api_discussions2"),
|
|
||||||
#url(r'^html/discussion/(?P<msg_id>\d+)/$', discussion2, name="api_discussion2"),
|
|
||||||
#url(r'^html/more_discussions/(?P<group_id>\d+)/$', more_discussions2, name="more_discussions"),
|
|
||||||
#url(r'^html/usermsgs2/(?P<id_or_email>[^/]+)/$', api_usermsgs),
|
|
||||||
#url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', api_more_usermsgs, name="api_more_usermsgs"),
|
|
||||||
|
|
||||||
# Deprecated
|
# Deprecated
|
||||||
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view()),
|
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view()),
|
||||||
|
@@ -50,7 +50,7 @@ from seahub.base.templatetags.seahub_tags import email2nickname, \
|
|||||||
from seahub.group.models import GroupMessage, MessageReply, MessageAttachment
|
from seahub.group.models import GroupMessage, MessageReply, MessageAttachment
|
||||||
from seahub.group.signals import grpmsg_added, grpmsg_reply_added
|
from seahub.group.signals import grpmsg_added, grpmsg_reply_added
|
||||||
from seahub.group.views import group_check, remove_group_common, \
|
from seahub.group.views import group_check, remove_group_common, \
|
||||||
rename_group_with_new_name
|
rename_group_with_new_name, is_group_staff
|
||||||
from seahub.group.utils import BadGroupNameError, ConflictGroupNameError, \
|
from seahub.group.utils import BadGroupNameError, ConflictGroupNameError, \
|
||||||
validate_group_name
|
validate_group_name
|
||||||
from seahub.thumbnail.utils import generate_thumbnail
|
from seahub.thumbnail.utils import generate_thumbnail
|
||||||
@@ -3526,69 +3526,6 @@ class GroupMembers(APIView):
|
|||||||
|
|
||||||
return HttpResponse(json.dumps({'success': True}), status=200, content_type=json_content_type)
|
return HttpResponse(json.dumps({'success': True}), status=200, content_type=json_content_type)
|
||||||
|
|
||||||
|
|
||||||
class GroupChanges(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
@api_group_check
|
|
||||||
def get(self, request, group, format=None):
|
|
||||||
group_id = int(group.id)
|
|
||||||
username = request.user.username
|
|
||||||
if is_org_context(request):
|
|
||||||
org_id = request.user.org.org_id
|
|
||||||
repos = seaserv.get_org_group_repos(org_id, group_id, username)
|
|
||||||
else:
|
|
||||||
repos = seaserv.get_group_repos(group_id, username)
|
|
||||||
|
|
||||||
recent_commits = []
|
|
||||||
cmt_repo_dict = {}
|
|
||||||
for repo in repos:
|
|
||||||
repo.user_perm = check_permission(repo.props.id, username)
|
|
||||||
cmmts = get_commits(repo.props.id, 0, 10)
|
|
||||||
for c in cmmts:
|
|
||||||
cmt_repo_dict[c.id] = repo
|
|
||||||
recent_commits += cmmts
|
|
||||||
|
|
||||||
recent_commits.sort(lambda x, y: cmp(y.props.ctime, x.props.ctime))
|
|
||||||
recent_commits = recent_commits[:15]
|
|
||||||
for cmt in recent_commits:
|
|
||||||
cmt.repo = cmt_repo_dict[cmt.id]
|
|
||||||
cmt.repo.password_set = is_passwd_set(cmt.props.repo_id, username)
|
|
||||||
cmt.tp = cmt.props.desc.split(' ')[0]
|
|
||||||
|
|
||||||
res = []
|
|
||||||
for c in recent_commits:
|
|
||||||
cmt_tp = c.tp.lower()
|
|
||||||
if 'add' in cmt_tp:
|
|
||||||
change_tp = 'added'
|
|
||||||
elif ('delete' or 'remove') in cmt_tp:
|
|
||||||
change_tp = 'deleted'
|
|
||||||
else:
|
|
||||||
change_tp = 'modified'
|
|
||||||
|
|
||||||
change_repo = {
|
|
||||||
'id': c.repo.id,
|
|
||||||
'name': c.repo.name,
|
|
||||||
'desc': c.repo.desc,
|
|
||||||
'encrypted': c.repo.encrypted,
|
|
||||||
}
|
|
||||||
change = {
|
|
||||||
"type": change_tp,
|
|
||||||
"repo": change_repo,
|
|
||||||
"id": c.id,
|
|
||||||
"desc": c.desc,
|
|
||||||
"desc_human": translate_commit_desc(c.desc),
|
|
||||||
"ctime": c.ctime,
|
|
||||||
"ctime_human": translate_seahub_time(c.ctime),
|
|
||||||
"creator": c.creator_name,
|
|
||||||
"creator_nickname": email2nickname(c.creator_name)
|
|
||||||
}
|
|
||||||
res.append(change)
|
|
||||||
|
|
||||||
return Response(res)
|
|
||||||
|
|
||||||
class GroupRepos(APIView):
|
class GroupRepos(APIView):
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
@@ -3708,186 +3645,6 @@ class GroupRepo(APIView):
|
|||||||
return HttpResponse(json.dumps({'success': True}), status=200,
|
return HttpResponse(json.dumps({'success': True}), status=200,
|
||||||
content_type=json_content_type)
|
content_type=json_content_type)
|
||||||
|
|
||||||
def is_group_staff(group, user):
|
|
||||||
if user.is_anonymous():
|
|
||||||
return False
|
|
||||||
return check_group_staff(group.id, user.username)
|
|
||||||
|
|
||||||
def get_page_index(request, default=1):
|
|
||||||
try:
|
|
||||||
page = int(request.GET.get('page', default))
|
|
||||||
except ValueError:
|
|
||||||
page = default
|
|
||||||
return page
|
|
||||||
|
|
||||||
class GroupMsgsView(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
@api_group_check
|
|
||||||
def get(self, request, group, format=None):
|
|
||||||
username = request.user.username
|
|
||||||
page = get_page_index (request, 1)
|
|
||||||
msgs, next_page = get_group_msgs_json(group.id, page, username)
|
|
||||||
if not msgs:
|
|
||||||
msgs = []
|
|
||||||
# remove user notifications
|
|
||||||
UserNotification.objects.seen_group_msg_notices(username, group.id)
|
|
||||||
ret = {
|
|
||||||
'next_page' : next_page,
|
|
||||||
'msgs' : msgs,
|
|
||||||
}
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
@api_group_check
|
|
||||||
def post(self, request, group, format=None):
|
|
||||||
username = request.user.username
|
|
||||||
msg = request.POST.get('message')
|
|
||||||
message = GroupMessage()
|
|
||||||
message.group_id = group.id
|
|
||||||
message.from_email = request.user.username
|
|
||||||
message.message = msg
|
|
||||||
message.save()
|
|
||||||
|
|
||||||
# send signal
|
|
||||||
grpmsg_added.send(sender=GroupMessage, group_id=group.id,
|
|
||||||
from_email=username, message=msg)
|
|
||||||
|
|
||||||
repo_id = request.POST.get('repo_id', None)
|
|
||||||
path = request.POST.get('path', None)
|
|
||||||
if repo_id and path:
|
|
||||||
# save attachment
|
|
||||||
ma = MessageAttachment(group_message=message, repo_id=repo_id,
|
|
||||||
attach_type='file', path=path,
|
|
||||||
src='recommend')
|
|
||||||
ma.save()
|
|
||||||
|
|
||||||
# save discussion
|
|
||||||
fd = FileDiscuss(group_message=message, repo_id=repo_id, path=path)
|
|
||||||
fd.save()
|
|
||||||
|
|
||||||
ret = { "msgid" : message.id }
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
class GroupMsgView(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
@api_group_check
|
|
||||||
def get(self, request, group, msg_id, format=None):
|
|
||||||
msg = get_group_message_json(group.id, msg_id, True)
|
|
||||||
if not msg:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'Message not found.')
|
|
||||||
|
|
||||||
UserNotification.objects.seen_group_msg_reply_notice(request.user.username, msg_id)
|
|
||||||
return Response(msg)
|
|
||||||
|
|
||||||
@api_group_check
|
|
||||||
def post(self, request, group, msg_id, format=None):
|
|
||||||
try:
|
|
||||||
group_msg = GroupMessage.objects.get(group_id=group.id, id=msg_id)
|
|
||||||
except GroupMessage.DoesNotExist:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'Message not found.')
|
|
||||||
|
|
||||||
msg = request.POST.get('message')
|
|
||||||
msg_reply = MessageReply()
|
|
||||||
msg_reply.reply_to = group_msg
|
|
||||||
msg_reply.from_email = request.user.username
|
|
||||||
msg_reply.message = msg
|
|
||||||
msg_reply.save()
|
|
||||||
|
|
||||||
grpmsg_reply_added.send(sender=MessageReply,
|
|
||||||
msg_id=msg_id,
|
|
||||||
from_email=request.user.username,
|
|
||||||
grpmsg_topic=group_msg.message,
|
|
||||||
reply_msg=msg)
|
|
||||||
ret = { "msgid" : msg_reply.id }
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
class UserMsgsView(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, id_or_email, format=None):
|
|
||||||
username = request.user.username
|
|
||||||
to_email = get_email(id_or_email)
|
|
||||||
if not to_email:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'User not found.')
|
|
||||||
|
|
||||||
UserNotification.objects.seen_user_msg_notices(username, to_email)
|
|
||||||
UserMessage.objects.update_unread_messages(to_email, username)
|
|
||||||
page = get_page_index(request, 1)
|
|
||||||
|
|
||||||
next_page = -1
|
|
||||||
person_msgs = get_person_msgs(to_email, page, username)
|
|
||||||
if not person_msgs:
|
|
||||||
Response({
|
|
||||||
'to_email' : to_email,
|
|
||||||
'next_page' : next_page,
|
|
||||||
'msgs' : [],})
|
|
||||||
elif person_msgs.has_next():
|
|
||||||
next_page = person_msgs.next_page_number()
|
|
||||||
|
|
||||||
msgs = []
|
|
||||||
for msg in person_msgs.object_list:
|
|
||||||
atts = []
|
|
||||||
for att in msg.attachments:
|
|
||||||
atts.append({
|
|
||||||
'repo_id' : att.repo_id,
|
|
||||||
'path' : att.path,
|
|
||||||
})
|
|
||||||
m = {
|
|
||||||
'from_email' : msg.from_email,
|
|
||||||
'nickname' : email2nickname(msg.from_email),
|
|
||||||
'timestamp' : get_timestamp(msg.timestamp),
|
|
||||||
'msg' : msg.message,
|
|
||||||
'attachments' : atts,
|
|
||||||
'msgid' : msg.message_id,
|
|
||||||
}
|
|
||||||
msgs.append(m)
|
|
||||||
|
|
||||||
ret = {
|
|
||||||
'to_email' : to_email,
|
|
||||||
'next_page' : next_page,
|
|
||||||
'msgs' : msgs,
|
|
||||||
}
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
def post(self, request, id_or_email, format=None):
|
|
||||||
username = request.user.username
|
|
||||||
to_email = get_email(id_or_email)
|
|
||||||
if not to_email:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'User not found.')
|
|
||||||
|
|
||||||
mass_msg = request.POST.get('message')
|
|
||||||
if not mass_msg:
|
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, "Missing argument")
|
|
||||||
|
|
||||||
usermsg = UserMessage.objects.add_unread_message(username, to_email, mass_msg)
|
|
||||||
ret = { 'msgid' : usermsg.message_id }
|
|
||||||
return Response(ret)
|
|
||||||
|
|
||||||
class NewRepliesView(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, format=None):
|
|
||||||
notes = UserNotification.objects.get_user_notifications(request.user.username, seen=False)
|
|
||||||
grpmsg_reply_list = [ n.grpmsg_reply_detail_to_dict().get('msg_id') for n in notes if n.msg_type == 'grpmsg_reply']
|
|
||||||
group_msgs = []
|
|
||||||
for msg_id in grpmsg_reply_list:
|
|
||||||
msg = get_group_message_json (None, msg_id, True)
|
|
||||||
if msg:
|
|
||||||
group_msgs.append(msg)
|
|
||||||
|
|
||||||
# remove new group msg reply notification
|
|
||||||
UserNotification.objects.seen_group_msg_reply_notice(request.user.username)
|
|
||||||
return Response(group_msgs)
|
|
||||||
|
|
||||||
class UserAvatarView(APIView):
|
class UserAvatarView(APIView):
|
||||||
authentication_classes = (TokenAuthentication, )
|
authentication_classes = (TokenAuthentication, )
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
@@ -3964,182 +3721,6 @@ def ajax_events(request):
|
|||||||
'new_start': start}),
|
'new_start': start}),
|
||||||
content_type=json_content_type)
|
content_type=json_content_type)
|
||||||
|
|
||||||
@group_check
|
|
||||||
def html_group_discussions(request, group):
|
|
||||||
username = request.user.username
|
|
||||||
if request.method == 'POST':
|
|
||||||
# only login user can post to public group
|
|
||||||
if group.view_perm == "pub" and not request.user.is_authenticated():
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
msg = request.POST.get('message')
|
|
||||||
message = GroupMessage()
|
|
||||||
message.group_id = group.id
|
|
||||||
message.from_email = request.user.username
|
|
||||||
message.message = msg
|
|
||||||
message.save()
|
|
||||||
|
|
||||||
# send signal
|
|
||||||
grpmsg_added.send(sender=GroupMessage, group_id=group.id,
|
|
||||||
from_email=username, message=msg)
|
|
||||||
|
|
||||||
repo_id = request.POST.get('repo_id', None)
|
|
||||||
path = request.POST.get('path', None)
|
|
||||||
if repo_id and path:
|
|
||||||
# save attachment
|
|
||||||
ma = MessageAttachment(group_message=message, repo_id=repo_id,
|
|
||||||
attach_type='file', path=path,
|
|
||||||
src='recommend')
|
|
||||||
ma.save()
|
|
||||||
|
|
||||||
# save discussion
|
|
||||||
fd = FileDiscuss(group_message=message, repo_id=repo_id, path=path)
|
|
||||||
fd.save()
|
|
||||||
|
|
||||||
ctx = {}
|
|
||||||
ctx['msg'] = message
|
|
||||||
html = render_to_string("api2/discussion_posted.html", ctx)
|
|
||||||
serialized_data = json.dumps({"html": html})
|
|
||||||
return HttpResponse(serialized_data, content_type=json_content_type)
|
|
||||||
|
|
||||||
group_msgs = get_group_msgs(group.id, page=1, username=request.user.username)
|
|
||||||
# remove user notifications
|
|
||||||
UserNotification.objects.seen_group_msg_notices(username, group.id)
|
|
||||||
return render_to_response("api2/discussions.html", {
|
|
||||||
"group" : group,
|
|
||||||
"group_msgs": group_msgs,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
@group_check
|
|
||||||
def ajax_discussions(request, group):
|
|
||||||
try:
|
|
||||||
page = int(request.GET.get('page'))
|
|
||||||
except ValueError:
|
|
||||||
page = 2
|
|
||||||
|
|
||||||
group_msgs = get_group_msgs(group.id, page, request.user.username)
|
|
||||||
if group_msgs.has_next():
|
|
||||||
next_page = group_msgs.next_page_number()
|
|
||||||
else:
|
|
||||||
next_page = None
|
|
||||||
|
|
||||||
html = render_to_string('api2/discussions_body.html', {"group_msgs": group_msgs}, context_instance=RequestContext(request))
|
|
||||||
return HttpResponse(json.dumps({"html": html, 'next_page': next_page}), content_type=json_content_type)
|
|
||||||
|
|
||||||
def html_get_group_discussion(request, msg_id):
|
|
||||||
try:
|
|
||||||
msg = GroupMessage.objects.get(id=msg_id)
|
|
||||||
except GroupMessage.DoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
try:
|
|
||||||
att = MessageAttachment.objects.get(group_message_id=msg_id)
|
|
||||||
except MessageAttachment.DoesNotExist:
|
|
||||||
att = None
|
|
||||||
|
|
||||||
if att:
|
|
||||||
path = att.path
|
|
||||||
if path == '/':
|
|
||||||
repo = get_repo(att.repo_id)
|
|
||||||
if repo:
|
|
||||||
att.name = repo.name
|
|
||||||
else:
|
|
||||||
att.err = 'the libray does not exist'
|
|
||||||
else:
|
|
||||||
path = path.rstrip('/') # cut out last '/' if possible
|
|
||||||
att.name = os.path.basename(path)
|
|
||||||
|
|
||||||
# Load to discuss page if attachment is a image and from recommend.
|
|
||||||
if att.attach_type == 'file' and att.src == 'recommend':
|
|
||||||
att.filetype, att.fileext = get_file_type_and_ext(att.name)
|
|
||||||
if att.filetype == IMAGE:
|
|
||||||
att.obj_id = get_file_id_by_path(att.repo_id, path)
|
|
||||||
if not att.obj_id:
|
|
||||||
att.err = 'File does not exist'
|
|
||||||
else:
|
|
||||||
att.token = seafile_api.get_fileserver_access_token(
|
|
||||||
att.repo_id, att.obj_id, 'view', request.user.username)
|
|
||||||
att.img_url = gen_file_get_url(att.token, att.name)
|
|
||||||
|
|
||||||
msg.attachment = att
|
|
||||||
|
|
||||||
msg.replies = MessageReply.objects.filter(reply_to=msg)
|
|
||||||
msg.reply_cnt = len(msg.replies)
|
|
||||||
|
|
||||||
return render_to_response("api2/discussion.html", {
|
|
||||||
"msg": msg,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
def html_msg_reply(request, msg_id):
|
|
||||||
"""Show group message replies, and process message reply in ajax"""
|
|
||||||
|
|
||||||
ctx = {}
|
|
||||||
try:
|
|
||||||
group_msg = GroupMessage.objects.get(id=msg_id)
|
|
||||||
except GroupMessage.DoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
msg = request.POST.get('message')
|
|
||||||
msg_reply = MessageReply()
|
|
||||||
msg_reply.reply_to = group_msg
|
|
||||||
msg_reply.from_email = request.user.username
|
|
||||||
msg_reply.message = msg
|
|
||||||
msg_reply.save()
|
|
||||||
|
|
||||||
grpmsg_reply_added.send(sender=MessageReply,
|
|
||||||
msg_id=msg_id,
|
|
||||||
from_email=request.user.username,
|
|
||||||
reply_msg=msg)
|
|
||||||
ctx['r'] = msg_reply
|
|
||||||
html = render_to_string("api2/reply.html", ctx)
|
|
||||||
serialized_data = json.dumps({"html": html})
|
|
||||||
return HttpResponse(serialized_data, content_type=json_content_type)
|
|
||||||
|
|
||||||
def html_user_messages(request, id_or_email):
|
|
||||||
to_email = get_email(id_or_email)
|
|
||||||
if not to_email:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'User not found.')
|
|
||||||
|
|
||||||
username = request.user.username
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
|
||||||
mass_msg = request.POST.get('message')
|
|
||||||
if not mass_msg:
|
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, "Missing argument")
|
|
||||||
|
|
||||||
usermsg = UserMessage.objects.add_unread_message(username, to_email, mass_msg)
|
|
||||||
ctx = { 'msg' : usermsg }
|
|
||||||
html = render_to_string("api2/user_msg.html", ctx)
|
|
||||||
serialized_data = json.dumps({"html": html})
|
|
||||||
return HttpResponse(serialized_data, content_type=json_content_type)
|
|
||||||
|
|
||||||
UserNotification.objects.seen_user_msg_notices(username, to_email)
|
|
||||||
UserMessage.objects.update_unread_messages(to_email, username)
|
|
||||||
person_msgs = get_person_msgs(to_email, 1, username)
|
|
||||||
|
|
||||||
return render_to_response("api2/user_msg_list.html", {
|
|
||||||
"person_msgs": person_msgs,
|
|
||||||
"to_email": to_email,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
def ajax_usermsgs(request, id_or_email):
|
|
||||||
try:
|
|
||||||
page = int(request.GET.get('page'))
|
|
||||||
except ValueError:
|
|
||||||
page = 2
|
|
||||||
|
|
||||||
to_email = get_email(id_or_email)
|
|
||||||
if not to_email:
|
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'User not found.')
|
|
||||||
|
|
||||||
person_msgs = get_person_msgs(to_email, page, request.user.username)
|
|
||||||
if person_msgs.has_next():
|
|
||||||
next_page = person_msgs.next_page_number()
|
|
||||||
else:
|
|
||||||
next_page = None
|
|
||||||
|
|
||||||
html = render_to_string('api2/user_msg_body.html', {"person_msgs": person_msgs}, context_instance=RequestContext(request))
|
|
||||||
return HttpResponse(json.dumps({"html": html, 'next_page': next_page}), content_type=json_content_type)
|
|
||||||
|
|
||||||
def html_repo_history_changes(request, repo_id):
|
def html_repo_history_changes(request, repo_id):
|
||||||
changes = {}
|
changes = {}
|
||||||
@@ -4178,51 +3759,6 @@ def html_repo_history_changes(request, repo_id):
|
|||||||
html = render_to_string('api2/event_details.html', {'changes': changes})
|
html = render_to_string('api2/event_details.html', {'changes': changes})
|
||||||
return HttpResponse(json.dumps({"html": html}), content_type=json_content_type)
|
return HttpResponse(json.dumps({"html": html}), content_type=json_content_type)
|
||||||
|
|
||||||
def html_new_replies(request):
|
|
||||||
notes = UserNotification.objects.get_user_notifications(request.user.username, seen=False)
|
|
||||||
grpmsg_reply_list = [ n.grpmsg_reply_detail_to_dict().get('msg_id') for n in notes if n.msg_type == 'grpmsg_reply']
|
|
||||||
group_msgs = []
|
|
||||||
for msg_id in grpmsg_reply_list:
|
|
||||||
try:
|
|
||||||
m = GroupMessage.objects.get(id=msg_id)
|
|
||||||
except GroupMessage.DoesNotExist:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
# get group name
|
|
||||||
group = get_group(m.group_id)
|
|
||||||
if not group:
|
|
||||||
continue
|
|
||||||
m.group_name = group.group_name
|
|
||||||
|
|
||||||
# get attachement
|
|
||||||
attachment = get_first_object_or_none(m.messageattachment_set.all())
|
|
||||||
if attachment:
|
|
||||||
path = attachment.path
|
|
||||||
if path == '/':
|
|
||||||
repo = get_repo(attachment.repo_id)
|
|
||||||
if not repo:
|
|
||||||
continue
|
|
||||||
attachment.name = repo.name
|
|
||||||
else:
|
|
||||||
attachment.name = os.path.basename(path)
|
|
||||||
m.attachment = attachment
|
|
||||||
|
|
||||||
# get message replies
|
|
||||||
reply_list = MessageReply.objects.filter(reply_to=m)
|
|
||||||
m.reply_cnt = reply_list.count()
|
|
||||||
if m.reply_cnt > 3:
|
|
||||||
m.replies = reply_list[m.reply_cnt - 3:]
|
|
||||||
else:
|
|
||||||
m.replies = reply_list
|
|
||||||
|
|
||||||
group_msgs.append(m)
|
|
||||||
|
|
||||||
# remove new group msg reply notification
|
|
||||||
UserNotification.objects.seen_group_msg_reply_notice(request.user.username)
|
|
||||||
|
|
||||||
return render_to_response("api2/new_msg_reply.html", {
|
|
||||||
'group_msgs': group_msgs,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
class AjaxEvents(APIView):
|
class AjaxEvents(APIView):
|
||||||
authentication_classes = (TokenAuthentication, )
|
authentication_classes = (TokenAuthentication, )
|
||||||
@@ -4232,22 +3768,6 @@ class AjaxEvents(APIView):
|
|||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
return ajax_events(request)
|
return ajax_events(request)
|
||||||
|
|
||||||
class AjaxDiscussions(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, group_id, format=None):
|
|
||||||
return ajax_discussions(request, group_id)
|
|
||||||
|
|
||||||
class AjaxUserMsgs(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, id_or_email, format=None):
|
|
||||||
return ajax_usermsgs(request, id_or_email)
|
|
||||||
|
|
||||||
class EventsHtml(APIView):
|
class EventsHtml(APIView):
|
||||||
authentication_classes = (TokenAuthentication, )
|
authentication_classes = (TokenAuthentication, )
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
@@ -4256,47 +3776,6 @@ class EventsHtml(APIView):
|
|||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
return html_events(request)
|
return html_events(request)
|
||||||
|
|
||||||
class NewReplyHtml(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, format=None):
|
|
||||||
return html_new_replies(request)
|
|
||||||
|
|
||||||
class DiscussionsHtml(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, group_id, format=None):
|
|
||||||
return html_group_discussions(request, group_id)
|
|
||||||
|
|
||||||
def post(self, request, group_id, format=None):
|
|
||||||
return html_group_discussions(request, group_id)
|
|
||||||
|
|
||||||
class UserMsgsHtml(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, id_or_email, format=None):
|
|
||||||
return html_user_messages(request, id_or_email)
|
|
||||||
|
|
||||||
def post(self, request, id_or_email, format=None):
|
|
||||||
return html_user_messages(request, id_or_email)
|
|
||||||
|
|
||||||
class DiscussionHtml(APIView):
|
|
||||||
authentication_classes = (TokenAuthentication, )
|
|
||||||
permission_classes = (IsAuthenticated,)
|
|
||||||
throttle_classes = (UserRateThrottle, )
|
|
||||||
|
|
||||||
def get(self, request, msg_id, format=None):
|
|
||||||
return html_get_group_discussion(request, msg_id)
|
|
||||||
|
|
||||||
def post(self, request, msg_id, format=None):
|
|
||||||
return html_msg_reply(request, msg_id)
|
|
||||||
|
|
||||||
class RepoHistoryChange(APIView):
|
class RepoHistoryChange(APIView):
|
||||||
authentication_classes = (TokenAuthentication, )
|
authentication_classes = (TokenAuthentication, )
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
@@ -4564,45 +4043,3 @@ class OrganizationView(APIView):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, "Internal error")
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, "Internal error")
|
||||||
|
|
||||||
#Following is only for debug
|
|
||||||
# from seahub.auth.decorators import login_required
|
|
||||||
# @login_required
|
|
||||||
# def activity2(request):
|
|
||||||
# return html_events(request)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def discussions2(request, group_id):
|
|
||||||
# return html_group_discussions(request, group_id)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def more_discussions2(request, group_id):
|
|
||||||
# return ajax_discussions(request, group_id)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def discussion2(request, msg_id):
|
|
||||||
# return html_get_group_discussion(request, msg_id)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def events2(request):
|
|
||||||
# return ajax_events(request)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def api_repo_history_changes(request, repo_id):
|
|
||||||
# return html_repo_history_changes(request, repo_id)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def api_msg_reply(request, msg_id):
|
|
||||||
# return html_msg_reply(request, msg_id)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def api_new_replies(request):
|
|
||||||
# return html_new_replies(request)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def api_usermsgs(request, id_or_email):
|
|
||||||
# return html_user_messages(request, id_or_email)
|
|
||||||
|
|
||||||
# @login_required
|
|
||||||
# def api_more_usermsgs(request, id_or_email):
|
|
||||||
# return ajax_usermsgs(request, id_or_email)
|
|
||||||
|
@@ -10,15 +10,6 @@ from tests.api.apitestbase import ApiTestBase
|
|||||||
from tests.api.urls import LIST_GROUP_AND_CONTACTS_URL, SERVER_INFO_URL
|
from tests.api.urls import LIST_GROUP_AND_CONTACTS_URL, SERVER_INFO_URL
|
||||||
|
|
||||||
class MiscApiTest(ApiTestBase, TestCase):
|
class MiscApiTest(ApiTestBase, TestCase):
|
||||||
def test_list_group_and_contacts(self):
|
|
||||||
res = self.get(LIST_GROUP_AND_CONTACTS_URL).json()
|
|
||||||
self.assertIsNotNone(res)
|
|
||||||
self.assertIsInstance(res['contacts'], list)
|
|
||||||
self.assertIsNotNone(res['umsgnum'])
|
|
||||||
self.assertIsNotNone(res['replynum'])
|
|
||||||
self.assertIsInstance(res['groups'], list)
|
|
||||||
self.assertIsNotNone(res['gmsgnum'])
|
|
||||||
self.assertIsNotNone(res['newreplies'])
|
|
||||||
|
|
||||||
def test_server_info(self):
|
def test_server_info(self):
|
||||||
r = requests.get(SERVER_INFO_URL)
|
r = requests.get(SERVER_INFO_URL)
|
||||||
|
Reference in New Issue
Block a user