mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-15 05:33:38 +00:00
remove reference id (#6768)
This commit is contained in:
parent
f10c7b111c
commit
fa56751ab9
@ -9,7 +9,6 @@ class SysAdminUser {
|
|||||||
this.create_time = object.create_time;
|
this.create_time = object.create_time;
|
||||||
this.is_active = object.is_active;
|
this.is_active = object.is_active;
|
||||||
this.is_staff = object.is_staff;
|
this.is_staff = object.is_staff;
|
||||||
this.reference_id = object.reference_id;
|
|
||||||
this.department = object.department;
|
this.department = object.department;
|
||||||
this.quota_total = object.quota_total;
|
this.quota_total = object.quota_total;
|
||||||
this.quota_usage = object.quota_usage;
|
this.quota_usage = object.quota_usage;
|
||||||
|
@ -51,7 +51,6 @@ from seahub.utils.timeutils import timestamp_to_isoformat_timestr, \
|
|||||||
from seahub.utils.user_permissions import get_user_role
|
from seahub.utils.user_permissions import get_user_role
|
||||||
from seahub.utils.repo import normalize_repo_status_code
|
from seahub.utils.repo import normalize_repo_status_code
|
||||||
from seahub.utils.ccnet_db import CcnetDB
|
from seahub.utils.ccnet_db import CcnetDB
|
||||||
from seahub.constants import DEFAULT_ADMIN
|
|
||||||
from seahub.constants import DEFAULT_ADMIN, DEFAULT_ORG
|
from seahub.constants import DEFAULT_ADMIN, DEFAULT_ORG
|
||||||
from seahub.role_permissions.models import AdminRole
|
from seahub.role_permissions.models import AdminRole
|
||||||
from seahub.role_permissions.utils import get_available_roles
|
from seahub.role_permissions.utils import get_available_roles
|
||||||
@ -357,7 +356,7 @@ def create_user_info(request, email, role, nickname,
|
|||||||
|
|
||||||
|
|
||||||
def update_user_info(request, user, password, is_active, is_staff, role,
|
def update_user_info(request, user, password, is_active, is_staff, role,
|
||||||
nickname, login_id, contact_email, reference_id,
|
nickname, login_id, contact_email,
|
||||||
quota_total_mb, institution_name,
|
quota_total_mb, institution_name,
|
||||||
upload_rate_limit, download_rate_limit):
|
upload_rate_limit, download_rate_limit):
|
||||||
|
|
||||||
@ -366,7 +365,7 @@ def update_user_info(request, user, password, is_active, is_staff, role,
|
|||||||
# update basic user info
|
# update basic user info
|
||||||
if is_active is not None:
|
if is_active is not None:
|
||||||
user.is_active = is_active
|
user.is_active = is_active
|
||||||
if is_active == False:
|
if not is_active:
|
||||||
# del tokens and personal repo api tokens (not department)
|
# del tokens and personal repo api tokens (not department)
|
||||||
from seahub.utils import inactive_user
|
from seahub.utils import inactive_user
|
||||||
try:
|
try:
|
||||||
@ -400,13 +399,6 @@ def update_user_info(request, user, password, is_active, is_staff, role,
|
|||||||
key = normalize_cache_key(email, CONTACT_CACHE_PREFIX)
|
key = normalize_cache_key(email, CONTACT_CACHE_PREFIX)
|
||||||
cache.set(key, contact_email, CONTACT_CACHE_TIMEOUT)
|
cache.set(key, contact_email, CONTACT_CACHE_TIMEOUT)
|
||||||
|
|
||||||
if reference_id is not None:
|
|
||||||
if reference_id.strip():
|
|
||||||
ccnet_api.set_reference_id(email, reference_id.strip())
|
|
||||||
else:
|
|
||||||
# remove reference id
|
|
||||||
ccnet_api.set_reference_id(email, None)
|
|
||||||
|
|
||||||
if institution_name is not None:
|
if institution_name is not None:
|
||||||
Profile.objects.add_or_update(email, institution=institution_name)
|
Profile.objects.add_or_update(email, institution=institution_name)
|
||||||
if institution_name == '':
|
if institution_name == '':
|
||||||
@ -445,7 +437,6 @@ def get_user_info(email):
|
|||||||
|
|
||||||
info['is_staff'] = user.is_staff
|
info['is_staff'] = user.is_staff
|
||||||
info['is_active'] = user.is_active
|
info['is_active'] = user.is_active
|
||||||
info['reference_id'] = user.reference_id if user.reference_id else ''
|
|
||||||
|
|
||||||
orgs = ccnet_api.get_orgs_by_user(email)
|
orgs = ccnet_api.get_orgs_by_user(email)
|
||||||
try:
|
try:
|
||||||
@ -1335,14 +1326,6 @@ class AdminUser(APIView):
|
|||||||
|
|
||||||
password = request.data.get("password")
|
password = request.data.get("password")
|
||||||
|
|
||||||
reference_id = request.data.get("reference_id", None)
|
|
||||||
if reference_id:
|
|
||||||
if ' ' in reference_id:
|
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Reference ID can not contain spaces.')
|
|
||||||
primary_id = ccnet_api.get_primary_id(reference_id)
|
|
||||||
if primary_id:
|
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Reference ID %s already exists.' % reference_id)
|
|
||||||
|
|
||||||
quota_total_mb = request.data.get("quota_total", None)
|
quota_total_mb = request.data.get("quota_total", None)
|
||||||
if quota_total_mb:
|
if quota_total_mb:
|
||||||
try:
|
try:
|
||||||
@ -1422,7 +1405,6 @@ class AdminUser(APIView):
|
|||||||
nickname=name,
|
nickname=name,
|
||||||
login_id=login_id,
|
login_id=login_id,
|
||||||
contact_email=contact_email,
|
contact_email=contact_email,
|
||||||
reference_id=reference_id,
|
|
||||||
quota_total_mb=quota_total_mb,
|
quota_total_mb=quota_total_mb,
|
||||||
institution_name=institution,
|
institution_name=institution,
|
||||||
upload_rate_limit=upload_rate_limit,
|
upload_rate_limit=upload_rate_limit,
|
||||||
|
@ -293,7 +293,6 @@ class UserManager(object):
|
|||||||
user.org = emailuser.org
|
user.org = emailuser.org
|
||||||
user.source = emailuser.source
|
user.source = emailuser.source
|
||||||
user.role = emailuser.role
|
user.role = emailuser.role
|
||||||
user.reference_id = emailuser.reference_id
|
|
||||||
|
|
||||||
if user.is_staff:
|
if user.is_staff:
|
||||||
try:
|
try:
|
||||||
@ -330,7 +329,6 @@ class UserManager(object):
|
|||||||
user.org = emailuser.org
|
user.org = emailuser.org
|
||||||
user.source = emailuser.source
|
user.source = emailuser.source
|
||||||
user.role = emailuser.role
|
user.role = emailuser.role
|
||||||
user.reference_id = emailuser.reference_id
|
|
||||||
|
|
||||||
if user.is_staff:
|
if user.is_staff:
|
||||||
try:
|
try:
|
||||||
|
@ -341,50 +341,6 @@ class AdminUserTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['login_id'] == ''
|
assert json_resp['login_id'] == ''
|
||||||
|
|
||||||
def test_update_reference_id(self):
|
|
||||||
self.login_as(self.admin)
|
|
||||||
|
|
||||||
data = {"email": self.tmp_email, "reference_id": ''}
|
|
||||||
resp = self.client.put(self.url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
json_resp = json.loads(resp.content)
|
|
||||||
assert json_resp['reference_id'] == ''
|
|
||||||
|
|
||||||
data = {"email": self.tmp_email, "reference_id": 'rf@id.com'}
|
|
||||||
resp = self.client.put(self.url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
json_resp = json.loads(resp.content)
|
|
||||||
assert json_resp['reference_id'] == 'rf@id.com'
|
|
||||||
|
|
||||||
data = {"email": self.tmp_email, "reference_id": ''}
|
|
||||||
resp = self.client.put(self.url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
json_resp = json.loads(resp.content)
|
|
||||||
|
|
||||||
def test_put_same_reference_id(self):
|
|
||||||
self.login_as(self.admin)
|
|
||||||
|
|
||||||
admin_url = reverse('api-v2.1-admin-user', args=[self.admin.email])
|
|
||||||
data = {"email": self.admin.email, "reference_id": 'test@email.com'}
|
|
||||||
resp = self.client.put(admin_url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
json_resp = json.loads(resp.content)
|
|
||||||
assert resp.status_code == 200
|
|
||||||
assert json_resp['reference_id'] == 'test@email.com'
|
|
||||||
|
|
||||||
data = {"email": self.tmp_email, "reference_id": 'test@email.com'}
|
|
||||||
resp = self.client.put(self.url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
json_resp = json.loads(resp.content)
|
|
||||||
assert resp.status_code == 400
|
|
||||||
|
|
||||||
data = {"email": self.admin.email, "reference_id": ''}
|
|
||||||
resp = self.client.put(admin_url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
data = {"email": self.tmp_email, "reference_id": ''}
|
|
||||||
resp = self.client.put(self.url, json.dumps(data),
|
|
||||||
'application/json')
|
|
||||||
|
|
||||||
|
|
||||||
class AdminUserShareLinksTest(BaseTestCase):
|
class AdminUserShareLinksTest(BaseTestCase):
|
||||||
|
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
from mock import patch
|
from mock import patch
|
||||||
from seaserv import ccnet_api
|
|
||||||
|
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
from seahub.api2.serializers import AuthTokenSerializer
|
from seahub.api2.serializers import AuthTokenSerializer
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
|
|
||||||
|
|
||||||
class AuthTokenSerializerTest(BaseTestCase):
|
class AuthTokenSerializerTest(BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
||||||
Profile.objects.add_or_update(self.user.username,
|
Profile.objects.add_or_update(self.user.username,
|
||||||
login_id='user_login_id',
|
login_id='user_login_id',
|
||||||
contact_email='contact@test.com')
|
contact_email='contact@test.com')
|
||||||
|
|
||||||
ccnet_api.set_reference_id(self.user.username, 'another_email@test.com')
|
|
||||||
|
|
||||||
def assertSuccess(self, s):
|
def assertSuccess(self, s):
|
||||||
assert s.is_valid() is True
|
assert s.is_valid() is True
|
||||||
assert s.errors == {}
|
assert s.errors == {}
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
from seaserv import ccnet_api
|
|
||||||
|
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
from seahub.auth.forms import AuthenticationForm
|
from seahub.auth.forms import AuthenticationForm
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
|
|
||||||
|
|
||||||
class AuthenticationFormTest(BaseTestCase):
|
class AuthenticationFormTest(BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
||||||
Profile.objects.add_or_update(self.user.username,
|
Profile.objects.add_or_update(self.user.username,
|
||||||
login_id='user_login_id',
|
login_id='user_login_id',
|
||||||
contact_email='contact@test.com')
|
contact_email='contact@test.com')
|
||||||
|
|
||||||
ccnet_api.set_reference_id(self.user.username, 'another_email@test.com')
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_user(self.inactive_user.username)
|
self.remove_user(self.inactive_user.username)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user