2013-01-26 14:25:15 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
import logging
|
2012-08-13 21:26:58 +08:00
|
|
|
|
import os
|
2013-03-12 16:09:30 +08:00
|
|
|
|
import stat
|
2012-06-26 22:01:36 +08:00
|
|
|
|
import simplejson as json
|
2013-03-15 20:47:26 +08:00
|
|
|
|
import urllib2
|
2012-09-19 19:52:35 +08:00
|
|
|
|
from django.core.mail import send_mail
|
2013-03-19 11:49:52 +08:00
|
|
|
|
from django.core.paginator import EmptyPage, InvalidPage
|
2012-05-20 20:32:21 +08:00
|
|
|
|
from django.core.urlresolvers import reverse
|
2012-08-10 21:16:55 +08:00
|
|
|
|
from django.contrib import messages
|
2012-09-19 19:52:35 +08:00
|
|
|
|
from django.contrib.sites.models import RequestSite
|
2012-08-08 20:16:00 +08:00
|
|
|
|
from django.http import HttpResponse, HttpResponseRedirect, Http404, \
|
|
|
|
|
HttpResponseBadRequest
|
2013-04-04 19:57:52 +08:00
|
|
|
|
from django.shortcuts import render_to_response
|
2012-09-19 19:52:35 +08:00
|
|
|
|
from django.template import Context, loader, RequestContext
|
2012-08-09 16:36:11 +08:00
|
|
|
|
from django.template.loader import render_to_string
|
2013-04-03 11:49:32 +08:00
|
|
|
|
from django.utils.encoding import smart_str
|
2013-04-04 19:58:00 +08:00
|
|
|
|
from django.utils import datetime_safe
|
2013-03-15 20:47:26 +08:00
|
|
|
|
from django.utils.hashcompat import md5_constructor
|
2012-09-07 16:14:36 +08:00
|
|
|
|
from django.utils.translation import ugettext as _
|
2012-11-01 15:45:12 +08:00
|
|
|
|
from django.utils.translation import ungettext
|
2012-02-11 11:12:54 +08:00
|
|
|
|
|
2012-05-20 20:32:21 +08:00
|
|
|
|
from auth.decorators import login_required
|
2013-03-30 11:46:42 +08:00
|
|
|
|
import seaserv
|
2013-04-04 19:57:52 +08:00
|
|
|
|
from seaserv import ccnet_threaded_rpc, seafserv_threaded_rpc, seafserv_rpc, \
|
|
|
|
|
web_get_access_token, \
|
2013-03-30 11:46:42 +08:00
|
|
|
|
get_repo, get_group_repos, get_commits, is_group_user, \
|
2013-03-16 16:11:55 +08:00
|
|
|
|
get_personal_groups_by_user, get_group, get_group_members, create_repo, \
|
2012-09-22 17:46:56 +08:00
|
|
|
|
get_personal_groups, create_org_repo, get_org_group_repos, \
|
2013-04-04 19:57:52 +08:00
|
|
|
|
check_permission, is_passwd_set, remove_repo, \
|
2013-03-16 16:11:55 +08:00
|
|
|
|
unshare_group_repo, get_file_id_by_path, post_empty_file, del_file
|
2012-05-15 10:59:16 +08:00
|
|
|
|
from pysearpc import SearpcError
|
|
|
|
|
|
2012-10-22 11:54:06 +08:00
|
|
|
|
from decorators import group_staff_required
|
2013-03-29 11:46:28 +08:00
|
|
|
|
from models import GroupMessage, MessageReply, MessageAttachment, GroupWiki, \
|
|
|
|
|
PublicGroup
|
2012-09-18 14:04:47 +08:00
|
|
|
|
from forms import MessageForm, MessageReplyForm, GroupRecommendForm, \
|
2013-03-15 10:16:19 +08:00
|
|
|
|
GroupAddForm, GroupJoinMsgForm, WikiCreateForm
|
2012-06-27 16:39:49 +08:00
|
|
|
|
from signals import grpmsg_added, grpmsg_reply_added
|
2013-01-04 20:11:57 +08:00
|
|
|
|
from settings import GROUP_MEMBERS_DEFAULT_DISPLAY
|
2013-03-28 20:48:22 +08:00
|
|
|
|
from base.decorators import sys_staff_required
|
2013-04-04 19:58:00 +08:00
|
|
|
|
from base.models import FileDiscuss
|
2012-05-18 21:32:16 +08:00
|
|
|
|
from seahub.contacts.models import Contact
|
2012-07-31 14:58:47 +08:00
|
|
|
|
from seahub.contacts.signals import mail_sended
|
2012-06-25 21:40:18 +08:00
|
|
|
|
from seahub.notifications.models import UserNotification
|
2013-03-14 14:07:09 +08:00
|
|
|
|
from seahub.settings import SITE_ROOT, SITE_NAME, MEDIA_URL
|
2012-08-10 21:16:55 +08:00
|
|
|
|
from seahub.shortcuts import get_first_object_or_none
|
2013-04-04 19:57:52 +08:00
|
|
|
|
from seahub.utils import render_error, render_permission_error, string2list, \
|
|
|
|
|
check_and_get_org_by_group, gen_file_get_url, get_file_type_and_ext, \
|
2013-03-15 20:47:26 +08:00
|
|
|
|
get_file_contributors
|
2013-03-30 13:47:12 +08:00
|
|
|
|
from seahub.utils.file_types import IMAGE
|
2013-04-04 19:58:00 +08:00
|
|
|
|
from seahub.utils import calc_file_path_hash
|
2013-04-04 19:57:52 +08:00
|
|
|
|
from seahub.utils.paginator import Paginator
|
|
|
|
|
from seahub.utils.wiki import normalize_page_name, clean_page_name, get_wiki_dirent
|
2012-08-07 16:48:26 +08:00
|
|
|
|
from seahub.views import is_registered_user
|
2013-04-04 19:57:52 +08:00
|
|
|
|
from seahub.forms import SharedRepoCreateForm
|
2012-05-18 21:32:16 +08:00
|
|
|
|
|
2013-01-26 14:25:15 +08:00
|
|
|
|
# Get an instance of a logger
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-30 10:26:49 +08:00
|
|
|
|
def is_group_staff(group, user):
|
|
|
|
|
if user.is_anonymous():
|
|
|
|
|
return False
|
2013-03-30 11:46:42 +08:00
|
|
|
|
return seaserv.check_group_staff(group.id, user.username)
|
2013-03-30 10:26:49 +08:00
|
|
|
|
|
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
def group_check(func):
|
|
|
|
|
"""
|
|
|
|
|
Decorator for initial group permission check tasks
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
|
|
|
|
un-login user & group not pub --> public info page
|
|
|
|
|
un-login user & group pub --> view_perm = "pub"
|
|
|
|
|
login user & non group member & group not pub --> public info page
|
|
|
|
|
login user & non group member & group pub --> view_perm = "pub"
|
|
|
|
|
group member --> view_perm = "joined"
|
|
|
|
|
sys admin --> view_perm = "sys_admin"
|
2013-03-09 15:27:17 +08:00
|
|
|
|
"""
|
|
|
|
|
def _decorated(request, group_id, *args, **kwargs):
|
|
|
|
|
group_id_int = int(group_id) # Checked by URL Conf
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
2013-03-29 11:46:28 +08:00
|
|
|
|
group.is_staff = False
|
|
|
|
|
|
|
|
|
|
if not request.user.is_authenticated():
|
|
|
|
|
if not PublicGroup.objects.filter(group_id=group_id_int):
|
|
|
|
|
return render_to_response('group/group_pubinfo.html', {
|
|
|
|
|
'group': group,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
else:
|
|
|
|
|
group.view_perm = "pub"
|
|
|
|
|
return func(request, group, *args, **kwargs)
|
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
joined = is_group_user(group_id_int, request.user.username)
|
2013-03-29 11:46:28 +08:00
|
|
|
|
if joined:
|
|
|
|
|
group.view_perm = "joined"
|
2013-03-30 10:42:50 +08:00
|
|
|
|
group.is_staff = is_group_staff(group, request.user)
|
2013-03-29 11:46:28 +08:00
|
|
|
|
return func(request, group, *args, **kwargs)
|
|
|
|
|
if request.user.is_staff:
|
|
|
|
|
# viewed by system admin
|
|
|
|
|
group.view_perm = "sys_admin"
|
|
|
|
|
return func(request, group, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
pub = PublicGroup.objects.filter(group_id=group_id_int)
|
|
|
|
|
if pub:
|
|
|
|
|
group.view_perm = "pub"
|
|
|
|
|
return func(request, group, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
# Return group public info page.
|
|
|
|
|
return render_to_response('group/group_pubinfo.html', {
|
|
|
|
|
'group': group,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
return _decorated
|
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2012-11-22 16:47:57 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_list(request):
|
|
|
|
|
username = request.user.username
|
2012-09-17 21:38:54 +08:00
|
|
|
|
|
2012-11-22 16:47:57 +08:00
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
"""
|
|
|
|
|
Add a new group.
|
|
|
|
|
"""
|
2012-10-23 16:41:46 +08:00
|
|
|
|
result = {}
|
2012-11-22 16:47:57 +08:00
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
form = GroupAddForm(request.POST)
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
group_name = form.cleaned_data['group_name']
|
|
|
|
|
|
|
|
|
|
# Check whether group name is duplicated.
|
|
|
|
|
if request.cloud_mode:
|
|
|
|
|
checked_groups = get_personal_groups_by_user(username)
|
|
|
|
|
else:
|
|
|
|
|
checked_groups = get_personal_groups(-1, -1)
|
|
|
|
|
for g in checked_groups:
|
|
|
|
|
if g.group_name == group_name:
|
|
|
|
|
result['error'] = _(u'There is already a group with that name.')
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# Group name is valid, create that group.
|
|
|
|
|
try:
|
|
|
|
|
ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
|
|
|
|
username)
|
|
|
|
|
return HttpResponse(json.dumps({'success': True}),
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
result['error'] = _(e.msg)
|
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
|
|
|
|
content_type=content_type)
|
2012-09-18 14:04:47 +08:00
|
|
|
|
else:
|
2012-11-22 16:47:57 +08:00
|
|
|
|
return HttpResponseBadRequest(json.dumps(form.errors),
|
|
|
|
|
content_type=content_type)
|
2012-09-17 21:38:54 +08:00
|
|
|
|
|
2012-11-22 16:47:57 +08:00
|
|
|
|
### GET ###
|
|
|
|
|
joined_groups = get_personal_groups_by_user(username)
|
2012-09-17 21:38:54 +08:00
|
|
|
|
|
2012-11-22 16:47:57 +08:00
|
|
|
|
return render_to_response('group/groups.html', {
|
|
|
|
|
'joined_groups': joined_groups,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
@login_required
|
2013-03-28 20:48:22 +08:00
|
|
|
|
@sys_staff_required
|
2012-05-22 21:42:29 +08:00
|
|
|
|
def group_remove(request, group_id):
|
2012-08-03 11:32:11 +08:00
|
|
|
|
"""
|
2012-08-04 11:00:04 +08:00
|
|
|
|
Remove group from groupadmin page. Only system admin can perform this
|
|
|
|
|
operation.
|
2012-08-03 11:32:11 +08:00
|
|
|
|
"""
|
|
|
|
|
# Request header may missing HTTP_REFERER, we need to handle that case.
|
|
|
|
|
next = request.META.get('HTTP_REFERER', None)
|
|
|
|
|
if not next:
|
|
|
|
|
next = SITE_ROOT
|
|
|
|
|
|
2012-05-15 10:59:16 +08:00
|
|
|
|
try:
|
|
|
|
|
group_id_int = int(group_id)
|
|
|
|
|
except ValueError:
|
2012-08-03 11:32:11 +08:00
|
|
|
|
return HttpResponseRedirect(next)
|
|
|
|
|
|
2012-05-15 10:59:16 +08:00
|
|
|
|
try:
|
2012-06-25 20:42:19 +08:00
|
|
|
|
ccnet_threaded_rpc.remove_group(group_id_int, request.user.username)
|
2012-05-15 10:59:16 +08:00
|
|
|
|
seafserv_threaded_rpc.remove_repo_group(group_id_int, None)
|
2012-08-03 11:32:11 +08:00
|
|
|
|
except SearpcError, e:
|
2013-01-10 13:35:49 +08:00
|
|
|
|
return render_error(request, _(e.msg))
|
2012-08-03 11:32:11 +08:00
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(next)
|
|
|
|
|
|
|
|
|
|
@login_required
|
2013-03-30 11:03:54 +08:00
|
|
|
|
@group_staff_required
|
2012-08-03 11:32:11 +08:00
|
|
|
|
def group_dismiss(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Dismiss a group, only group staff can perform this operation.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
group_id_int = int(group_id)
|
|
|
|
|
except ValueError:
|
2013-03-30 10:26:49 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
2012-08-03 11:32:11 +08:00
|
|
|
|
|
2013-03-30 10:26:49 +08:00
|
|
|
|
username = request.user.username
|
2012-08-03 11:32:11 +08:00
|
|
|
|
try:
|
2013-03-30 10:26:49 +08:00
|
|
|
|
ccnet_threaded_rpc.remove_group(group.id, username)
|
|
|
|
|
seafserv_threaded_rpc.remove_repo_group(group.id, None)
|
2013-03-30 11:03:54 +08:00
|
|
|
|
|
|
|
|
|
if request.user.org:
|
|
|
|
|
org_id = request.user.org['org_id']
|
|
|
|
|
url_prefix = request.user.org['url_prefix']
|
|
|
|
|
ccnet_threaded_rpc.remove_org_group(org_id, group_id_int)
|
|
|
|
|
return HttpResponseRedirect(reverse('org_groups',
|
|
|
|
|
args=[url_prefix]))
|
|
|
|
|
|
2012-05-15 10:59:16 +08:00
|
|
|
|
except SearpcError, e:
|
2013-01-10 13:35:49 +08:00
|
|
|
|
return render_error(request, _(e.msg))
|
2012-08-03 11:32:11 +08:00
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list'))
|
2012-05-15 10:59:16 +08:00
|
|
|
|
|
2013-03-30 11:01:43 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_make_public(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Make a group public, only group staff can perform this operation.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
group_id_int = int(group_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
|
|
|
|
# Check whether user is group staff
|
|
|
|
|
if not is_group_staff(group, request.user):
|
|
|
|
|
return render_permission_error(request, _(u'Only administrators can make the group public'))
|
|
|
|
|
|
|
|
|
|
p = PublicGroup(group_id=group.id)
|
|
|
|
|
p.save()
|
|
|
|
|
return HttpResponseRedirect(reverse('group_manage', args=[group_id]))
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def group_revoke_public(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Revoke a group from public, only group staff can perform this operation.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
group_id_int = int(group_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
|
|
|
|
# Check whether user is group staff
|
|
|
|
|
if not is_group_staff(group, request.user):
|
|
|
|
|
return render_permission_error(request, _(u'Only administrators can make the group public'))
|
|
|
|
|
|
|
|
|
|
try:
|
2013-03-31 19:22:57 +08:00
|
|
|
|
p = PublicGroup.objects.get(group_id=group.id)
|
2013-03-30 11:01:43 +08:00
|
|
|
|
p.delete()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('group_manage', args=[group_id]))
|
|
|
|
|
|
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_quit(request, group_id):
|
|
|
|
|
try:
|
|
|
|
|
group_id_int = int(group_id)
|
|
|
|
|
except ValueError:
|
2013-03-30 10:26:49 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
try:
|
2012-06-25 20:42:19 +08:00
|
|
|
|
ccnet_threaded_rpc.quit_group(group_id_int, request.user.username)
|
2012-05-26 20:52:53 +08:00
|
|
|
|
seafserv_threaded_rpc.remove_repo_group(group_id_int,
|
|
|
|
|
request.user.username)
|
2012-05-22 21:42:29 +08:00
|
|
|
|
except SearpcError, e:
|
2013-01-10 13:35:49 +08:00
|
|
|
|
return render_error(request, _(e.msg))
|
2012-05-22 21:42:29 +08:00
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
|
|
|
|
|
2012-10-18 10:57:02 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_message_remove(request, group_id, msg_id):
|
|
|
|
|
"""
|
|
|
|
|
Remove group message and all message replies and attachments.
|
|
|
|
|
"""
|
|
|
|
|
# Checked by URL Conf
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group_id_int = int(group_id)
|
2012-10-18 10:57:02 +08:00
|
|
|
|
msg_id = int(msg_id)
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2012-10-18 10:57:02 +08:00
|
|
|
|
# Test whether user is in the group
|
2013-03-30 10:42:50 +08:00
|
|
|
|
if not is_group_user(group_id_int, request.user.username):
|
2012-10-18 10:57:02 +08:00
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
gm = GroupMessage.objects.get(id=msg_id)
|
|
|
|
|
except GroupMessage.DoesNotExist:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return HttpResponse(json.dumps({'success': False, 'err_msg':_(u"The message doesn't exist")}),
|
2012-10-25 16:48:08 +08:00
|
|
|
|
content_type='application/json; charset=utf-8')
|
2012-10-18 10:57:02 +08:00
|
|
|
|
else:
|
2012-10-18 13:55:24 +08:00
|
|
|
|
# Test whether user is group admin or message owner.
|
2013-03-30 11:46:42 +08:00
|
|
|
|
if seaserv.check_group_staff(group_id, request.user.username) or \
|
2012-10-18 13:55:24 +08:00
|
|
|
|
gm.from_email == request.user.username:
|
|
|
|
|
gm.delete()
|
2012-10-25 16:48:08 +08:00
|
|
|
|
return HttpResponse(json.dumps({'success': True}),
|
|
|
|
|
content_type='application/json; charset=utf-8')
|
2012-10-18 13:55:24 +08:00
|
|
|
|
else:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return HttpResponse(json.dumps({'success': False, 'err_msg': _(u"You don't have the permission.")}),
|
2012-10-25 16:48:08 +08:00
|
|
|
|
content_type='application/json; charset=utf-8')
|
2012-10-18 10:57:02 +08:00
|
|
|
|
|
2012-06-25 14:57:14 +08:00
|
|
|
|
def msg_reply(request, msg_id):
|
|
|
|
|
"""Show group message replies, and process message reply in ajax"""
|
2012-08-08 20:16:00 +08:00
|
|
|
|
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
2012-06-25 14:57:14 +08:00
|
|
|
|
if request.is_ajax():
|
2012-08-16 20:20:41 +08:00
|
|
|
|
ctx = {}
|
2013-03-12 21:48:47 +08:00
|
|
|
|
try:
|
|
|
|
|
group_msg = GroupMessage.objects.get(id=msg_id)
|
|
|
|
|
except GroupMessage.DoesNotExist:
|
|
|
|
|
return HttpResponseBadRequest(content_type=content_type)
|
|
|
|
|
|
2012-06-25 14:57:14 +08:00
|
|
|
|
if request.method == 'POST':
|
2012-06-27 11:27:00 +08:00
|
|
|
|
form = MessageReplyForm(request.POST)
|
2012-06-25 14:57:14 +08:00
|
|
|
|
# TODO: invalid form
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
msg = form.cleaned_data['message']
|
2013-03-12 21:48:47 +08:00
|
|
|
|
|
2012-06-25 14:57:14 +08:00
|
|
|
|
msg_reply = MessageReply()
|
|
|
|
|
msg_reply.reply_to = group_msg
|
|
|
|
|
msg_reply.from_email = request.user.username
|
|
|
|
|
msg_reply.message = msg
|
|
|
|
|
msg_reply.save()
|
2012-06-27 16:39:49 +08:00
|
|
|
|
|
|
|
|
|
# send signal if reply other's message
|
|
|
|
|
if group_msg.from_email != request.user.username:
|
|
|
|
|
grpmsg_reply_added.send(sender=MessageReply,
|
|
|
|
|
msg_id=msg_id,
|
|
|
|
|
from_email=request.user.username)
|
2013-03-12 21:48:47 +08:00
|
|
|
|
replies = MessageReply.objects.filter(reply_to=group_msg)
|
|
|
|
|
r_num = len(replies)
|
|
|
|
|
if r_num < 4:
|
|
|
|
|
ctx['replies'] = replies
|
|
|
|
|
else:
|
|
|
|
|
ctx['replies'] = replies[r_num - 3:]
|
|
|
|
|
html = render_to_string("group/group_reply_list.html", ctx)
|
|
|
|
|
serialized_data = json.dumps({"r_num": r_num, "html": html})
|
|
|
|
|
return HttpResponse(serialized_data, content_type=content_type)
|
2012-08-16 20:20:41 +08:00
|
|
|
|
|
2012-08-14 16:33:16 +08:00
|
|
|
|
else:
|
2013-03-12 21:48:47 +08:00
|
|
|
|
replies = MessageReply.objects.filter(reply_to=group_msg)
|
|
|
|
|
r_num = len(replies)
|
2012-08-14 16:33:16 +08:00
|
|
|
|
ctx['replies'] = replies
|
2012-08-16 20:20:41 +08:00
|
|
|
|
html = render_to_string("group/group_reply_list.html", ctx)
|
2013-03-12 21:48:47 +08:00
|
|
|
|
serialized_data = json.dumps({"r_num": r_num, "html": html})
|
|
|
|
|
return HttpResponse(serialized_data, content_type=content_type)
|
2012-06-25 14:57:14 +08:00
|
|
|
|
else:
|
2012-08-09 16:36:11 +08:00
|
|
|
|
return HttpResponseBadRequest(content_type=content_type)
|
2012-06-25 14:57:14 +08:00
|
|
|
|
|
2012-06-27 16:39:49 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def msg_reply_new(request):
|
|
|
|
|
notes = UserNotification.objects.filter(to_user=request.user.username)
|
2012-09-11 10:11:44 +08:00
|
|
|
|
grpmsg_reply_list = [ n.detail for n in notes if \
|
|
|
|
|
n.msg_type == 'grpmsg_reply']
|
2012-06-27 16:39:49 +08:00
|
|
|
|
|
|
|
|
|
group_msgs = []
|
|
|
|
|
for msg_id in grpmsg_reply_list:
|
|
|
|
|
try:
|
|
|
|
|
m = GroupMessage.objects.get(id=msg_id)
|
2012-08-16 17:54:21 +08:00
|
|
|
|
except GroupMessage.DoesNotExist:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
2012-06-27 19:56:11 +08:00
|
|
|
|
# get group name
|
2012-08-01 22:45:58 +08:00
|
|
|
|
group = get_group(m.group_id)
|
|
|
|
|
if not group:
|
|
|
|
|
continue
|
2012-06-27 19:56:11 +08:00
|
|
|
|
m.group_name = group.group_name
|
|
|
|
|
|
2012-08-16 17:13:03 +08:00
|
|
|
|
# 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
|
|
|
|
|
|
2012-06-27 16:39:49 +08:00
|
|
|
|
# get message replies
|
|
|
|
|
reply_list = MessageReply.objects.filter(reply_to=m)
|
2012-08-16 17:54:21 +08:00
|
|
|
|
m.reply_cnt = reply_list.count()
|
2013-03-15 14:41:20 +08:00
|
|
|
|
if m.reply_cnt > 3:
|
|
|
|
|
m.replies = reply_list[m.reply_cnt - 3:]
|
|
|
|
|
else:
|
|
|
|
|
m.replies = reply_list
|
|
|
|
|
|
2012-06-27 16:39:49 +08:00
|
|
|
|
group_msgs.append(m)
|
|
|
|
|
|
|
|
|
|
# remove new group msg reply notification
|
|
|
|
|
UserNotification.objects.filter(to_user=request.user.username,
|
|
|
|
|
msg_type='grpmsg_reply').delete()
|
|
|
|
|
|
|
|
|
|
return render_to_response("group/new_msg_reply.html", {
|
|
|
|
|
'group_msgs': group_msgs,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-30 10:26:49 +08:00
|
|
|
|
def group_info_for_pub(request, group):
|
|
|
|
|
return render_to_response("group/group_info_for_pub.html", {
|
2013-03-29 11:46:28 +08:00
|
|
|
|
"repos": [],
|
2013-03-30 10:26:49 +08:00
|
|
|
|
"group": group,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
|
|
|
|
|
2013-03-28 20:48:22 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_info(request, group):
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
|
|
|
|
if group.view_perm == "pub":
|
2013-03-30 10:26:49 +08:00
|
|
|
|
return group_info_for_pub(request, group)
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-28 20:48:22 +08:00
|
|
|
|
# Get all group members.
|
|
|
|
|
members = get_group_members(group.id)
|
2012-06-25 14:57:14 +08:00
|
|
|
|
|
2013-03-28 20:48:22 +08:00
|
|
|
|
org = request.user.org
|
|
|
|
|
if org:
|
|
|
|
|
repos = get_org_group_repos(org['org_id'], group.id,
|
|
|
|
|
request.user.username)
|
|
|
|
|
else:
|
|
|
|
|
repos = get_group_repos(group.id, request.user.username)
|
|
|
|
|
|
|
|
|
|
recent_commits = []
|
|
|
|
|
cmt_repo_dict = {}
|
|
|
|
|
for repo in repos:
|
|
|
|
|
repo.user_perm = check_permission(repo.props.id, request.user.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,
|
|
|
|
|
request.user.username)
|
|
|
|
|
cmt.tp = cmt.props.desc.split(' ')[0]
|
2012-06-25 14:57:14 +08:00
|
|
|
|
|
2013-03-28 20:48:22 +08:00
|
|
|
|
return render_to_response("group/group_info.html", {
|
|
|
|
|
"members": members,
|
|
|
|
|
"repos": repos,
|
|
|
|
|
"recent_commits": recent_commits,
|
|
|
|
|
"group" : group,
|
2013-03-29 11:46:28 +08:00
|
|
|
|
"is_staff": group.is_staff,
|
2013-03-28 20:48:22 +08:00
|
|
|
|
'create_shared_repo': True,
|
|
|
|
|
'group_members_default_display': GROUP_MEMBERS_DEFAULT_DISPLAY,
|
2013-04-04 19:57:52 +08:00
|
|
|
|
}, context_instance=RequestContext(request))
|
2012-06-25 14:57:14 +08:00
|
|
|
|
|
2013-03-31 14:46:40 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_members(request, group):
|
|
|
|
|
|
2013-04-01 13:50:17 +08:00
|
|
|
|
if group.view_perm == 'pub':
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-31 14:46:40 +08:00
|
|
|
|
# Get all group members.
|
|
|
|
|
members = get_group_members(group.id)
|
|
|
|
|
|
|
|
|
|
user = request.user.username
|
|
|
|
|
contacts = Contact.objects.filter(user_email=user)
|
|
|
|
|
contact_emails = []
|
|
|
|
|
for c in contacts:
|
|
|
|
|
contact_emails.append(c.contact_email)
|
|
|
|
|
for m in members:
|
|
|
|
|
if m.user_name == user or m.user_name in contact_emails:
|
|
|
|
|
m.can_be_contact = False
|
|
|
|
|
else:
|
|
|
|
|
m.can_be_contact = True
|
|
|
|
|
|
|
|
|
|
return render_to_response("group/group_members.html", {
|
|
|
|
|
"members": members,
|
|
|
|
|
"group" : group,
|
|
|
|
|
"is_staff": group.is_staff,
|
2013-04-04 19:57:52 +08:00
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-31 14:46:40 +08:00
|
|
|
|
|
2012-05-15 10:59:16 +08:00
|
|
|
|
@login_required
|
2012-10-22 11:54:06 +08:00
|
|
|
|
@group_staff_required
|
2013-03-30 10:26:49 +08:00
|
|
|
|
def group_manage(request, group_id):
|
|
|
|
|
group_id_int = int(group_id) # Checked by URL Conf
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
return HttpResponseRedirect(reverse('group_list', args=[]))
|
2012-10-22 11:54:06 +08:00
|
|
|
|
user = request.user.username
|
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
"""
|
|
|
|
|
Add group members.
|
|
|
|
|
"""
|
2012-09-06 17:20:15 +08:00
|
|
|
|
result = {}
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
2012-07-31 14:58:47 +08:00
|
|
|
|
|
2012-10-22 11:54:06 +08:00
|
|
|
|
member_name_str = request.POST.get('user_name', '')
|
2012-08-10 21:16:55 +08:00
|
|
|
|
member_list = string2list(member_name_str)
|
2012-05-18 21:32:16 +08:00
|
|
|
|
|
2012-10-22 11:54:06 +08:00
|
|
|
|
# Add users to contacts.
|
|
|
|
|
for email in member_list:
|
|
|
|
|
mail_sended.send(sender=None, user=user, email=email)
|
2012-10-22 17:50:09 +08:00
|
|
|
|
|
|
|
|
|
mail_sended_list = []
|
2012-10-22 11:54:06 +08:00
|
|
|
|
if request.cloud_mode:
|
|
|
|
|
if request.user.org:
|
|
|
|
|
# Can only invite org users to group.
|
|
|
|
|
org_id = request.user.org['org_id']
|
|
|
|
|
for email in member_list:
|
|
|
|
|
if not ccnet_threaded_rpc.org_user_exists(org_id, email):
|
2012-11-01 15:45:12 +08:00
|
|
|
|
err_msg = _(u'Failed to add, %s is not in current organization.') % email
|
2012-10-22 11:54:06 +08:00
|
|
|
|
result['error'] = err_msg
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
else:
|
|
|
|
|
try:
|
2013-03-09 15:40:58 +08:00
|
|
|
|
ccnet_threaded_rpc.group_add_member(group.id,
|
2012-10-22 11:54:06 +08:00
|
|
|
|
user, email)
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
result['error'] = _(e.msg)
|
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
else:
|
|
|
|
|
# Can invite unregistered user to group.
|
|
|
|
|
for email in member_list:
|
|
|
|
|
if not is_registered_user(email):
|
|
|
|
|
use_https = request.is_secure()
|
|
|
|
|
domain = RequestSite(request).domain
|
|
|
|
|
|
|
|
|
|
t = loader.get_template('group/add_member_email.html')
|
|
|
|
|
c = {
|
|
|
|
|
'email': user,
|
|
|
|
|
'to_email': email,
|
|
|
|
|
'group': group,
|
|
|
|
|
'domain': domain,
|
|
|
|
|
'protocol': use_https and 'https' or 'http',
|
2012-11-06 19:42:56 +08:00
|
|
|
|
'site_name': SITE_NAME,
|
2012-10-22 11:54:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try:
|
2013-01-10 14:47:07 +08:00
|
|
|
|
send_mail(_(u'Your friend added you to a group at Seafile.'),
|
2012-10-22 11:54:06 +08:00
|
|
|
|
t.render(Context(c)), None, [email],
|
|
|
|
|
fail_silently=False)
|
2012-10-22 17:50:09 +08:00
|
|
|
|
mail_sended_list.append(email)
|
2012-10-22 11:54:06 +08:00
|
|
|
|
except:
|
|
|
|
|
data = json.dumps({'error': _(u'Failed to send mail.')})
|
|
|
|
|
return HttpResponse(data, status=500,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# Add user to group, unregistered user will see the group
|
|
|
|
|
# when he logs in.
|
2012-06-20 19:39:21 +08:00
|
|
|
|
try:
|
2013-03-09 15:40:58 +08:00
|
|
|
|
ccnet_threaded_rpc.group_add_member(group.id,
|
2012-10-22 11:54:06 +08:00
|
|
|
|
user, email)
|
2012-06-20 19:39:21 +08:00
|
|
|
|
except SearpcError, e:
|
2012-09-07 16:14:36 +08:00
|
|
|
|
result['error'] = _(e.msg)
|
2012-09-19 19:52:35 +08:00
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
2012-09-06 17:20:15 +08:00
|
|
|
|
content_type=content_type)
|
2012-06-20 19:39:21 +08:00
|
|
|
|
else:
|
2012-10-22 11:54:06 +08:00
|
|
|
|
# Can only invite registered user to group if not in cloud mode.
|
|
|
|
|
for email in member_list:
|
|
|
|
|
if not is_registered_user(email):
|
2012-11-01 15:45:12 +08:00
|
|
|
|
err_msg = _(u'Failed to add, %s is not registerd.')
|
2012-10-22 11:54:06 +08:00
|
|
|
|
result['error'] = err_msg % email
|
2012-09-26 20:22:09 +08:00
|
|
|
|
return HttpResponse(json.dumps(result), status=400,
|
|
|
|
|
content_type=content_type)
|
2012-09-19 19:52:35 +08:00
|
|
|
|
# Add user to group.
|
|
|
|
|
try:
|
2013-03-09 15:40:58 +08:00
|
|
|
|
ccnet_threaded_rpc.group_add_member(group.id,
|
2012-10-22 11:54:06 +08:00
|
|
|
|
user, email)
|
2012-09-19 19:52:35 +08:00
|
|
|
|
except SearpcError, e:
|
|
|
|
|
result['error'] = _(e.msg)
|
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
|
|
|
|
content_type=content_type)
|
2012-10-22 17:50:09 +08:00
|
|
|
|
if mail_sended_list:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
msg = ungettext(
|
|
|
|
|
'Successfully added. An email has been sent.',
|
|
|
|
|
'Successfully added. %(count)s emails have been sent.',
|
2012-11-13 11:40:30 +08:00
|
|
|
|
len(mail_sended_list)) % {
|
2012-11-01 15:45:12 +08:00
|
|
|
|
'count': len(mail_sended_list),
|
|
|
|
|
}
|
|
|
|
|
messages.success(request, msg)
|
|
|
|
|
|
2012-10-22 17:50:09 +08:00
|
|
|
|
else:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
messages.success(request, _(u'Successfully added.'))
|
2012-09-19 19:52:35 +08:00
|
|
|
|
return HttpResponse(json.dumps('success'), status=200,
|
2012-09-06 17:20:15 +08:00
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
|
|
|
|
### GET ###
|
2013-03-09 15:40:58 +08:00
|
|
|
|
members_all = ccnet_threaded_rpc.get_group_members(group.id)
|
2012-10-22 17:50:09 +08:00
|
|
|
|
admins = [ m for m in members_all if m.is_staff ]
|
|
|
|
|
|
2012-10-22 11:54:06 +08:00
|
|
|
|
contacts = Contact.objects.filter(user_email=user)
|
2012-08-30 20:15:17 +08:00
|
|
|
|
|
2013-03-30 11:01:43 +08:00
|
|
|
|
if PublicGroup.objects.filter(group_id=group.id):
|
|
|
|
|
is_pub = True
|
|
|
|
|
else:
|
|
|
|
|
is_pub = False
|
|
|
|
|
|
2012-05-16 14:10:54 +08:00
|
|
|
|
return render_to_response('group/group_manage.html', {
|
2012-05-17 23:50:04 +08:00
|
|
|
|
'group' : group,
|
2012-10-22 16:22:55 +08:00
|
|
|
|
'members': members_all,
|
2012-10-19 10:33:54 +08:00
|
|
|
|
'admins': admins,
|
2012-05-18 21:32:16 +08:00
|
|
|
|
'contacts': contacts,
|
2013-03-30 11:01:43 +08:00
|
|
|
|
'is_pub': is_pub,
|
2012-05-16 14:10:54 +08:00
|
|
|
|
}, context_instance=RequestContext(request))
|
2012-10-18 19:54:00 +08:00
|
|
|
|
|
|
|
|
|
@login_required
|
2012-10-22 16:22:55 +08:00
|
|
|
|
@group_staff_required
|
2012-10-18 19:54:00 +08:00
|
|
|
|
def group_add_admin(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Add group admin.
|
|
|
|
|
"""
|
|
|
|
|
group_id = int(group_id) # Checked by URL Conf
|
|
|
|
|
|
|
|
|
|
if request.method != 'POST' or not request.is_ajax():
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
member_name_str = request.POST.get('user_name', '')
|
|
|
|
|
member_list = string2list(member_name_str)
|
|
|
|
|
|
|
|
|
|
for member_name in member_list:
|
|
|
|
|
# Add user to contacts.
|
|
|
|
|
mail_sended.send(sender=None, user=request.user.username,
|
|
|
|
|
email=member_name)
|
|
|
|
|
|
|
|
|
|
if not is_registered_user(member_name):
|
2012-11-01 15:45:12 +08:00
|
|
|
|
err_msg = _(u'Failed to add, %s is not registrated.') % member_name
|
2012-10-18 19:54:00 +08:00
|
|
|
|
result['error'] = err_msg
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# Check whether user is in the group
|
|
|
|
|
if is_group_user(group_id, member_name):
|
2012-10-20 10:12:29 +08:00
|
|
|
|
try:
|
|
|
|
|
ccnet_threaded_rpc.group_set_admin(group_id, member_name)
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
result['error'] = _(e.msg)
|
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
|
|
|
|
content_type=content_type)
|
2012-10-18 19:54:00 +08:00
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
ccnet_threaded_rpc.group_add_member(group_id,
|
|
|
|
|
request.user.username,
|
|
|
|
|
member_name)
|
|
|
|
|
ccnet_threaded_rpc.group_set_admin(group_id, member_name)
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
result['error'] = _(e.msg)
|
|
|
|
|
return HttpResponse(json.dumps(result), status=500,
|
|
|
|
|
content_type=content_type)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
messages.success(request, _(u'Operation succeeded.'))
|
2012-10-18 19:54:00 +08:00
|
|
|
|
return HttpResponse(json.dumps('success'), status=200,
|
|
|
|
|
content_type=content_type)
|
2012-10-22 16:22:55 +08:00
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
@group_staff_required
|
|
|
|
|
def group_remove_admin(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Remove group admin, and becomes normal group member.
|
|
|
|
|
"""
|
|
|
|
|
user = request.GET.get('u', '')
|
|
|
|
|
try:
|
|
|
|
|
ccnet_threaded_rpc.group_unset_admin(int(group_id), user)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
messages.success(request, _(u'Operation succeeded.'))
|
2012-10-22 16:22:55 +08:00
|
|
|
|
except SearpcError, e:
|
2013-01-10 13:35:49 +08:00
|
|
|
|
messages.error(request, _(e.msg))
|
2013-03-18 17:19:44 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_manage', args=[group_id]))
|
2012-05-16 14:10:54 +08:00
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_member_operations(request, group_id, user_name):
|
|
|
|
|
if request.GET.get('op','') == 'delete':
|
|
|
|
|
return group_remove_member(request, group_id, user_name)
|
|
|
|
|
else:
|
2013-03-18 17:19:44 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_manage', args=[group_id]))
|
2012-05-22 21:42:29 +08:00
|
|
|
|
|
|
|
|
|
def group_remove_member(request, group_id, user_name):
|
2013-03-30 11:03:54 +08:00
|
|
|
|
group_id_int = int(group_id) # Checked by URLConf
|
2013-03-30 10:26:49 +08:00
|
|
|
|
|
|
|
|
|
group = get_group(group_id_int)
|
|
|
|
|
if not group:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
if not is_group_staff(group, request.user):
|
2013-03-30 11:03:54 +08:00
|
|
|
|
raise Http404
|
2012-09-28 10:47:51 +08:00
|
|
|
|
|
2012-07-09 10:37:42 +08:00
|
|
|
|
try:
|
2013-03-30 10:26:49 +08:00
|
|
|
|
ccnet_threaded_rpc.group_remove_member(group.id,
|
2012-07-09 10:37:42 +08:00
|
|
|
|
request.user.username,
|
|
|
|
|
user_name)
|
2013-03-30 10:26:49 +08:00
|
|
|
|
seafserv_threaded_rpc.remove_repo_group(group.id, user_name)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
messages.success(request, _(u'Operation succeeded.'))
|
2012-07-09 10:37:42 +08:00
|
|
|
|
except SearpcError, e:
|
2013-01-10 13:35:49 +08:00
|
|
|
|
messages.error(request, _(u'Failed:%s') % _(e.msg))
|
2012-05-22 21:42:29 +08:00
|
|
|
|
|
2013-03-18 17:19:44 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_manage', args=[group_id]))
|
2012-09-03 12:03:06 +08:00
|
|
|
|
|
2012-09-21 11:22:46 +08:00
|
|
|
|
def group_share_repo(request, repo_id, group_id, from_email, permission):
|
2012-05-15 14:29:37 +08:00
|
|
|
|
"""
|
2012-05-22 21:42:29 +08:00
|
|
|
|
Share a repo to a group.
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
|
|
|
|
"""
|
2012-05-22 21:42:29 +08:00
|
|
|
|
# Check whether group exists
|
2012-08-01 22:45:58 +08:00
|
|
|
|
group = get_group(group_id)
|
2012-05-15 14:29:37 +08:00
|
|
|
|
if not group:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return render_error(request, _(u"Failed to share: the group doesn't exist."))
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
2012-09-21 11:22:46 +08:00
|
|
|
|
if seafserv_threaded_rpc.group_share_repo(repo_id, group_id, from_email, permission) != 0:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return render_error(request, _(u"Failed to share: internal error."))
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
|
|
|
|
def group_unshare_repo(request, repo_id, group_id, from_email):
|
|
|
|
|
"""
|
2012-09-03 12:03:06 +08:00
|
|
|
|
Unshare a repo in group.
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
|
|
|
|
"""
|
2012-05-22 21:42:29 +08:00
|
|
|
|
# Check whether group exists
|
2012-08-01 22:45:58 +08:00
|
|
|
|
group = get_group(group_id)
|
2012-05-15 14:29:37 +08:00
|
|
|
|
if not group:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return render_error(request, _(u"Failed to unshare: the group doesn't exist."))
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
2012-05-22 21:42:29 +08:00
|
|
|
|
# Check whether user is group staff or the one share the repo
|
2013-03-30 11:46:42 +08:00
|
|
|
|
if not seaserv.check_group_staff(group_id, from_email) and \
|
2012-09-03 16:14:15 +08:00
|
|
|
|
seafserv_threaded_rpc.get_group_repo_owner(repo_id) != from_email:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return render_permission_error(request, _(u"Operation failed: only administrators and the owner of the library can unshare it."))
|
2012-05-15 14:29:37 +08:00
|
|
|
|
|
2013-02-20 20:51:37 +08:00
|
|
|
|
if unshare_group_repo(repo_id, group_id, from_email) != 0:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return render_error(request, _(u"Failed to unshare: internal error."))
|
2012-08-10 21:16:55 +08:00
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def group_recommend(request):
|
|
|
|
|
"""
|
2012-08-13 15:58:54 +08:00
|
|
|
|
Recommend a file or directory to a group.
|
2013-04-04 19:58:00 +08:00
|
|
|
|
now changed to 'Discuss'
|
|
|
|
|
for ajax post/get
|
2012-08-10 21:16:55 +08:00
|
|
|
|
"""
|
2013-04-04 19:58:00 +08:00
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
result = {}
|
|
|
|
|
if request.method == 'POST':
|
2012-09-14 11:39:33 +08:00
|
|
|
|
|
2013-04-04 19:58:00 +08:00
|
|
|
|
form = GroupRecommendForm(request.POST)
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
repo_id = form.cleaned_data['repo_id']
|
|
|
|
|
attach_type = form.cleaned_data['attach_type']
|
|
|
|
|
path = form.cleaned_data['path']
|
|
|
|
|
message = form.cleaned_data['message']
|
|
|
|
|
groups = request.POST.getlist('groups') # groups is a group_id list, e.g. [u'1', u'7']
|
|
|
|
|
username = request.user.username
|
|
|
|
|
|
|
|
|
|
groups_not_in = []
|
|
|
|
|
groups_posted_to = []
|
|
|
|
|
for group_id in groups:
|
|
|
|
|
# Check group id format
|
|
|
|
|
try:
|
|
|
|
|
group_id = int(group_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
result['err'] = _(u'Error: wrong group id')
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
|
|
|
|
|
|
|
|
|
group = get_group(group_id)
|
|
|
|
|
if not group:
|
|
|
|
|
result['err'] = _(u'Error: the group does not exist.')
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# TODO: Check whether repo is in the group and Im in the group
|
|
|
|
|
if not is_group_user(group_id, username):
|
|
|
|
|
groups_not_in.append(group.group_name)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# save message to group
|
|
|
|
|
gm = GroupMessage(group_id=group_id, from_email=username,
|
2012-10-20 15:22:27 +08:00
|
|
|
|
message=message)
|
2013-04-04 19:58:00 +08:00
|
|
|
|
gm.save()
|
2012-09-14 11:39:33 +08:00
|
|
|
|
|
2013-04-04 19:58:00 +08:00
|
|
|
|
# send signal
|
|
|
|
|
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
|
2012-10-20 15:22:27 +08:00
|
|
|
|
from_email=request.user.username)
|
2012-08-16 17:54:21 +08:00
|
|
|
|
|
2013-04-04 19:58:00 +08:00
|
|
|
|
# save attachment
|
|
|
|
|
ma = MessageAttachment(group_message=gm, repo_id=repo_id,
|
2012-10-20 15:22:27 +08:00
|
|
|
|
attach_type=attach_type, path=path,
|
|
|
|
|
src='recommend')
|
2013-04-04 19:58:00 +08:00
|
|
|
|
ma.save()
|
|
|
|
|
|
|
|
|
|
# save discussion
|
|
|
|
|
fd = FileDiscuss(group_message=gm, repo_id=repo_id, path=path)
|
|
|
|
|
fd.save()
|
|
|
|
|
|
|
|
|
|
group_url = reverse('group_discuss', args=[group_id])
|
|
|
|
|
groups_posted_to.append(u'<a href="%(url)s" target="_blank">%(name)s</a>' % \
|
|
|
|
|
{'url':group_url, 'name':group.group_name})
|
2012-10-20 15:22:27 +08:00
|
|
|
|
|
2013-04-04 19:58:00 +08:00
|
|
|
|
if len(groups_posted_to) > 0:
|
|
|
|
|
result['success'] = _(u'Successfully posted to %(groups)s.') % {'groups': ', '.join(groups_posted_to)}
|
2012-10-20 15:22:27 +08:00
|
|
|
|
|
2013-04-04 19:58:00 +08:00
|
|
|
|
if len(groups_not_in) > 0:
|
|
|
|
|
result['err'] = _(u'Error: you are not in group %s.') % (', '.join(groups_not_in))
|
|
|
|
|
|
|
|
|
|
else:
|
2013-04-05 11:52:37 +08:00
|
|
|
|
result['err'] = str(form.errors)
|
2013-04-04 19:58:00 +08:00
|
|
|
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# request.method == 'GET'
|
2012-08-10 21:16:55 +08:00
|
|
|
|
else:
|
2013-04-04 19:58:00 +08:00
|
|
|
|
repo_id = request.GET.get('repo_id')
|
|
|
|
|
path = request.GET.get('path', None)
|
|
|
|
|
repo = get_repo(repo_id)
|
|
|
|
|
if not repo:
|
|
|
|
|
result['err'] = _(u'Error: the library does not exist.')
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
|
|
|
|
if path is None:
|
|
|
|
|
result['err'] = _(u'Error: no path.')
|
|
|
|
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
|
|
|
|
|
|
|
|
|
# get discussions & replies
|
|
|
|
|
path_hash = calc_file_path_hash(path)
|
|
|
|
|
discussions = FileDiscuss.objects.filter(path_hash=path_hash, repo_id=repo_id)
|
|
|
|
|
msg_ids = [ e.group_message_id for e in discussions ]
|
|
|
|
|
|
|
|
|
|
grp_msgs = GroupMessage.objects.filter(id__in=msg_ids).order_by('-timestamp')
|
|
|
|
|
msg_replies = MessageReply.objects.filter(reply_to__in=grp_msgs)
|
|
|
|
|
for msg in grp_msgs:
|
|
|
|
|
msg.replies = []
|
|
|
|
|
for reply in msg_replies:
|
|
|
|
|
if msg.id == reply.reply_to_id:
|
|
|
|
|
msg.replies.append(reply)
|
|
|
|
|
msg.reply_cnt = len(msg.replies)
|
|
|
|
|
msg.replies = msg.replies[-3:]
|
|
|
|
|
|
|
|
|
|
ctx = {}
|
|
|
|
|
ctx['messages'] = grp_msgs
|
2013-04-05 11:52:37 +08:00
|
|
|
|
html = render_to_string("group/discussion_list.html", ctx)
|
2013-04-04 19:58:00 +08:00
|
|
|
|
result['html'] = html
|
|
|
|
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
|
|
|
|
2012-08-18 17:25:08 +08:00
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def create_group_repo(request, group_id):
|
|
|
|
|
"""Create a repo and share it to current group"""
|
|
|
|
|
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
def json_error(err_msg):
|
|
|
|
|
result = {'error': [err_msg]}
|
|
|
|
|
return HttpResponseBadRequest(json.dumps(result),
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
group_id = int(group_id)
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group = get_group(group_id)
|
|
|
|
|
if not group:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create: the group does not exist.'))
|
2012-08-18 17:25:08 +08:00
|
|
|
|
|
2012-09-11 10:11:44 +08:00
|
|
|
|
# Check whether user belongs to the group.
|
|
|
|
|
if not is_group_user(group_id, request.user.username):
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create: you are not in the group.'))
|
2012-08-18 17:25:08 +08:00
|
|
|
|
|
2012-09-26 10:49:00 +08:00
|
|
|
|
form = SharedRepoCreateForm(request.POST)
|
2012-08-18 17:25:08 +08:00
|
|
|
|
if not form.is_valid():
|
|
|
|
|
return json_error(form.errors)
|
|
|
|
|
else:
|
|
|
|
|
repo_name = form.cleaned_data['repo_name']
|
|
|
|
|
repo_desc = form.cleaned_data['repo_desc']
|
2012-09-26 10:49:00 +08:00
|
|
|
|
permission = form.cleaned_data['permission']
|
2012-08-18 17:25:08 +08:00
|
|
|
|
encrypted = form.cleaned_data['encryption']
|
|
|
|
|
passwd = form.cleaned_data['passwd']
|
|
|
|
|
user = request.user.username
|
|
|
|
|
|
2013-03-30 10:26:49 +08:00
|
|
|
|
org, base_template = check_and_get_org_by_group(group.id, user)
|
2012-08-30 20:15:17 +08:00
|
|
|
|
if org:
|
|
|
|
|
# create group repo in org context
|
|
|
|
|
try:
|
|
|
|
|
repo_id = create_org_repo(repo_name, repo_desc, user, passwd,
|
|
|
|
|
org.org_id)
|
|
|
|
|
except:
|
|
|
|
|
repo_id = None
|
|
|
|
|
if not repo_id:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create'))
|
2012-08-18 17:25:08 +08:00
|
|
|
|
|
2012-08-30 20:15:17 +08:00
|
|
|
|
try:
|
|
|
|
|
status = seafserv_threaded_rpc.add_org_group_repo(repo_id,
|
|
|
|
|
org.org_id,
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group.id,
|
2012-09-26 10:49:00 +08:00
|
|
|
|
user,
|
|
|
|
|
permission)
|
2012-08-30 20:15:17 +08:00
|
|
|
|
except SearpcError, e:
|
|
|
|
|
status = -1
|
|
|
|
|
|
|
|
|
|
# if share failed, remove the newly created repo
|
|
|
|
|
if status != 0:
|
2013-03-16 16:11:55 +08:00
|
|
|
|
remove_repo(repo_id)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create: internal error.'))
|
2012-08-30 20:15:17 +08:00
|
|
|
|
else:
|
|
|
|
|
result = {'success': True}
|
|
|
|
|
return HttpResponse(json.dumps(result),
|
|
|
|
|
content_type=content_type)
|
2012-08-18 17:25:08 +08:00
|
|
|
|
else:
|
2012-08-30 20:15:17 +08:00
|
|
|
|
# create group repo in user context
|
2013-03-16 16:11:55 +08:00
|
|
|
|
repo_id = create_repo(repo_name, repo_desc, user, passwd)
|
2012-08-30 20:15:17 +08:00
|
|
|
|
if not repo_id:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create'))
|
2012-08-30 20:15:17 +08:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
status = seafserv_threaded_rpc.group_share_repo(repo_id,
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group.id,
|
2012-09-26 10:49:00 +08:00
|
|
|
|
user,
|
|
|
|
|
permission)
|
2012-08-30 20:15:17 +08:00
|
|
|
|
except SearpcError, e:
|
|
|
|
|
status = -1
|
|
|
|
|
|
|
|
|
|
# if share failed, remove the newly created repo
|
2012-08-18 17:25:08 +08:00
|
|
|
|
if status != 0:
|
2013-03-16 16:11:55 +08:00
|
|
|
|
remove_repo(repo_id)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
return json_error(_(u'Failed to create: internal error.'))
|
2012-08-18 17:25:08 +08:00
|
|
|
|
else:
|
|
|
|
|
result = {'success': True}
|
|
|
|
|
return HttpResponse(json.dumps(result),
|
|
|
|
|
content_type=content_type)
|
2012-09-11 10:11:44 +08:00
|
|
|
|
|
2012-09-26 17:05:32 +08:00
|
|
|
|
@login_required
|
|
|
|
|
def group_joinrequest(request, group_id):
|
|
|
|
|
"""
|
|
|
|
|
Handle post request to join a group.
|
|
|
|
|
"""
|
|
|
|
|
if not request.is_ajax() or request.method != 'POST':
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
group_id = int(group_id)
|
2013-03-30 10:26:49 +08:00
|
|
|
|
group = get_group(group_id)
|
2012-09-26 17:05:32 +08:00
|
|
|
|
if not group:
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
user = request.user.username
|
|
|
|
|
# TODO: Group creator is group staff now, but may changed in future.
|
|
|
|
|
staff = group.creator_name
|
|
|
|
|
if is_group_user(group_id, user):
|
|
|
|
|
# Already in the group. Normally, this case should not happen.
|
2012-11-01 15:45:12 +08:00
|
|
|
|
err = _(u'You are already in the group.')
|
2012-09-26 17:05:32 +08:00
|
|
|
|
return HttpResponseBadRequest(json.dumps({'error': err}),
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
else:
|
|
|
|
|
form = GroupJoinMsgForm(request.POST)
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
group_join_msg = form.cleaned_data['group_join_msg']
|
|
|
|
|
# Send the message to group staff.
|
|
|
|
|
use_https = request.is_secure()
|
|
|
|
|
domain = RequestSite(request).domain
|
|
|
|
|
t = loader.get_template('group/group_join_email.html')
|
|
|
|
|
c = {
|
|
|
|
|
'staff': staff,
|
|
|
|
|
'user': user,
|
2012-11-06 19:42:56 +08:00
|
|
|
|
'group_name': group.group_name,
|
2012-09-26 17:05:32 +08:00
|
|
|
|
'group_join_msg': group_join_msg,
|
2012-11-06 19:42:56 +08:00
|
|
|
|
'site_name': SITE_NAME,
|
2012-09-26 17:05:32 +08:00
|
|
|
|
}
|
|
|
|
|
try:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
send_mail(_(u'apply to join the group'), t.render(Context(c)), None, [staff],
|
2012-09-26 17:05:32 +08:00
|
|
|
|
fail_silently=False)
|
2012-11-01 15:45:12 +08:00
|
|
|
|
messages.success(request, _(u'Sent successfully, the group admin will handle it.'))
|
2012-09-26 17:05:32 +08:00
|
|
|
|
return HttpResponse(json.dumps('success'),
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
except:
|
2012-11-01 15:45:12 +08:00
|
|
|
|
err = _(u'Failed to send. You can try it again later.')
|
2012-09-26 17:05:32 +08:00
|
|
|
|
return HttpResponse(json.dumps({'error': err}), status=500,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
else:
|
|
|
|
|
return HttpResponseBadRequest(json.dumps(form.errors),
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
2012-09-28 22:43:25 +08:00
|
|
|
|
def attention(request):
|
|
|
|
|
"""
|
|
|
|
|
Handle ajax request to query group members used in autocomplete.
|
|
|
|
|
"""
|
|
|
|
|
if not request.is_ajax():
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
user = request.user.username
|
2012-10-20 19:43:56 +08:00
|
|
|
|
name_str = request.GET.get('name_startsWith')
|
|
|
|
|
gids = request.GET.get('gids', '')
|
|
|
|
|
result = []
|
2012-09-28 22:43:25 +08:00
|
|
|
|
|
2012-10-20 19:43:56 +08:00
|
|
|
|
members = []
|
2012-10-23 16:19:20 +08:00
|
|
|
|
for gid in gids.split('_'):
|
2012-10-20 19:43:56 +08:00
|
|
|
|
try:
|
|
|
|
|
gid = int(gid)
|
|
|
|
|
except ValueError:
|
|
|
|
|
continue
|
2012-09-28 22:43:25 +08:00
|
|
|
|
|
2012-10-20 19:43:56 +08:00
|
|
|
|
if not is_group_user(gid, user):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Get all group users
|
|
|
|
|
members += get_group_members(gid)
|
|
|
|
|
|
|
|
|
|
member_names = []
|
2012-09-28 22:43:25 +08:00
|
|
|
|
for m in members:
|
2013-01-04 20:11:57 +08:00
|
|
|
|
if len(result) == 10: # Return at most 10 results.
|
|
|
|
|
break
|
|
|
|
|
|
2012-09-28 22:43:25 +08:00
|
|
|
|
if m.user_name == user:
|
|
|
|
|
continue
|
2013-01-04 20:11:57 +08:00
|
|
|
|
|
2012-10-20 19:43:56 +08:00
|
|
|
|
if m.user_name in member_names:
|
|
|
|
|
# Remove duplicated member names
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
member_names.append(m.user_name)
|
|
|
|
|
|
2012-09-28 22:43:25 +08:00
|
|
|
|
from base.templatetags.seahub_tags import email2nickname, char2pinyin
|
|
|
|
|
nickname = email2nickname(m.user_name)
|
|
|
|
|
pinyin = char2pinyin(nickname)
|
|
|
|
|
if nickname.startswith(name_str) or pinyin.startswith(name_str):
|
|
|
|
|
result.append({'contact_name': nickname})
|
|
|
|
|
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
|
|
|
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-28 16:16:39 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_discuss(request, group):
|
2013-03-30 13:47:12 +08:00
|
|
|
|
username = request.user.username
|
2013-03-04 20:23:59 +08:00
|
|
|
|
if request.method == 'POST':
|
2013-03-29 11:46:28 +08:00
|
|
|
|
# only login user can post to public group
|
|
|
|
|
if group.view_perm == "pub" and not request.user.is_authenticated():
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-04 20:23:59 +08:00
|
|
|
|
form = MessageForm(request.POST)
|
|
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
msg = form.cleaned_data['message']
|
|
|
|
|
message = GroupMessage()
|
2013-03-28 16:16:39 +08:00
|
|
|
|
message.group_id = group.id
|
2013-03-04 20:23:59 +08:00
|
|
|
|
message.from_email = request.user.username
|
|
|
|
|
message.message = msg
|
|
|
|
|
message.save()
|
|
|
|
|
|
|
|
|
|
# send signal
|
2013-03-28 16:16:39 +08:00
|
|
|
|
grpmsg_added.send(sender=GroupMessage, group_id=group.id,
|
2013-03-30 13:47:12 +08:00
|
|
|
|
from_email=username)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
# Always return an HttpResponseRedirect after successfully dealing
|
|
|
|
|
# with POST data.
|
2013-03-28 16:16:39 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_discuss', args=[group.id]))
|
2013-03-04 20:23:59 +08:00
|
|
|
|
else:
|
|
|
|
|
form = MessageForm()
|
|
|
|
|
|
|
|
|
|
# remove user notifications
|
2013-03-30 13:47:12 +08:00
|
|
|
|
UserNotification.objects.filter(to_user=username, msg_type='group_msg',
|
2013-03-28 16:16:39 +08:00
|
|
|
|
detail=str(group.id)).delete()
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
|
|
|
|
# Get all group members.
|
2013-03-30 10:26:49 +08:00
|
|
|
|
members = get_group_members(group.id)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
|
|
|
|
"""group messages"""
|
2013-03-19 11:49:52 +08:00
|
|
|
|
# Show 15 group messages per page.
|
|
|
|
|
paginator = Paginator(GroupMessage.objects.filter(
|
2013-03-28 16:16:39 +08:00
|
|
|
|
group_id=group.id).order_by('-timestamp'), 15)
|
2013-03-19 11:49:52 +08:00
|
|
|
|
|
2013-03-04 20:23:59 +08:00
|
|
|
|
# Make sure page request is an int. If not, deliver first page.
|
|
|
|
|
try:
|
2013-03-19 11:49:52 +08:00
|
|
|
|
page = int(request.GET.get('page', '1'))
|
2013-03-04 20:23:59 +08:00
|
|
|
|
except ValueError:
|
2013-03-19 11:49:52 +08:00
|
|
|
|
page = 1
|
|
|
|
|
|
|
|
|
|
# If page request (9999) is out of range, deliver last page of results.
|
|
|
|
|
try:
|
|
|
|
|
group_msgs = paginator.page(page)
|
|
|
|
|
except (EmptyPage, InvalidPage):
|
|
|
|
|
group_msgs = paginator.page(paginator.num_pages)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-19 11:49:52 +08:00
|
|
|
|
group_msgs.page_range = paginator.get_page_range(group_msgs.number)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-19 11:49:52 +08:00
|
|
|
|
# Force evaluate queryset to fix some database error for mysql.
|
|
|
|
|
group_msgs.object_list = list(group_msgs.object_list)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-19 11:49:52 +08:00
|
|
|
|
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-19 11:49:52 +08:00
|
|
|
|
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
|
2013-03-04 20:23:59 +08:00
|
|
|
|
reply_to_list = [ r.reply_to_id for r in msg_replies ]
|
|
|
|
|
|
2013-03-19 11:49:52 +08:00
|
|
|
|
for msg in group_msgs.object_list:
|
2013-03-04 20:23:59 +08:00
|
|
|
|
msg.reply_cnt = reply_to_list.count(msg.id)
|
2013-03-12 21:48:47 +08:00
|
|
|
|
msg.replies = []
|
|
|
|
|
for r in msg_replies:
|
|
|
|
|
if msg.id == r.reply_to_id:
|
|
|
|
|
msg.replies.append(r)
|
|
|
|
|
msg.replies = msg.replies[-3:]
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
|
|
|
|
for att in attachments:
|
2013-03-30 13:47:12 +08:00
|
|
|
|
if att.group_message_id != msg.id:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Attachment name is file name or directory name.
|
|
|
|
|
# If is top directory, use repo name instead.
|
|
|
|
|
path = att.path
|
|
|
|
|
if path == '/':
|
|
|
|
|
repo = get_repo(att.repo_id)
|
|
|
|
|
if not repo:
|
|
|
|
|
# TODO: what should we do here, tell user the repo
|
|
|
|
|
# is no longer exists?
|
|
|
|
|
continue
|
|
|
|
|
att.name = repo.name
|
|
|
|
|
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 = _(u'File does not exist')
|
|
|
|
|
else:
|
|
|
|
|
att.token = web_get_access_token(att.repo_id, att.obj_id,
|
|
|
|
|
'view', username)
|
|
|
|
|
att.img_url = gen_file_get_url(att.token, att.name)
|
|
|
|
|
|
|
|
|
|
msg.attachment = att
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-12 21:48:47 +08:00
|
|
|
|
return render_to_response("group/group_discuss.html", {
|
2013-03-04 20:23:59 +08:00
|
|
|
|
"members": members,
|
|
|
|
|
"group" : group,
|
2013-03-29 11:46:28 +08:00
|
|
|
|
"is_staff": group.is_staff,
|
2013-03-04 20:23:59 +08:00
|
|
|
|
"group_msgs": group_msgs,
|
|
|
|
|
"form": form,
|
|
|
|
|
'group_members_default_display': GROUP_MEMBERS_DEFAULT_DISPLAY,
|
2013-04-04 19:57:52 +08:00
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-04 20:23:59 +08:00
|
|
|
|
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-08 19:34:53 +08:00
|
|
|
|
class WikiDoesNotExist(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class WikiPageMissing(Exception):
|
|
|
|
|
pass
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
def find_wiki_repo(request, group):
|
2013-03-15 10:16:19 +08:00
|
|
|
|
try:
|
|
|
|
|
groupwiki = GroupWiki.objects.get(group_id=group.id)
|
|
|
|
|
repos = get_group_repos(group.id, request.user.username)
|
|
|
|
|
for repo in repos:
|
|
|
|
|
if repo.id == groupwiki.repo_id:
|
|
|
|
|
return repo
|
|
|
|
|
return None
|
|
|
|
|
except GroupWiki.DoesNotExist:
|
|
|
|
|
return None
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-04-04 19:57:52 +08:00
|
|
|
|
def get_file_url(repo, obj_id, file_name):
|
|
|
|
|
repo_id = repo.id
|
2013-03-05 11:56:51 +08:00
|
|
|
|
access_token = seafserv_rpc.web_get_access_token(repo_id, obj_id,
|
|
|
|
|
'view', '')
|
2013-04-04 19:57:52 +08:00
|
|
|
|
url = gen_file_get_url(access_token, file_name)
|
|
|
|
|
return url
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
def get_wiki_page(request, group, page_name):
|
|
|
|
|
repo = find_wiki_repo(request, group)
|
2013-03-08 19:34:53 +08:00
|
|
|
|
if not repo:
|
|
|
|
|
raise WikiDoesNotExist
|
2013-04-04 19:57:52 +08:00
|
|
|
|
dirent = get_wiki_dirent(repo.id, page_name)
|
|
|
|
|
if not dirent:
|
|
|
|
|
raise WikiPageMissing
|
|
|
|
|
url = get_file_url(repo, dirent.obj_id, dirent.obj_name)
|
2013-03-05 11:56:51 +08:00
|
|
|
|
file_response = urllib2.urlopen(url)
|
|
|
|
|
content = file_response.read()
|
2013-04-04 19:57:52 +08:00
|
|
|
|
return content, repo.id, dirent
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-13 17:31:12 +08:00
|
|
|
|
def convert_wiki_link(content, group, repo_id, username):
|
2013-03-05 11:56:51 +08:00
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
def repl(matchobj):
|
2013-03-25 10:37:05 +08:00
|
|
|
|
if matchobj.group(2): # return origin string in backquotes
|
|
|
|
|
return matchobj.group(2)
|
|
|
|
|
|
2013-04-04 19:57:52 +08:00
|
|
|
|
page_name = matchobj.group(1).strip()
|
|
|
|
|
filetype, fileext = get_file_type_and_ext(page_name)
|
2013-03-14 14:07:09 +08:00
|
|
|
|
if fileext == '':
|
2013-04-04 19:57:52 +08:00
|
|
|
|
# convert page_name that extension is missing to a markdown page
|
2013-04-06 12:06:47 +08:00
|
|
|
|
page_alias = page_name
|
|
|
|
|
if len(page_name.split('|')) > 1:
|
|
|
|
|
page_alias = page_name.split('|')[0]
|
|
|
|
|
page_name = page_name.split('|')[1]
|
2013-04-04 19:57:52 +08:00
|
|
|
|
dirent = get_wiki_dirent(repo_id, page_name)
|
|
|
|
|
if dirent is not None:
|
2013-03-14 14:07:09 +08:00
|
|
|
|
a_tag = "<a href='%s'>%s</a>"
|
2013-04-06 12:06:47 +08:00
|
|
|
|
return a_tag % (reverse('group_wiki', args=[group.id, normalize_page_name(page_name)]), page_alias)
|
2013-03-14 14:07:09 +08:00
|
|
|
|
else:
|
|
|
|
|
a_tag = '''<a class="wiki-page-missing" href='%s'>%s</a>'''
|
2013-04-06 12:06:47 +08:00
|
|
|
|
return a_tag % (reverse('group_wiki', args=[group.id, page_name.replace('/', '-')]), page_alias)
|
2013-03-30 13:47:12 +08:00
|
|
|
|
elif filetype == IMAGE:
|
2013-03-14 14:07:09 +08:00
|
|
|
|
# load image to wiki page
|
2013-04-04 19:57:52 +08:00
|
|
|
|
path = "/" + page_name
|
2013-03-13 17:31:12 +08:00
|
|
|
|
filename = os.path.basename(path)
|
|
|
|
|
obj_id = get_file_id_by_path(repo_id, path)
|
|
|
|
|
if not obj_id:
|
2013-04-04 19:57:52 +08:00
|
|
|
|
# Replace '/' in page_name to '-', since wiki name can not
|
2013-03-14 14:07:09 +08:00
|
|
|
|
# contain '/'.
|
|
|
|
|
return '''<a class="wiki-page-missing" href='%s'>%s</a>''' % \
|
2013-04-04 19:57:52 +08:00
|
|
|
|
(reverse('group_wiki', args=[group.id, page_name.replace('/', '-')]), page_name)
|
2013-03-14 14:07:09 +08:00
|
|
|
|
|
2013-03-13 17:31:12 +08:00
|
|
|
|
token = web_get_access_token(repo_id, obj_id, 'view', username)
|
2013-03-15 16:57:33 +08:00
|
|
|
|
return '<img src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
|
2013-03-08 19:34:53 +08:00
|
|
|
|
else:
|
2013-03-14 14:07:09 +08:00
|
|
|
|
from base.templatetags.seahub_tags import file_icon_filter
|
|
|
|
|
|
|
|
|
|
# convert other types of filelinks to clickable links
|
2013-04-04 19:57:52 +08:00
|
|
|
|
path = "/" + page_name
|
|
|
|
|
icon = file_icon_filter(page_name)
|
2013-04-03 11:49:32 +08:00
|
|
|
|
s = reverse('repo_view_file', args=[repo_id]) + \
|
|
|
|
|
'?p=' + urllib2.quote(smart_str(path))
|
2013-03-15 16:57:33 +08:00
|
|
|
|
a_tag = '''<img src="%simg/file/%s" alt="%s" class="vam" /> <a href='%s' target='_blank' class="vam">%s</a>'''
|
2013-04-04 19:57:52 +08:00
|
|
|
|
return a_tag % (MEDIA_URL, icon, icon, s, page_name)
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-25 10:37:05 +08:00
|
|
|
|
return re.sub(r'\[\[(.+)\]\]|(`.+`)', repl, content)
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki(request, group, page_name="home"):
|
2013-03-13 17:31:12 +08:00
|
|
|
|
username = request.user.username
|
2013-03-12 16:09:30 +08:00
|
|
|
|
wiki_exists = True
|
2013-03-08 19:34:53 +08:00
|
|
|
|
try:
|
2013-04-04 19:57:52 +08:00
|
|
|
|
content, repo_id, dirent = get_wiki_page(request, group, page_name)
|
2013-03-08 19:34:53 +08:00
|
|
|
|
except WikiDoesNotExist:
|
|
|
|
|
wiki_exists = False
|
2013-04-04 19:57:52 +08:00
|
|
|
|
return render_to_response("group/group_wiki.html", {
|
|
|
|
|
"group" : group,
|
|
|
|
|
"is_staff": group.is_staff,
|
|
|
|
|
"wiki_exists": wiki_exists,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-08 19:34:53 +08:00
|
|
|
|
except WikiPageMissing:
|
2013-04-01 14:15:20 +08:00
|
|
|
|
'''create that page for user if he/she is a group member'''
|
|
|
|
|
if not is_group_user(group.id, username):
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
repo = find_wiki_repo(request, group)
|
|
|
|
|
# No need to check whether repo is none, since repo is already created
|
|
|
|
|
|
2013-04-04 19:57:52 +08:00
|
|
|
|
filename = clean_page_name(page_name) + '.md'
|
2013-03-16 16:11:55 +08:00
|
|
|
|
if not post_empty_file(repo.id, "/", filename, username):
|
2013-03-26 14:09:40 +08:00
|
|
|
|
return render_error(request, _("Failed to create wiki page. Please retry later."))
|
2013-03-16 16:11:55 +08:00
|
|
|
|
return HttpResponseRedirect(reverse('group_wiki', args=[group.id, page_name]))
|
2013-03-08 19:34:53 +08:00
|
|
|
|
else:
|
2013-03-13 17:31:12 +08:00
|
|
|
|
content = convert_wiki_link(content, group, repo_id, username)
|
2013-03-15 20:47:26 +08:00
|
|
|
|
|
|
|
|
|
# fetch file latest contributor and last modified
|
2013-04-04 19:57:52 +08:00
|
|
|
|
path = '/' + dirent.obj_name
|
2013-03-15 20:47:26 +08:00
|
|
|
|
file_path_hash = md5_constructor(urllib2.quote(path.encode('utf-8'))).hexdigest()[:12]
|
|
|
|
|
contributors, last_modified, last_commit_id = get_file_contributors(\
|
2013-04-04 19:57:52 +08:00
|
|
|
|
repo_id, path.encode('utf-8'), file_path_hash, dirent.obj_id)
|
2013-03-15 20:47:26 +08:00
|
|
|
|
latest_contributor = contributors[0] if contributors else None
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-04-04 19:57:52 +08:00
|
|
|
|
return render_to_response("group/group_wiki.html", {
|
|
|
|
|
"group" : group,
|
|
|
|
|
"is_staff": group.is_staff,
|
|
|
|
|
"wiki_exists": wiki_exists,
|
|
|
|
|
"content": content,
|
|
|
|
|
"page": os.path.splitext(dirent.obj_name)[0],
|
|
|
|
|
"last_modified": last_modified,
|
|
|
|
|
"latest_contributor": latest_contributor,
|
|
|
|
|
"path": path,
|
|
|
|
|
"repo_id": repo_id,
|
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki_pages(request, group):
|
|
|
|
|
"""
|
|
|
|
|
List wiki pages in group.
|
|
|
|
|
"""
|
|
|
|
|
repo = find_wiki_repo(request, group)
|
|
|
|
|
if not repo:
|
|
|
|
|
return render_error(request, _('Wiki is not found.'))
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
dir_id = seafserv_threaded_rpc.get_dir_id_by_path(repo.id, '/')
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
dir_id = None
|
|
|
|
|
if not dir_id:
|
|
|
|
|
return render_error(request, _('Wiki root path is missing.'))
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
dirs = seafserv_threaded_rpc.list_dir(dir_id)
|
|
|
|
|
except SearpcError, e:
|
|
|
|
|
return render_error(request, _('Failed to list wiki directories.'))
|
|
|
|
|
|
2013-04-04 19:57:52 +08:00
|
|
|
|
pages = {}
|
2013-03-12 16:09:30 +08:00
|
|
|
|
for e in dirs:
|
|
|
|
|
if stat.S_ISDIR(e.mode):
|
|
|
|
|
continue # skip directories
|
|
|
|
|
name, ext = os.path.splitext(e.obj_name)
|
|
|
|
|
if ext == '.md':
|
2013-04-04 19:57:52 +08:00
|
|
|
|
key = normalize_page_name(name)
|
|
|
|
|
pages[key] = name
|
2013-03-12 16:09:30 +08:00
|
|
|
|
|
|
|
|
|
return render_to_response("group/group_wiki_pages.html", {
|
|
|
|
|
"group": group,
|
|
|
|
|
"pages": pages,
|
2013-03-29 11:46:28 +08:00
|
|
|
|
"is_staff": group.is_staff,
|
2013-04-01 14:02:08 +08:00
|
|
|
|
"repo_id": repo.id
|
2013-03-08 19:34:53 +08:00
|
|
|
|
}, context_instance=RequestContext(request))
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki_create(request, group):
|
2013-03-29 11:46:28 +08:00
|
|
|
|
if group.view_perm == "pub":
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-15 10:16:19 +08:00
|
|
|
|
if request.method != 'POST':
|
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
|
|
content_type = 'application/json; charset=utf-8'
|
|
|
|
|
|
|
|
|
|
def json_error(err_msg, status=400):
|
|
|
|
|
result = {'error': err_msg}
|
|
|
|
|
return HttpResponse(json.dumps(result), status=status,
|
|
|
|
|
content_type=content_type)
|
|
|
|
|
|
|
|
|
|
form = WikiCreateForm(request.POST)
|
|
|
|
|
if not form.is_valid():
|
|
|
|
|
return json_error(str(form.errors.values()[0]))
|
|
|
|
|
|
2013-03-05 11:56:51 +08:00
|
|
|
|
# create group repo in user context
|
2013-03-15 10:16:19 +08:00
|
|
|
|
repo_name = form.cleaned_data['repo_name']
|
|
|
|
|
repo_desc = form.cleaned_data['repo_desc']
|
2013-03-05 11:56:51 +08:00
|
|
|
|
user = request.user.username
|
|
|
|
|
passwd = None
|
|
|
|
|
permission = "rw"
|
|
|
|
|
|
2013-03-16 16:11:55 +08:00
|
|
|
|
repo_id = create_repo(repo_name, repo_desc, user, passwd)
|
|
|
|
|
if not repo_id:
|
2013-03-15 10:16:19 +08:00
|
|
|
|
return json_error(_(u'Failed to create'), 500)
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
status = seafserv_threaded_rpc.group_share_repo(repo_id,
|
2013-03-12 16:09:30 +08:00
|
|
|
|
group.id,
|
2013-03-05 11:56:51 +08:00
|
|
|
|
user,
|
|
|
|
|
permission)
|
|
|
|
|
except SearpcError, e:
|
2013-03-16 16:11:55 +08:00
|
|
|
|
remove_repo(repo_id)
|
2013-03-15 10:16:19 +08:00
|
|
|
|
return json_error(_(u'Failed to create: internal error.'), 500)
|
|
|
|
|
|
|
|
|
|
GroupWiki.objects.save_group_wiki(group_id=group.id, repo_id=repo_id)
|
2013-03-05 11:56:51 +08:00
|
|
|
|
|
2013-03-08 19:34:53 +08:00
|
|
|
|
# create home page
|
|
|
|
|
page_name = "home.md"
|
2013-03-16 16:11:55 +08:00
|
|
|
|
if not post_empty_file(repo_id, "/", page_name, user):
|
|
|
|
|
return json_error(_(u'Failed to create home page. Please retry later'), 500)
|
2013-03-07 12:05:30 +08:00
|
|
|
|
|
2013-03-15 10:16:19 +08:00
|
|
|
|
next = reverse('group_wiki', args=[group.id])
|
|
|
|
|
return HttpResponse(json.dumps({'href': next}), content_type=content_type)
|
2013-03-12 16:09:30 +08:00
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki_page_new(request, group, page_name="home"):
|
2013-03-29 11:46:28 +08:00
|
|
|
|
if group.view_perm == "pub":
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-07 12:05:30 +08:00
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
form = MessageForm(request.POST)
|
|
|
|
|
|
|
|
|
|
page_name = request.POST.get('page_name', '')
|
|
|
|
|
if not page_name:
|
|
|
|
|
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
|
2013-04-04 19:57:52 +08:00
|
|
|
|
page_name = clean_page_name(page_name)
|
2013-03-12 16:09:30 +08:00
|
|
|
|
|
|
|
|
|
repo = find_wiki_repo(request, group)
|
2013-03-07 12:05:30 +08:00
|
|
|
|
if not repo:
|
2013-03-12 16:09:30 +08:00
|
|
|
|
return render_error(request, _('Wiki is not found.'))
|
2013-04-02 19:39:30 +08:00
|
|
|
|
|
2013-03-07 12:05:30 +08:00
|
|
|
|
filename = page_name + ".md"
|
|
|
|
|
filepath = "/" + page_name + ".md"
|
2013-04-01 11:01:09 +08:00
|
|
|
|
|
|
|
|
|
# check whether file exists
|
|
|
|
|
if get_file_id_by_path(repo.id, filepath):
|
|
|
|
|
return render_error(request, _('Page "%s" already exists.') % filename)
|
|
|
|
|
|
2013-03-16 16:11:55 +08:00
|
|
|
|
if not post_empty_file(repo.id, "/", filename, request.user.username):
|
|
|
|
|
return render_error(request, _('Failed to create wiki page. Please retry later.'))
|
2013-03-07 12:05:30 +08:00
|
|
|
|
|
2013-04-02 19:39:30 +08:00
|
|
|
|
url = "%s?p=%s&from=wiki_page_new&gid=%s" % (
|
|
|
|
|
reverse('file_edit', args=[repo.id]),
|
|
|
|
|
urllib2.quote(filepath.encode('utf-8')), group.id)
|
2013-03-07 12:05:30 +08:00
|
|
|
|
return HttpResponseRedirect(url)
|
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-09 15:27:17 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki_page_edit(request, group, page_name="home"):
|
2013-03-29 11:46:28 +08:00
|
|
|
|
if group.view_perm == "pub":
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
repo = find_wiki_repo(request, group)
|
2013-03-07 12:05:30 +08:00
|
|
|
|
if not repo:
|
2013-03-12 16:09:30 +08:00
|
|
|
|
return render_error(request, _('Wiki is not found.'))
|
|
|
|
|
|
2013-03-07 12:05:30 +08:00
|
|
|
|
filepath = "/" + page_name + ".md"
|
2013-04-02 19:39:30 +08:00
|
|
|
|
url = "%s?p=%s&from=wiki_page_edit&gid=%s" % (
|
|
|
|
|
reverse('file_edit', args=[repo.id]),
|
|
|
|
|
urllib2.quote(filepath.encode('utf-8')), group.id)
|
|
|
|
|
|
2013-03-07 12:05:30 +08:00
|
|
|
|
return HttpResponseRedirect(url)
|
2013-03-12 16:09:30 +08:00
|
|
|
|
|
2013-03-29 11:46:28 +08:00
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
@group_check
|
|
|
|
|
def group_wiki_page_delete(request, group, page_name):
|
2013-03-29 11:46:28 +08:00
|
|
|
|
if group.view_perm == "pub":
|
|
|
|
|
raise Http404
|
|
|
|
|
|
2013-03-12 16:09:30 +08:00
|
|
|
|
repo = find_wiki_repo(request, group)
|
|
|
|
|
if not repo:
|
|
|
|
|
return render_error(request, _('Wiki is not found.'))
|
|
|
|
|
|
|
|
|
|
file_name = page_name + '.md'
|
|
|
|
|
user = request.user.username
|
2013-03-16 16:11:55 +08:00
|
|
|
|
if del_file(repo.id, '/', file_name, user):
|
2013-03-12 16:09:30 +08:00
|
|
|
|
messages.success(request, 'Successfully deleted "%s".' % page_name)
|
2013-03-16 16:11:55 +08:00
|
|
|
|
else:
|
2013-03-12 16:09:30 +08:00
|
|
|
|
messages.error(request, 'Failed to delete "%s". Please retry later.' % page_name)
|
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('group_wiki', args=[group.id]))
|
|
|
|
|
|