mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-02 07:47:32 +00:00
[shareadmin]added permission-set
This commit is contained in:
parent
c6cbb8fc67
commit
fc2011c856
@ -1301,6 +1301,11 @@ ul.with-bg li {
|
||||
.view-link-alert p {
|
||||
display: inline-block;
|
||||
}
|
||||
.share-permission {
|
||||
background:#fff;
|
||||
border:1px solid #eee;
|
||||
border-radius:2px;
|
||||
}
|
||||
/*bottom bar*/
|
||||
#bottom-bar button {
|
||||
color:#fff;
|
||||
|
@ -21,6 +21,7 @@ urlpatterns = patterns('',
|
||||
# repo share
|
||||
url(r'^(?P<url_prefix>[^/]+)/shareadmin/$', org_shareadmin, name='org_shareadmin'),
|
||||
url(r'^(?P<url_prefix>[^/]+)/repo/share/$', org_repo_share, name='org_repo_share'),
|
||||
url(r'^(?P<url_prefix>[^/]+)/share/permission_admin/$', org_share_permission_admin, name='org_share_permission_admin'),
|
||||
|
||||
# url(r'^([^/]+)/repo/(?P<repo_id>[^/]+)/$', RepoView.as_view(), name='repo'),
|
||||
|
||||
|
@ -575,7 +575,7 @@ def org_repo_share(request, url_prefix):
|
||||
repo_id, permission)
|
||||
except:
|
||||
msg = u'共享到公共资料失败'
|
||||
message.add_message(request, message.ERROR, msg)
|
||||
messages.add_message(request, messages.ERROR, msg)
|
||||
continue
|
||||
|
||||
msg = u'共享公共资料成功,请前往<a href="%s">共享管理</a>查看。' % \
|
||||
@ -658,6 +658,7 @@ def org_shareadmin(request, url_prefix):
|
||||
repo.props.user = ''
|
||||
continue
|
||||
repo.props.user = group.props.group_name
|
||||
repo.props.user_info = repo.group_id
|
||||
shared_repos += group_repos
|
||||
|
||||
# public repos shared by this user
|
||||
@ -665,6 +666,7 @@ def org_shareadmin(request, url_prefix):
|
||||
username)
|
||||
for repo in pub_repos:
|
||||
repo.props.user = '所有团体成员'
|
||||
repo.props.user_info = 'all'
|
||||
shared_repos += pub_repos
|
||||
|
||||
for repo in shared_repos:
|
||||
@ -675,6 +677,9 @@ def org_shareadmin(request, url_prefix):
|
||||
else:
|
||||
repo.share_permission = ''
|
||||
|
||||
if repo.props.share_type == 'personal':
|
||||
repo.props.user_info = repo.props.user
|
||||
|
||||
shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))
|
||||
|
||||
# File shared links
|
||||
@ -697,6 +702,42 @@ def org_shareadmin(request, url_prefix):
|
||||
"domain": RequestSite(request).domain,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def org_share_permission_admin(request, url_prefix):
|
||||
org_id = int(request.GET.get('org_id', ''))
|
||||
share_type = request.GET.get('share_type', '')
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
||||
form = RepoShareForm(request.POST)
|
||||
form.is_valid()
|
||||
|
||||
email_or_group = form.cleaned_data['email_or_group']
|
||||
repo_id = form.cleaned_data['repo_id']
|
||||
permission = form.cleaned_data['permission']
|
||||
from_email = request.user.username
|
||||
|
||||
if share_type == 'personal':
|
||||
try:
|
||||
seafserv_threaded_rpc.set_share_permission(repo_id, from_email, email_or_group, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
if share_type == 'group':
|
||||
group_id = int(email_or_group)
|
||||
try:
|
||||
seafserv_threaded_rpc.set_org_group_repo_permission(org_id, group_id, repo_id, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
if share_type == 'public':
|
||||
try:
|
||||
seafserv_threaded_rpc.set_org_inner_pub_repo(org_id, repo_id, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
@login_required
|
||||
def org_pubinfo(request, url_prefix):
|
||||
"""
|
||||
|
@ -1,5 +1,6 @@
|
||||
{% extends base_template %}
|
||||
{% load seahub_tags %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block nav_shareadmin_class %}class="cur"{% endblock %}
|
||||
|
||||
@ -12,21 +13,30 @@
|
||||
{% block right_panel %}
|
||||
<h3>我共享的资料库</h3>
|
||||
{% if shared_repos %}
|
||||
<table class="repo-list">
|
||||
<table>
|
||||
<tr>
|
||||
<th width="4%"><!--icon--></th>
|
||||
<th width="20%">名字</th>
|
||||
<th width="25%">共享给</th>
|
||||
<th width="10%">权限</th>
|
||||
<th width="22%">共享给</th>
|
||||
<th width="13%">权限</th>
|
||||
<th width="30%">描述</th>
|
||||
<th width="11%">操作</th>
|
||||
</tr>
|
||||
{% for repo in shared_repos %}
|
||||
<tr>
|
||||
<tr data="{{repo.props.share_type}}">
|
||||
<td><img src="{{MEDIA_URL}}img/sync-folder-20.png" title="可读写" alt="目录icon" /></td>
|
||||
<td><a href="{{ SITE_ROOT }}repo/{{ repo.props.repo_id }}">{{ repo.props.repo_name }}</a></td>
|
||||
<td>{{ repo.props.user }}</td>
|
||||
<td>{{ repo.share_permission }}</td>
|
||||
<td data="{{ repo.props.repo_id }}"><a href="{{ SITE_ROOT }}repo/{{ repo.props.repo_id }}">{{ repo.props.repo_name }}</a></td>
|
||||
<td data="{{repo.props.user_info}}">{{ repo.props.user }}</td>
|
||||
<td>
|
||||
<select name="permission" class="share-permission">
|
||||
<option value="{{ repo.props.permission }}" selected="selected">{{ repo.share_permission }}</option>
|
||||
{% if repo.props.permission == 'rw' %}
|
||||
<option value="r">只可浏览</option>
|
||||
{% else %}
|
||||
<option value="rw">可读写</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</td>
|
||||
<td>{{ repo.props.repo_desc }}</td>
|
||||
<td>
|
||||
{% if repo.props.share_type == 'group' %}
|
||||
@ -79,6 +89,49 @@
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
$('.share-permission').change(function() {
|
||||
var select = $(this),
|
||||
select_cont = $(this).parent(),
|
||||
user = select_cont.prev(),
|
||||
share_type = select_cont.parent().attr('data');
|
||||
{% if org %}
|
||||
var url = '{% url 'org_share_permission_admin' org.url_prefix %}?org_id={{ org.org_id }}&share_type=' + share_type;
|
||||
{% else %}
|
||||
var url = '{% url 'share_permission_admin' %}?share_type=' + share_type;
|
||||
{% endif %}
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
contentType: 'application/json; charset=utf-8',
|
||||
beforeSend: prepareCSRFToken,
|
||||
data: {
|
||||
repo_id: user.prev().attr('data'),
|
||||
email_or_group: user.attr('data'),
|
||||
permission: select.val()
|
||||
},
|
||||
success: function(data) {
|
||||
if (data['success']) {
|
||||
feedback('权限设置成功', 'success');
|
||||
} else {
|
||||
feedback('权限设置失败', 'error');
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
feedback(textStatus + ',权限设置失败', 'error');
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
function feedback(con, type) {
|
||||
var html = '<ul class="messages"><li class="' + type + '">' + con + '</li></ul>';
|
||||
$('#main').append(html).css('position','relative');
|
||||
$('.messages').css({'left':($('#main').width() - $('.messages').width())/2 + 'px', 'top':'-20px'}).removeClass('hide');
|
||||
setTimeout(function() { $('.messages').addClass('hide'); }, 10000);
|
||||
}
|
||||
|
||||
$('.cancel-share').click(function() {
|
||||
location.href = $(this).attr('data');
|
||||
});
|
||||
|
@ -6,4 +6,5 @@ urlpatterns = patterns('',
|
||||
url(r'^add/$', share_repo, name='share_repo'),
|
||||
url('^remove/(?P<token>[^/]{24,24})/$', remove_anonymous_share, name='remove_anonymous_share'),
|
||||
url('^(?P<token>[^/]{24,24})/$', anonymous_share_confirm, name='anonymous_share_confirm'),
|
||||
url(r'^permission_admin/$', share_permission_admin, name='share_permission_admin'),
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
# encoding: utf-8
|
||||
import os
|
||||
import simplejson as json
|
||||
from django.core.mail import send_mail
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
@ -152,6 +153,7 @@ def share_admin(request):
|
||||
repo.props.user = ''
|
||||
continue
|
||||
repo.props.user = group.props.group_name
|
||||
repo.props.user_info = repo.group_id
|
||||
shared_repos += group_repos
|
||||
|
||||
if not CLOUD_MODE:
|
||||
@ -159,6 +161,7 @@ def share_admin(request):
|
||||
pub_repos = seafserv_threaded_rpc.list_inner_pub_repos_by_owner(username)
|
||||
for repo in pub_repos:
|
||||
repo.props.user = '所有人'
|
||||
repo.props.user_info = 'all'
|
||||
shared_repos += pub_repos
|
||||
|
||||
for repo in shared_repos:
|
||||
@ -169,6 +172,9 @@ def share_admin(request):
|
||||
else:
|
||||
repo.share_permission = ''
|
||||
|
||||
if repo.props.share_type == 'personal':
|
||||
repo.props.user_info = repo.props.user
|
||||
|
||||
shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id))
|
||||
|
||||
# Repo anonymous share links
|
||||
@ -197,6 +203,40 @@ def share_admin(request):
|
||||
"domain": RequestSite(request).domain,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def share_permission_admin(request):
|
||||
share_type = request.GET.get('share_type', '')
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
||||
form = RepoShareForm(request.POST)
|
||||
form.is_valid()
|
||||
|
||||
email_or_group = form.cleaned_data['email_or_group']
|
||||
repo_id = form.cleaned_data['repo_id']
|
||||
permission = form.cleaned_data['permission']
|
||||
from_email = request.user.username
|
||||
|
||||
if share_type == 'personal':
|
||||
try:
|
||||
seafserv_threaded_rpc.set_share_permission(repo_id, from_email, email_or_group, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
if share_type == 'group':
|
||||
try:
|
||||
seafserv_threaded_rpc.set_group_repo_permission(int(email_or_group), repo_id, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
if share_type == 'public':
|
||||
try:
|
||||
seafserv_threaded_rpc.set_inner_pub_repo(repo_id, permission)
|
||||
except:
|
||||
return HttpResponse(json.dumps({'success': False}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||
|
||||
# 2 views for anonymous share:
|
||||
# - anonymous_share records share infomation to db and sends the mail
|
||||
# - anonymous_share_confirm checks the link use clicked and
|
||||
|
Loading…
Reference in New Issue
Block a user