mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-26 07:22:34 +00:00
Move included files to templates/snippets
This commit is contained in:
@@ -12,8 +12,6 @@ class OrganizationMiddleware(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
"""
|
|
||||||
"""
|
|
||||||
# Get current org context
|
# Get current org context
|
||||||
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
|
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
|
||||||
request.user.org = org
|
request.user.org = org
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import django.dispatch
|
import django.dispatch
|
||||||
|
|
||||||
org_user_added = django.dispatch.Signal(providing_args=["org_id", "from_email", "to_email"])
|
org_user_added = django.dispatch.Signal(providing_args=["org_id", "from_email", "to_email"])
|
||||||
|
|
||||||
|
@@ -1,48 +0,0 @@
|
|||||||
{% extends base_template %}
|
|
||||||
{% load avatar_tags %}
|
|
||||||
|
|
||||||
{% block left_panel %}
|
|
||||||
|
|
||||||
<h3>操作</h3>
|
|
||||||
<ul class="with-bg">
|
|
||||||
<li><a href="{% url organizations.views.create_org %}">创建企业帐号</a></li>
|
|
||||||
<li><a href="{% url organizations.views.change_account %}">切换帐号</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block right_panel %}
|
|
||||||
<div id="user-basic-info">
|
|
||||||
<h2>切换帐号</h2>
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th width="80%">名称</th>
|
|
||||||
<th width="20%">操作</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{{ request.user}}</td>
|
|
||||||
<td><button data={% url myhome %} class="account-change-btn">切换</button></td>
|
|
||||||
</tr>
|
|
||||||
{% for org in orgs %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ org.org_name }}</td>
|
|
||||||
<td><button data={% url organizations.views.org_info org.url_prefix %} class="account-change-btn">切换</button></td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form id="account-change-form" action="" method="post" class="hide">
|
|
||||||
<input id="url_prefix" type="text" name="url_prefix" value="" /><br />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block extra_script %}
|
|
||||||
<script type="text/javascript">
|
|
||||||
$('.account-change-btn').click(function() {
|
|
||||||
location.href=$(this).attr('data');
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@@ -1,9 +1,9 @@
|
|||||||
{% extends base_template %}
|
{% extends base_template %}
|
||||||
{% block main_panel %}
|
{% block main_panel %}
|
||||||
<div class="narrow-panel">
|
<div class="narrow-panel">
|
||||||
<h2>创建企业帐号</h2>
|
<h2>创建团体帐号</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<label for="id_org_name">企业名称:</label>
|
<label for="id_org_name">团体名称:</label>
|
||||||
{{ form.org_name}}
|
{{ form.org_name}}
|
||||||
<lable for="id_url_prefix">域名前缀:</label>
|
<lable for="id_url_prefix">域名前缀:</label>
|
||||||
{{ form.url_prefix }}
|
{{ form.url_prefix }}
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
{% if repos %}
|
{% if repos %}
|
||||||
{% for repo in repos %}
|
{% for repo in repos %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ SITE_ROOT }}organizations/{{ org.url_prefix }}/repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
|
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
|
||||||
<td>{{ repo.props.desc }}</td>
|
<td>{{ repo.props.desc }}</td>
|
||||||
{% if repo.latest_modify %}
|
{% if repo.latest_modify %}
|
||||||
<td>{{ repo.latest_modify|translate_commit_time }}</td>
|
<td>{{ repo.latest_modify|translate_commit_time }}</td>
|
||||||
@@ -50,33 +50,22 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<td>
|
<td>
|
||||||
<img src="{{ MEDIA_URL }}img/sync-20.png" data="{{ repo.props.id }}" class="download-btn vh" title="同步到本地" alt="同步" />
|
<img src="{{ MEDIA_URL }}img/sync-20.png" data="{{ repo.props.id }}" class="download-btn vh" title="同步到本地" alt="同步" />
|
||||||
<!-- <img src="{{ MEDIA_URL }}img/share-20.png" data="{{ repo.props.id }}" class="repo-share-btn vh" title="共享" alt="共享" /> -->
|
<img src="{{ MEDIA_URL }}img/share-20.png" data="{{ repo.props.id }}" class="repo-share-btn vh" title="共享" alt="共享" />
|
||||||
<img src="{{ MEDIA_URL }}img/delete-20.png" data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/?next={{ request.path }}" class="repo-delete-btn vh" title="删除" alt="删除" />
|
<img src="{{ MEDIA_URL }}img/delete-20.png" data="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/?next={{ request.path }}" class="repo-delete-btn vh" title="删除" alt="删除" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% include "snippets/repo_share_form.html" %}
|
||||||
|
{% include "snippets/repo_create_form.html" %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
addConfirmTo($('#quit-group'), '确定要退出?');
|
{% include "snippets/myhome_extra_script.html" %}
|
||||||
addConfirmTo($('.cancel-share'), '确定要取消共享该目录?');
|
|
||||||
|
|
||||||
$("table tr:gt(0)").hover(
|
|
||||||
function() {
|
|
||||||
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
$(this).find('img').addClass('vh');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$('.download').click(function() {
|
|
||||||
window.open($(this).attr('data'));
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -6,14 +6,12 @@ from seahub.views import repo, repo_history, org_seafadmin, \
|
|||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^create/$', create_org, name='create_org'),
|
url(r'^create/$', create_org, name='create_org'),
|
||||||
(r'^change_account/$', change_account),
|
|
||||||
url(r'^messages/$', org_msg, name='org_msg'),
|
url(r'^messages/$', org_msg, name='org_msg'),
|
||||||
|
|
||||||
url(r'^(?P<url_prefix>[^/]+)/$', org_info, name='org_info'),
|
url(r'^(?P<url_prefix>[^/]+)/$', org_info, name='org_info'),
|
||||||
url(r'^(?P<url_prefix>[^/]+)/groups/$', org_groups, name='org_groups'),
|
url(r'^(?P<url_prefix>[^/]+)/groups/$', org_groups, name='org_groups'),
|
||||||
|
|
||||||
url(r'^([^/]+)/repo/(?P<repo_id>[^/]+)/$', repo, name='repo'),
|
url(r'^([^/]+)/repo/(?P<repo_id>[^/]+)/$', repo, name='repo'),
|
||||||
url(r'^([^/]+)/repo/history/(?P<repo_id>[^/]+)/$', repo_history, name='org_repo_history'),
|
url(r'^([^/]+)/repo/history/(?P<repo_id>[^/]+)/$', repo_history, name='org_repo_history'),
|
||||||
|
url(r'^([^/]+)/repo/create/$', org_repo_create, name='org_repo_create'),
|
||||||
|
|
||||||
### Org admin ###
|
### Org admin ###
|
||||||
url(r'^([^/]+)/seafadmin/$', org_seafadmin, name='org_seafadmin'),
|
url(r'^([^/]+)/seafadmin/$', org_seafadmin, name='org_seafadmin'),
|
||||||
|
@@ -12,7 +12,7 @@ from auth.decorators import login_required
|
|||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
from seaserv import ccnet_threaded_rpc, get_orgs_by_user, get_org_repos, \
|
from seaserv import ccnet_threaded_rpc, get_orgs_by_user, get_org_repos, \
|
||||||
get_org_by_url_prefix, create_org, get_user_current_org, add_org_user, \
|
get_org_by_url_prefix, create_org, get_user_current_org, add_org_user, \
|
||||||
get_ccnetuser, remove_org_user, get_org_groups
|
get_ccnetuser, remove_org_user, get_org_groups, is_valid_filename
|
||||||
|
|
||||||
from forms import OrgCreateForm
|
from forms import OrgCreateForm
|
||||||
from signals import org_user_added
|
from signals import org_user_added
|
||||||
@@ -25,11 +25,10 @@ from seahub.utils import go_error, go_permission_error, validate_group_name, \
|
|||||||
emails2list, gen_token
|
emails2list, gen_token
|
||||||
from seahub.views import myhome
|
from seahub.views import myhome
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def create_org(request):
|
def create_org(request):
|
||||||
"""
|
"""
|
||||||
|
Create org account.
|
||||||
"""
|
"""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = OrgCreateForm(request.POST)
|
form = OrgCreateForm(request.POST)
|
||||||
@@ -53,20 +52,10 @@ def create_org(request):
|
|||||||
'form': form,
|
'form': form,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
|
||||||
def change_account(request):
|
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
orgs = get_orgs_by_user(request.user.username)
|
|
||||||
|
|
||||||
return render_to_response('organizations/change_account.html', {
|
|
||||||
'orgs': orgs,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def org_info(request, url_prefix):
|
def org_info(request, url_prefix):
|
||||||
"""
|
"""
|
||||||
|
Show org info page.
|
||||||
"""
|
"""
|
||||||
org = get_user_current_org(request.user.username, url_prefix)
|
org = get_user_current_org(request.user.username, url_prefix)
|
||||||
if not org:
|
if not org:
|
||||||
@@ -77,16 +66,19 @@ def org_info(request, url_prefix):
|
|||||||
org_members = ccnet_threaded_rpc.get_org_emailusers(url_prefix,
|
org_members = ccnet_threaded_rpc.get_org_emailusers(url_prefix,
|
||||||
0, sys.maxint)
|
0, sys.maxint)
|
||||||
repos = get_org_repos(org.org_id, 0, sys.maxint)
|
repos = get_org_repos(org.org_id, 0, sys.maxint)
|
||||||
|
|
||||||
|
url = 'organizations/%s/repo/create/' % org.url_prefix
|
||||||
return render_to_response('organizations/org_info.html', {
|
return render_to_response('organizations/org_info.html', {
|
||||||
'org': org,
|
'org': org,
|
||||||
'org_users': org_members,
|
'org_users': org_members,
|
||||||
'repos': repos,
|
'repos': repos,
|
||||||
|
'url': seahub_settings.SITE_ROOT + url,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def org_groups(request, url_prefix):
|
def org_groups(request, url_prefix):
|
||||||
"""
|
"""
|
||||||
|
List org groups and add org group.
|
||||||
"""
|
"""
|
||||||
org = get_user_current_org(request.user.username, url_prefix)
|
org = get_user_current_org(request.user.username, url_prefix)
|
||||||
if not org:
|
if not org:
|
||||||
@@ -232,8 +224,64 @@ def org_msg(request):
|
|||||||
# remove new org msg notification
|
# remove new org msg notification
|
||||||
UserNotification.objects.filter(to_user=request.user.username,
|
UserNotification.objects.filter(to_user=request.user.username,
|
||||||
msg_type='org_msg').delete()
|
msg_type='org_msg').delete()
|
||||||
print orgmsg_list
|
|
||||||
return render_to_response('organizations/new_msg.html', {
|
return render_to_response('organizations/new_msg.html', {
|
||||||
'orgmsg_list': orgmsg_list,
|
'orgmsg_list': orgmsg_list,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def org_repo_create(request):
|
||||||
|
'''
|
||||||
|
Handle ajax post to create org repo.
|
||||||
|
|
||||||
|
'''
|
||||||
|
if request.method != 'POST':
|
||||||
|
return Http404
|
||||||
|
repo_name = request.POST.get("repo_name")
|
||||||
|
repo_desc = request.POST.get("repo_desc")
|
||||||
|
encrypted = int(request.POST.get("encryption"))
|
||||||
|
passwd = request.POST.get("passwd")
|
||||||
|
passwd_again = request.POST.get("passwd_again")
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
content_type = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
|
error_msg = ""
|
||||||
|
if not repo_name:
|
||||||
|
error_msg = u"目录名不能为空"
|
||||||
|
elif len(repo_name) > 50:
|
||||||
|
error_msg = u"目录名太长"
|
||||||
|
elif not is_valid_filename(repo_name):
|
||||||
|
error_msg = (u"您输入的目录名 %s 包含非法字符" % repo_name)
|
||||||
|
elif not repo_desc:
|
||||||
|
error_msg = u"描述不能为空"
|
||||||
|
elif len(repo_desc) > 100:
|
||||||
|
error_msg = u"描述太长"
|
||||||
|
elif encrypted == 1:
|
||||||
|
if not passwd:
|
||||||
|
error_msg = u"密码不能为空"
|
||||||
|
elif not passwd_again:
|
||||||
|
error_msg = u"确认密码不能为空"
|
||||||
|
elif len(passwd) < 3:
|
||||||
|
error_msg = u"密码太短"
|
||||||
|
elif len(passwd) > 15:
|
||||||
|
error_msg = u"密码太长"
|
||||||
|
elif passwd != passwd_again:
|
||||||
|
error_msg = u"两次输入的密码不相同"
|
||||||
|
|
||||||
|
if error_msg:
|
||||||
|
result['error'] = error_msg
|
||||||
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||||
|
|
||||||
|
try:
|
||||||
|
user = request.user.username
|
||||||
|
org_id = request.user.org['org_id']
|
||||||
|
repo_id = create_org_repo(repo_name, repo_desc, user, passwd, org_id)
|
||||||
|
result['success'] = True
|
||||||
|
except:
|
||||||
|
result['error'] = u"创建目录失败"
|
||||||
|
else:
|
||||||
|
if not repo_id:
|
||||||
|
result['error'] = u"创建目录失败"
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||||
|
@@ -152,165 +152,13 @@
|
|||||||
<p>暂无</p>
|
<p>暂无</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form id="repo-share-form" action="{{ SITE_ROOT }}share/add/" method="post" name="repo-share-form" class="hide">
|
{% include "snippets/repo_share_form.html" %}
|
||||||
<label>邮箱或小组:</label><br />
|
{% include "snippets/repo_create_form.html" %}
|
||||||
<textarea id="email_or_group" name="email_or_group"></textarea>
|
|
||||||
<input id="repo_id" type="hidden" name="repo_id" value="" />
|
|
||||||
<p class="tip">可以是非网站注册用户,我们会以邮件通知对方。</p>
|
|
||||||
<p class="tip">(如未收到,请检查垃圾邮件)</p>
|
|
||||||
<p class="error hide">输入不能为空。</p>
|
|
||||||
<input type="submit" value="提交" id="share-submit-btn" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="repo-create-form" action="{{ SITE_ROOT }}repo/create/" method="post" class="hide">
|
|
||||||
<h3>新建同步目录</h3>
|
|
||||||
<label>名称:</label><br/>
|
|
||||||
<input id="repo-name" type="text" name="repo_name" value="" /><br />
|
|
||||||
<label>描述:</label><br/>
|
|
||||||
<textarea id="repo-desc" name="repo_desc"></textarea>
|
|
||||||
<div class="repo-create-encryption">
|
|
||||||
<input type="checkbox" name="encryption" id="encrypt-switch" /><label>加密</label><br />
|
|
||||||
<label>密码:</label><span class="tip">(3到15个字符)</span><br />
|
|
||||||
<input type="password" name="passwd" disabled="disabled" class="passwd input-disabled" /><br />
|
|
||||||
<label>密码确认:</label><br />
|
|
||||||
<input type="password" name="passwd_again" disabled="disabled" class="passwd input-disabled" />
|
|
||||||
</div>
|
|
||||||
<p class="error hide"></p>
|
|
||||||
<input type="submit" id="repo-create-submit" value="提交" class="submit" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
{% include "snippets/myhome_extra_script.html" %}
|
||||||
//repo-share-form share-list autocomplete
|
|
||||||
var share_list = [];
|
|
||||||
{% for contact in contacts %}
|
|
||||||
share_list.push('{{ contact.contact_email }}');
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for group in groups %}
|
|
||||||
share_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>');
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
$(".repo-share-btn").click(function() {
|
|
||||||
$("#repo_id").val($(this).attr("data"));
|
|
||||||
$("#repo-share-form").modal({appendTo: "#main"});
|
|
||||||
addAutocomplete('#email_or_group', '#repo-share-form', share_list);
|
|
||||||
});
|
|
||||||
|
|
||||||
//check before post
|
|
||||||
$('#share-submit-btn').click(function() {
|
|
||||||
if (!$.trim($('#email_or_group').attr('value'))) {
|
|
||||||
$('#repo-share-form .error').removeClass('hide');
|
|
||||||
$('#simplemodal-container').css('height', $('#repo-share-form').height());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addConfirmTo($('.repo-delete-btn'));
|
|
||||||
|
|
||||||
addConfirmTo($('.unshare-btn'), '确定要取消共享?');
|
|
||||||
|
|
||||||
$(".download-btn").click(function() {
|
|
||||||
window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + $(this).attr('data'));
|
|
||||||
});
|
|
||||||
|
|
||||||
//show op images when mouse hover on
|
|
||||||
$("table tr:gt(0)").hover(
|
|
||||||
function() {
|
|
||||||
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
$(this).find('img').addClass('vh');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
//repo-create-form
|
|
||||||
$('#repo-create').hover(
|
|
||||||
function() {
|
|
||||||
$(this).css({'background-color': '#fff', 'cursor': 'pointer'});
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
$(this).css('background-color', '#f5f5f5');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$('#repo-create').click(function() {
|
|
||||||
$('#repo-create-form').modal({appendTo: '#main', autoResize: true});
|
|
||||||
});
|
|
||||||
$('#encrypt-switch').click(function () {
|
|
||||||
if ($(this).attr('checked')) {
|
|
||||||
$('#repo-create-form input[type="password"]').attr('disabled', false).removeClass('input-disabled');
|
|
||||||
} else {
|
|
||||||
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
function showError(err) {
|
|
||||||
$('#repo-create-form .error').html(err).attr('class','error');
|
|
||||||
$('#simplemodal-container').css('height', $('#repo-create-form').height());
|
|
||||||
}
|
|
||||||
$('#repo-create-submit').click(function() {
|
|
||||||
var passwd = $('#repo-create-form input[name="passwd"]'),
|
|
||||||
passwd_again = $('#repo-create-form input[name="passwd_again"]');
|
|
||||||
|
|
||||||
if (!$('#repo-name').val()) {
|
|
||||||
showError('目录名不能为空。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$('#repo-desc').val()) {
|
|
||||||
showError('描述不能为空。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($('#encrypt-switch').attr('checked')) {
|
|
||||||
if (!passwd.val()) {
|
|
||||||
showError('密码不能为空。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!passwd_again.val()) {
|
|
||||||
showError('请确认密码。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (passwd.val().length < 3) {
|
|
||||||
showError('密码太短。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (passwd.val().length > 15) {
|
|
||||||
showError('密码太长。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (passwd.val() != passwd_again.val()) {
|
|
||||||
showError('两次输入的密码不一致。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '{{ SITE_ROOT }}repo/create/',
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
cache: 'false',
|
|
||||||
contentType: 'application/json; charset=utf-8',
|
|
||||||
beforeSend: prepareCSRFToken,
|
|
||||||
data: {
|
|
||||||
'repo_name': $('#repo-name').val(),
|
|
||||||
'repo_desc': $('#repo-desc').val(),
|
|
||||||
'encryption': $('#encrypt-switch').attr('checked') ? 1 : 0,
|
|
||||||
'passwd': passwd.val(),
|
|
||||||
'passwd_again': passwd_again.val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
if (data['success']) {
|
|
||||||
location.reload(true);
|
|
||||||
} else {
|
|
||||||
showError(data['error']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
129
templates/myhome_extra_script.html
Normal file
129
templates/myhome_extra_script.html
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
$(function() {
|
||||||
|
//repo-share-form share-list autocomplete
|
||||||
|
var share_list = [];
|
||||||
|
{% for contact in contacts %}
|
||||||
|
share_list.push('{{ contact.contact_email }}');
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for group in groups %}
|
||||||
|
share_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>');
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
$(".repo-share-btn").click(function() {
|
||||||
|
$("#repo_id").val($(this).attr("data"));
|
||||||
|
$("#repo-share-form").modal({appendTo: "#main"});
|
||||||
|
addAutocomplete('#email_or_group', '#repo-share-form', share_list);
|
||||||
|
});
|
||||||
|
|
||||||
|
//check before post
|
||||||
|
$('#share-submit-btn').click(function() {
|
||||||
|
if (!$.trim($('#email_or_group').attr('value'))) {
|
||||||
|
$('#repo-share-form .error').removeClass('hide');
|
||||||
|
$('#simplemodal-container').css('height', $('#repo-share-form').height());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addConfirmTo($('.repo-delete-btn'));
|
||||||
|
|
||||||
|
addConfirmTo($('.unshare-btn'), '确定要取消共享?');
|
||||||
|
|
||||||
|
$(".download-btn").click(function() {
|
||||||
|
window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + $(this).attr('data'));
|
||||||
|
});
|
||||||
|
|
||||||
|
//show op images when mouse hover on
|
||||||
|
$("table tr:gt(0)").hover(
|
||||||
|
function() {
|
||||||
|
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).find('img').addClass('vh');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
//repo-create-form
|
||||||
|
$('#repo-create').hover(
|
||||||
|
function() {
|
||||||
|
$(this).css({'background-color': '#fff', 'cursor': 'pointer'});
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).css('background-color', '#f5f5f5');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$('#repo-create').click(function() {
|
||||||
|
$('#repo-create-form').modal({appendTo: '#main', autoResize: true});
|
||||||
|
});
|
||||||
|
$('#encrypt-switch').click(function () {
|
||||||
|
if ($(this).attr('checked')) {
|
||||||
|
$('#repo-create-form input[type="password"]').attr('disabled', false).removeClass('input-disabled');
|
||||||
|
} else {
|
||||||
|
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
function showError(err) {
|
||||||
|
$('#repo-create-form .error').html(err).attr('class','error');
|
||||||
|
$('#simplemodal-container').css('height', $('#repo-create-form').height());
|
||||||
|
}
|
||||||
|
$('#repo-create-submit').click(function() {
|
||||||
|
var passwd = $('#repo-create-form input[name="passwd"]'),
|
||||||
|
passwd_again = $('#repo-create-form input[name="passwd_again"]');
|
||||||
|
|
||||||
|
if (!$('#repo-name').val()) {
|
||||||
|
showError('目录名不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$('#repo-desc').val()) {
|
||||||
|
showError('描述不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('#encrypt-switch').attr('checked')) {
|
||||||
|
if (!passwd.val()) {
|
||||||
|
showError('密码不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!passwd_again.val()) {
|
||||||
|
showError('请确认密码。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val().length < 3) {
|
||||||
|
showError('密码太短。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val().length > 15) {
|
||||||
|
showError('密码太长。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val() != passwd_again.val()) {
|
||||||
|
showError('两次输入的密码不一致。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ url }}',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
cache: 'false',
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
data: {
|
||||||
|
'repo_name': $('#repo-name').val(),
|
||||||
|
'repo_desc': $('#repo-desc').val(),
|
||||||
|
'encryption': $('#encrypt-switch').attr('checked') ? 1 : 0,
|
||||||
|
'passwd': passwd.val(),
|
||||||
|
'passwd_again': passwd_again.val()
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
if (data['success']) {
|
||||||
|
location.reload(true);
|
||||||
|
} else {
|
||||||
|
showError(data['error']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
130
templates/snippets/myhome_extra_script.html
Normal file
130
templates/snippets/myhome_extra_script.html
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
$(function() {
|
||||||
|
//repo-share-form share-list autocomplete
|
||||||
|
var share_list = [];
|
||||||
|
{% for contact in contacts %}
|
||||||
|
share_list.push('{{ contact.contact_email }}');
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for group in groups %}
|
||||||
|
share_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>');
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
$(".repo-share-btn").click(function() {
|
||||||
|
$("#repo_id").val($(this).attr("data"));
|
||||||
|
$("#repo-share-form").modal({appendTo: "#main"});
|
||||||
|
addAutocomplete('#email_or_group', '#repo-share-form', share_list);
|
||||||
|
});
|
||||||
|
|
||||||
|
//check before post
|
||||||
|
$('#share-submit-btn').click(function() {
|
||||||
|
if (!$.trim($('#email_or_group').attr('value'))) {
|
||||||
|
$('#repo-share-form .error').removeClass('hide');
|
||||||
|
$('#simplemodal-container').css('height', $('#repo-share-form').height());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addConfirmTo($('.repo-delete-btn'));
|
||||||
|
|
||||||
|
addConfirmTo($('.unshare-btn'), '确定要取消共享?');
|
||||||
|
|
||||||
|
$(".download-btn").click(function() {
|
||||||
|
window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + $(this).attr('data'));
|
||||||
|
});
|
||||||
|
|
||||||
|
//show op images when mouse hover on
|
||||||
|
$("table tr:gt(0)").hover(
|
||||||
|
function() {
|
||||||
|
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).find('img').addClass('vh');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
//repo-create-form
|
||||||
|
$('#repo-create').hover(
|
||||||
|
function() {
|
||||||
|
$(this).css({'background-color': '#fff', 'cursor': 'pointer'});
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).css('background-color', '#f5f5f5');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$('#repo-create').click(function() {
|
||||||
|
$('#repo-create-form').modal({appendTo: '#main', autoResize: true});
|
||||||
|
});
|
||||||
|
$('#encrypt-switch').click(function () {
|
||||||
|
if ($(this).attr('checked')) {
|
||||||
|
$('#repo-create-form input[type="password"]').attr('disabled', false).removeClass('input-disabled');
|
||||||
|
} else {
|
||||||
|
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
function showError(err) {
|
||||||
|
$('#repo-create-form .error').html(err).attr('class','error');
|
||||||
|
$('#simplemodal-container').css('height', $('#repo-create-form').height());
|
||||||
|
}
|
||||||
|
$('#repo-create-submit').click(function() {
|
||||||
|
var passwd = $('#repo-create-form input[name="passwd"]'),
|
||||||
|
passwd_again = $('#repo-create-form input[name="passwd_again"]');
|
||||||
|
|
||||||
|
if (!$('#repo-name').val()) {
|
||||||
|
showError('目录名不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$('#repo-desc').val()) {
|
||||||
|
showError('描述不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('#encrypt-switch').attr('checked')) {
|
||||||
|
if (!passwd.val()) {
|
||||||
|
showError('密码不能为空。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!passwd_again.val()) {
|
||||||
|
showError('请确认密码。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val().length < 3) {
|
||||||
|
showError('密码太短。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val().length > 15) {
|
||||||
|
showError('密码太长。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (passwd.val() != passwd_again.val()) {
|
||||||
|
showError('两次输入的密码不一致。');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ url }}',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
cache: 'false',
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
data: {
|
||||||
|
'repo_name': $('#repo-name').val(),
|
||||||
|
'repo_desc': $('#repo-desc').val(),
|
||||||
|
'encryption': $('#encrypt-switch').attr('checked') ? 1 : 0,
|
||||||
|
'passwd': passwd.val(),
|
||||||
|
'passwd_again': passwd_again.val()
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
alert(data);
|
||||||
|
if (data['success']) {
|
||||||
|
location.reload(true);
|
||||||
|
} else {
|
||||||
|
showError(data['error']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
16
templates/snippets/repo_create_form.html
Normal file
16
templates/snippets/repo_create_form.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<form id="repo-create-form" action="{{ SITE_ROOT }}repo/create/" method="post" class="hide">
|
||||||
|
<h3>新建同步目录</h3>
|
||||||
|
<label>名称:</label><br/>
|
||||||
|
<input id="repo-name" type="text" name="repo_name" value="" /><br />
|
||||||
|
<label>描述:</label><br/>
|
||||||
|
<textarea id="repo-desc" name="repo_desc"></textarea>
|
||||||
|
<div class="repo-create-encryption">
|
||||||
|
<input type="checkbox" name="encryption" id="encrypt-switch" /><label>加密</label><br />
|
||||||
|
<label>密码:</label><span class="tip">(3到15个字符)</span><br />
|
||||||
|
<input type="password" name="passwd" disabled="disabled" class="passwd input-disabled" /><br />
|
||||||
|
<label>密码确认:</label><br />
|
||||||
|
<input type="password" name="passwd_again" disabled="disabled" class="passwd input-disabled" />
|
||||||
|
</div>
|
||||||
|
<p class="error hide"></p>
|
||||||
|
<input type="submit" id="repo-create-submit" value="提交" class="submit" />
|
||||||
|
</form>
|
9
templates/snippets/repo_share_form.html
Normal file
9
templates/snippets/repo_share_form.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<form id="repo-share-form" action="{{ SITE_ROOT }}share/add/" method="post" name="repo-share-form" class="hide">
|
||||||
|
<label>邮箱或小组:</label><br />
|
||||||
|
<textarea id="email_or_group" name="email_or_group"></textarea>
|
||||||
|
<input id="repo_id" type="hidden" name="repo_id" value="" />
|
||||||
|
<p class="tip">可以是非网站注册用户,我们会以邮件通知对方。</p>
|
||||||
|
<p class="tip">(如未收到,请检查垃圾邮件)</p>
|
||||||
|
<p class="error hide">输入不能为空。</p>
|
||||||
|
<input type="submit" value="提交" id="share-submit-btn" />
|
||||||
|
</form>
|
@@ -9,7 +9,8 @@ from service import get_binding_peerids
|
|||||||
from service import get_ccnetuser, get_emailusers
|
from service import get_ccnetuser, get_emailusers
|
||||||
from service import get_group_repoids, check_group_staff
|
from service import get_group_repoids, check_group_staff
|
||||||
from service import create_org, get_orgs_by_user, get_org_by_url_prefix, \
|
from service import create_org, get_orgs_by_user, get_org_by_url_prefix, \
|
||||||
get_user_current_org, add_org_user, remove_org_user, get_org_by_id
|
get_user_current_org, add_org_user, remove_org_user, get_org_by_id, \
|
||||||
|
is_valid_filename
|
||||||
|
|
||||||
from service import CCNET_CONF_PATH
|
from service import CCNET_CONF_PATH
|
||||||
|
|
||||||
|
@@ -115,6 +115,14 @@ def get_emailusers(start, limit):
|
|||||||
# group.maintainers = group.props.maintainers.split(" ")
|
# group.maintainers = group.props.maintainers.split(" ")
|
||||||
# return group
|
# return group
|
||||||
|
|
||||||
|
def check_group_staff(group_id_int, user_or_username):
|
||||||
|
"""Check where user is group staff"""
|
||||||
|
from seahub.base.accounts import CcnetUser
|
||||||
|
if isinstance(user_or_username, CcnetUser):
|
||||||
|
user_or_username = user_or_username.username
|
||||||
|
|
||||||
|
return ccnet_threaded_rpc.check_group_staff(group_id_int, user_or_username)
|
||||||
|
|
||||||
def get_org_groups(org_id, start, limit):
|
def get_org_groups(org_id, start, limit):
|
||||||
try:
|
try:
|
||||||
groups = ccnet_threaded_rpc.get_org_groups(org_id, 0, sys.maxint)
|
groups = ccnet_threaded_rpc.get_org_groups(org_id, 0, sys.maxint)
|
||||||
@@ -198,6 +206,18 @@ def get_repos():
|
|||||||
"""
|
"""
|
||||||
return seafserv_threaded_rpc.get_repo_list("", 100)
|
return seafserv_threaded_rpc.get_repo_list("", 100)
|
||||||
|
|
||||||
|
def create_org_repo(repo_name, repo_desc, user, passwd, org_id):
|
||||||
|
"""
|
||||||
|
Create org repo, return valid repo id if success.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
repo_id = seafserv_threaded_rpc.create_org_repo(repo_name, repo_desc,
|
||||||
|
user, passwd, org_id)
|
||||||
|
except SearpcError:
|
||||||
|
repo_id = None
|
||||||
|
|
||||||
|
return repo_id
|
||||||
|
|
||||||
def get_org_repos(org_id, start, limit):
|
def get_org_repos(org_id, start, limit):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
@@ -253,11 +273,13 @@ def get_group_repoids(group_id=None):
|
|||||||
repoid_list.append(repo_id)
|
repoid_list.append(repo_id)
|
||||||
return repoid_list
|
return repoid_list
|
||||||
|
|
||||||
def check_group_staff(group_id_int, user_or_username):
|
def is_valid_filename(file_or_dir):
|
||||||
"""Check where user is group staff"""
|
"""
|
||||||
from seahub.base.accounts import CcnetUser
|
Check whether file name or directory name is valid.
|
||||||
if isinstance(user_or_username, CcnetUser):
|
"""
|
||||||
user_or_username = user_or_username.username
|
try:
|
||||||
|
ret = seafserv_threaded_rpc.is_valid_filename('', file_or_dir)
|
||||||
return ccnet_threaded_rpc.check_group_staff(group_id_int, user_or_username)
|
except SearpcError:
|
||||||
|
ret = 0
|
||||||
|
|
||||||
|
return ret
|
||||||
|
9
views.py
9
views.py
@@ -28,7 +28,7 @@ from auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, \
|
|||||||
from auth.tokens import default_token_generator
|
from auth.tokens import default_token_generator
|
||||||
from share.models import FileShare
|
from share.models import FileShare
|
||||||
from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_repos, get_emailusers, \
|
from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_repos, get_emailusers, \
|
||||||
get_repo, get_commits, get_branches, \
|
get_repo, get_commits, get_branches, is_valid_filename, \
|
||||||
seafserv_threaded_rpc, seafserv_rpc, get_binding_peerids, get_ccnetuser, \
|
seafserv_threaded_rpc, seafserv_rpc, get_binding_peerids, get_ccnetuser, \
|
||||||
get_group_repoids, check_group_staff, get_personal_groups
|
get_group_repoids, check_group_staff, get_personal_groups
|
||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
@@ -744,6 +744,7 @@ def myhome(request):
|
|||||||
"orgmsg_list": orgmsg_list,
|
"orgmsg_list": orgmsg_list,
|
||||||
"groups_manage": groups_manage,
|
"groups_manage": groups_manage,
|
||||||
"groups_join": groups_join,
|
"groups_join": groups_join,
|
||||||
|
"url": settings.SITE_ROOT + 'repo/create/',
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -1596,7 +1597,7 @@ def repo_new_dir(request):
|
|||||||
return go_error (request, error_msg)
|
return go_error (request, error_msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not seafserv_threaded_rpc.is_valid_filename(repo_id, new_dir_name):
|
if not is_valid_filename(new_dir_name):
|
||||||
error_msg = (u"您输入的目录名称 %s 包含非法字符" % new_dir_name)
|
error_msg = (u"您输入的目录名称 %s 包含非法字符" % new_dir_name)
|
||||||
return go_error (request, error_msg)
|
return go_error (request, error_msg)
|
||||||
except SearpcError,e:
|
except SearpcError,e:
|
||||||
@@ -1651,7 +1652,7 @@ def validate_filename(request):
|
|||||||
result = {'ret':'yes'}
|
result = {'ret':'yes'}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = seafserv_threaded_rpc.is_valid_filename (repo_id, filename);
|
ret = is_valid_filename(filename);
|
||||||
except SearpcError:
|
except SearpcError:
|
||||||
result['ret'] = 'error'
|
result['ret'] = 'error'
|
||||||
else:
|
else:
|
||||||
@@ -1681,7 +1682,7 @@ def repo_create(request):
|
|||||||
error_msg = u"目录名不能为空"
|
error_msg = u"目录名不能为空"
|
||||||
elif len(repo_name) > 50:
|
elif len(repo_name) > 50:
|
||||||
error_msg = u"目录名太长"
|
error_msg = u"目录名太长"
|
||||||
elif not seafserv_threaded_rpc.is_valid_filename('', repo_name):
|
elif not is_valid_filename(repo_name):
|
||||||
error_msg = (u"您输入的目录名 %s 包含非法字符" % repo_name)
|
error_msg = (u"您输入的目录名 %s 包含非法字符" % repo_name)
|
||||||
elif not repo_desc:
|
elif not repo_desc:
|
||||||
error_msg = u"描述不能为空"
|
error_msg = u"描述不能为空"
|
||||||
|
Reference in New Issue
Block a user