1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 06:11:16 +00:00

[api] added repo_history_changes api

Also include commit_id in events api
This commit is contained in:
lins05
2014-06-10 10:13:51 +08:00
parent fe576c11a0
commit c625ca3a77
3 changed files with 62 additions and 2 deletions

View File

@@ -51,6 +51,7 @@ urlpatterns = patterns('',
url(r'^groupandcontacts/$', GroupAndContacts.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'^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/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'^group/(?P<group_id>\d+)/msg/(?P<msg_id>\d+)/$', GroupMsgView.as_view()),

View File

@@ -4,11 +4,13 @@
import os import os
import time import time
from collections import defaultdict
from django.core.paginator import EmptyPage, InvalidPage from django.core.paginator import EmptyPage, InvalidPage
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from seaserv import seafile_api, get_commits, server_repo_size, \ from seaserv import seafile_api, get_commits, server_repo_size, \
get_personal_groups_by_user, is_group_user, get_group get_personal_groups_by_user, is_group_user, get_group, seafserv_threaded_rpc
from pysearpc import SearpcError from pysearpc import SearpcError
from seahub.base.accounts import User from seahub.base.accounts import User
@@ -479,3 +481,26 @@ def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR', '') ip = request.META.get('REMOTE_ADDR', '')
return ip return ip
def get_diff_details(repo_id, commit1, commit2):
result = defaultdict(list)
diff_result = seafserv_threaded_rpc.get_diff(repo_id, commit1, commit2)
if not diff_result:
return result
for d in diff_result:
if d.status == 'add':
result['added_files'].append(d.name)
elif d.status == 'del':
result['deleted_files'].append(d.name)
elif d.status == 'mov':
result['renamed_files'].extend((d.name, d.new_name))
elif d.status == 'mod':
result['modified_files'].append(d.name)
elif d.status == 'newdir':
result['added_dirs'].append(d.name)
elif d.status == 'deldir':
result['deleted_dirs'].append(d.name)
return result

View File

@@ -30,7 +30,7 @@ from utils import is_repo_writable, is_repo_accessible, calculate_repo_info, \
api_error, get_file_size, prepare_starred_files, \ api_error, get_file_size, prepare_starred_files, \
get_groups, get_group_and_contacts, prepare_events, \ get_groups, get_group_and_contacts, prepare_events, \
get_person_msgs, api_group_check, get_email, get_timestamp, \ get_person_msgs, api_group_check, get_email, get_timestamp, \
get_group_message_json, get_group_msgs, get_group_msgs_json get_group_message_json, get_group_msgs, get_group_msgs_json, get_diff_details
from seahub.avatar.templatetags.avatar_tags import api_avatar_url from seahub.avatar.templatetags.avatar_tags import api_avatar_url
from seahub.avatar.templatetags.group_avatar_tags import api_grp_avatar_url from seahub.avatar.templatetags.group_avatar_tags import api_grp_avatar_url
from seahub.base.accounts import User from seahub.base.accounts import User
@@ -2393,6 +2393,7 @@ class EventsView(APIView):
d['desc'] = e.commit.desc d['desc'] = e.commit.desc
d['repo_id'] = e.repo.id d['repo_id'] = e.repo.id
d['repo_name'] = e.repo.name d['repo_name'] = e.repo.name
d['commit_id'] = e.commit.id
else: else:
d['repo_id'] = e.repo_id d['repo_id'] = e.repo_id
d['repo_name'] = e.repo_name d['repo_name'] = e.repo_name
@@ -3121,6 +3122,39 @@ class DiscussionHtml(APIView):
def post(self, request, msg_id, format=None): def post(self, request, msg_id, format=None):
return html_msg_reply(request, msg_id) return html_msg_reply(request, msg_id)
class RepoHistoryChange(APIView):
authentication_classes = (TokenAuthentication, )
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle, )
def get(self, request, repo_id, format=None):
if not access_to_repo(request, repo_id, ''):
return HttpResponse(json.dumps({"err": 'Permission denied'}),
status=400,
content_type=json_content_type)
repo = get_repo(repo_id)
if not repo:
return HttpResponse(json.dumps({"err": 'Library does not exist'}),
status=400,
content_type=json_content_type)
if repo.encrypted and not is_passwd_set(repo_id, request.user.username):
return HttpResponse(json.dumps({"err": 'Library is encrypted'}),
status=400,
content_type=json_content_type)
commit_id = request.GET.get('commit_id', '')
if not commit_id:
return HttpResponse(json.dumps({"err": 'Invalid argument'}),
status=400,
content_type=json_content_type)
details = get_diff_details(repo_id, '', commit_id)
return HttpResponse(json.dumps(details),
content_type=json_content_type)
class RepoHistoryChangeHtml(APIView): class RepoHistoryChangeHtml(APIView):
authentication_classes = (TokenAuthentication, ) authentication_classes = (TokenAuthentication, )
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)