mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-28 03:10:45 +00:00
Merge pull request #904 from haiwen/userinfo-groups
[user admin] add "groups" tab at user info page
This commit is contained in:
commit
8b55b2ffaf
@ -71,6 +71,7 @@
|
||||
<li class="tab"><a href="#owned" class="a">{% trans "Owned Libs" %}</a></li>
|
||||
<li class="tab"><a href="#shared" class="a">{% trans "Shared Libs" %}</a></li>
|
||||
<li class="tab"><a href="#shared-links" class="a">{% trans "Shared Links" %}</a></li>
|
||||
<li class="tab"><a href="#groups" class="a">{% trans "Groups" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -111,7 +112,9 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>{% trans "None" %}</p>
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "This user has not created any libraries" %}</h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@ -147,7 +150,9 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>{% trans "None" %}</p>
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "This user has no shared libraries" %}</h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@ -193,7 +198,34 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>{% trans "None" %}</p>
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "This user has not created any shared links" %}</h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="groups">
|
||||
{% if personal_groups %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="30%">{% trans "Name" %}</th>
|
||||
<th width="30%">{% trans "Role" %}</th>
|
||||
<th width="25%">{% trans "Create At" %}</th>
|
||||
<th width="15%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
{% for group in personal_groups %}
|
||||
<tr>
|
||||
<td><a href="{% url 'sys_admin_group_info' group.id %}">{{ group.group_name }}</a></td>
|
||||
<td>{{ group.role }}</td>
|
||||
<td>{{ group.timestamp|tsstr_sec }}</td>
|
||||
<td><a href="#" data-url="{% url 'group_remove' group.id %}" data-target="{{ group.group_name }}" class="rm-grp op vh">{% trans "Delete" %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "This user has not created or joined any groups" %}</h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -273,5 +305,10 @@ $('#set-quota-form .submit').click(function() {
|
||||
});
|
||||
return false;
|
||||
});
|
||||
addConfirmTo($('.rm-grp'), {
|
||||
'title': "{% trans "Delete Group" %}",
|
||||
'con': "{% trans "Are you sure you want to delete %s ?" %}",
|
||||
'post': true
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@ -907,6 +907,26 @@ def user_info(request, email):
|
||||
p_uploadlinks.sort(key=lambda x: x.view_cnt, reverse=True)
|
||||
user_shared_links += p_uploadlinks
|
||||
|
||||
try:
|
||||
personal_groups = seaserv.get_personal_groups_by_user(email)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
personal_groups = []
|
||||
|
||||
for g in personal_groups:
|
||||
try:
|
||||
is_group_staff = seaserv.check_group_staff(g.id, email)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
is_group_staff = False
|
||||
|
||||
if email == g.creator_name:
|
||||
g.role = _('Owner')
|
||||
elif is_group_staff:
|
||||
g.role = _('Admin')
|
||||
else:
|
||||
g.role = _('Member')
|
||||
|
||||
return render_to_response(
|
||||
'sysadmin/userinfo.html', {
|
||||
'owned_repos': owned_repos,
|
||||
@ -922,6 +942,7 @@ def user_info(request, email):
|
||||
'org_name': org_name,
|
||||
'user_shared_links': user_shared_links,
|
||||
'enable_sys_admin_view_repo': ENABLE_SYS_ADMIN_VIEW_REPO,
|
||||
'personal_groups': personal_groups,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required_ajax
|
||||
|
@ -1,12 +1,16 @@
|
||||
import os
|
||||
from mock import patch
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http.cookie import parse_cookie
|
||||
|
||||
from tests.common.utils import randstring
|
||||
|
||||
from seahub.base.accounts import User
|
||||
from seahub.utils.ms_excel import write_xls as real_write_xls
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.share.models import FileShare
|
||||
|
||||
from seaserv import ccnet_threaded_rpc
|
||||
from seaserv import ccnet_threaded_rpc, seafile_api
|
||||
|
||||
class UserToggleStatusTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
@ -169,3 +173,127 @@ class SysUserAdminExportExcelTest(BaseTestCase):
|
||||
resp = self.client.get(reverse('sys_useradmin_export_excel'))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
assert 'application/ms-excel' in resp._headers['content-type']
|
||||
|
||||
|
||||
class UserInfoTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
self.login_as(self.admin)
|
||||
|
||||
# create group for admin user
|
||||
self.admin_group_1_name = randstring(6)
|
||||
self.admin_group_1_id = ccnet_threaded_rpc.create_group(self.admin_group_1_name,
|
||||
self.admin.email)
|
||||
|
||||
# create another group for admin user
|
||||
self.admin_group_2_name = randstring(6)
|
||||
self.admin_group_2_id = ccnet_threaded_rpc.create_group(self.admin_group_2_name,
|
||||
self.admin.email)
|
||||
|
||||
# create repo for admin user
|
||||
self.admin_repo_name = randstring(6)
|
||||
r = seafile_api.get_repo(self.create_repo(name=self.admin_repo_name,
|
||||
desc='', username=self.admin.email, passwd=None))
|
||||
self.admin_repo_id = r.id
|
||||
|
||||
# set common user as staff in admin user's group
|
||||
ccnet_threaded_rpc.group_set_admin(self.admin_group_1_id, self.user.email)
|
||||
|
||||
# add common user to admin user's another group
|
||||
ccnet_threaded_rpc.group_add_member(self.admin_group_2_id,
|
||||
self.admin.email, self.user.email)
|
||||
|
||||
# share admin user's repo to common user
|
||||
seafile_api.share_repo(self.admin_repo_id, self.admin.email,
|
||||
self.user.email, 'rw')
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
# remove common user's repo and group
|
||||
self.remove_group()
|
||||
self.remove_repo()
|
||||
|
||||
# remove admin user's group
|
||||
ccnet_threaded_rpc.remove_group(self.admin_group_1_id, self.admin.email)
|
||||
|
||||
# remove admin user's another group
|
||||
ccnet_threaded_rpc.remove_group(self.admin_group_2_id, self.admin.email)
|
||||
|
||||
# remove amdin user's repo
|
||||
seafile_api.remove_repo(self.admin_repo_id)
|
||||
|
||||
def test_can_render(self):
|
||||
|
||||
resp = self.client.get(reverse('user_info', kwargs={'email': self.user.email}))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed('sysadmin/userinfo.html')
|
||||
self.assertContains(resp, 'id="owned"')
|
||||
self.assertContains(resp, 'id="shared"')
|
||||
self.assertContains(resp, 'id="shared-links"')
|
||||
self.assertContains(resp, 'id="groups"')
|
||||
|
||||
def test_can_list_owned_repos(self):
|
||||
|
||||
repo_id = self.repo.id
|
||||
resp = self.client.get(reverse('user_info', kwargs={'email': self.user.email}))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed('sysadmin/userinfo.html')
|
||||
self.assertContains(resp, repo_id)
|
||||
|
||||
def test_can_list_shared_repos(self):
|
||||
|
||||
resp = self.client.get(reverse('user_info', kwargs={'email': self.user.email}))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed('sysadmin/userinfo.html')
|
||||
self.assertContains(resp, self.admin_repo_name)
|
||||
|
||||
def test_can_list_shared_links(self):
|
||||
|
||||
repo_id = self.repo.id
|
||||
file_path = self.file
|
||||
dir_path = self.folder
|
||||
file_name = os.path.basename(file_path)
|
||||
dir_name = os.path.basename(dir_path)
|
||||
|
||||
# create dir shared link for common user
|
||||
share_info = {
|
||||
'username': self.user.email,
|
||||
'repo_id': repo_id,
|
||||
'path': dir_path,
|
||||
'password': None,
|
||||
'expire_date': None,
|
||||
}
|
||||
FileShare.objects.create_dir_link(**share_info)
|
||||
|
||||
# create file shared link for common user
|
||||
share_info = {
|
||||
'username': self.user.email,
|
||||
'repo_id': repo_id,
|
||||
'path': file_path,
|
||||
'password': None,
|
||||
'expire_date': None,
|
||||
}
|
||||
FileShare.objects.create_file_link(**share_info)
|
||||
|
||||
resp = self.client.get(reverse('user_info', kwargs={'email': self.user.email}))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed('sysadmin/userinfo.html')
|
||||
self.assertContains(resp, dir_name)
|
||||
self.assertContains(resp, file_name)
|
||||
|
||||
def test_can_list_groups(self):
|
||||
|
||||
group_name = self.group.group_name
|
||||
resp = self.client.get(reverse('user_info', kwargs={'email': self.user.email}))
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertTemplateUsed('sysadmin/userinfo.html')
|
||||
|
||||
self.assertContains(resp, 'Owned')
|
||||
self.assertContains(resp, group_name)
|
||||
|
||||
self.assertContains(resp, 'Admin')
|
||||
self.assertContains(resp, self.admin_group_1_name)
|
||||
|
||||
self.assertContains(resp, 'Member')
|
||||
self.assertContains(resp, self.admin_group_2_name)
|
||||
|
Loading…
Reference in New Issue
Block a user