1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-21 11:27:18 +00:00

force change password after batch add user

This commit is contained in:
lian
2017-02-07 17:45:36 +08:00
parent bd054efe7f
commit 287257dd7c
2 changed files with 56 additions and 0 deletions

View File

@@ -1868,6 +1868,9 @@ def batch_add_user(request):
User.objects.create_user(username, password, is_staff=False,
is_active=True)
if config.FORCE_PASSWORD_CHANGE:
UserOptions.objects.set_force_passwd_change(username)
if nickname:
Profile.objects.add_or_update(username, nickname, '')
if department:

View File

@@ -10,6 +10,8 @@ from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE,
from seahub.test_utils import BaseTestCase
from seahub.utils.ms_excel import write_xls as real_write_xls
from constance import config
from seaserv import ccnet_threaded_rpc
class UserToggleStatusTest(BaseTestCase):
@@ -161,6 +163,7 @@ class SysUserAdminExportExcelTest(BaseTestCase):
class BatchAddUserTest(BaseTestCase):
def setUp(self):
self.clear_cache()
self.login_as(self.admin)
self.new_users = []
@@ -191,6 +194,56 @@ class BatchAddUserTest(BaseTestCase):
for e in self.new_users:
assert User.objects.get(e) is not None
def test_can_batch_add_when_pwd_change_required(self):
config.FORCE_PASSWORD_CHANGE = 1
for e in self.new_users:
assert len(UserOptions.objects.filter(
email=e, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0
for e in self.new_users:
try:
r = User.objects.get(e)
except User.DoesNotExist:
r = None
assert r is None
with open(self.csv_file) as f:
resp = self.client.post(reverse('batch_add_user'), {
'file': f
})
self.assertEqual(302, resp.status_code)
assert 'Import succeeded' in parse_cookie(resp.cookies)['messages']
for e in self.new_users:
assert User.objects.get(e) is not None
assert UserOptions.objects.passwd_change_required(e)
def test_can_batch_add_when_pwd_change_not_required(self):
config.FORCE_PASSWORD_CHANGE = 0
for e in self.new_users:
assert len(UserOptions.objects.filter(
email=e, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0
for e in self.new_users:
try:
r = User.objects.get(e)
except User.DoesNotExist:
r = None
assert r is None
with open(self.csv_file) as f:
resp = self.client.post(reverse('batch_add_user'), {
'file': f
})
self.assertEqual(302, resp.status_code)
assert 'Import succeeded' in parse_cookie(resp.cookies)['messages']
for e in self.new_users:
assert User.objects.get(e) is not None
assert not UserOptions.objects.passwd_change_required(e)
@patch('seahub.views.sysadmin.user_number_over_limit')
def test_can_not_batch_add_if_user_over_limit(self, mock_user_number_over_limit):