mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-02 07:47:32 +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.is_active = object.is_active;
|
||||
this.is_staff = object.is_staff;
|
||||
this.reference_id = object.reference_id;
|
||||
this.department = object.department;
|
||||
this.quota_total = object.quota_total;
|
||||
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.repo import normalize_repo_status_code
|
||||
from seahub.utils.ccnet_db import CcnetDB
|
||||
from seahub.constants import DEFAULT_ADMIN
|
||||
from seahub.constants import DEFAULT_ADMIN, DEFAULT_ORG
|
||||
from seahub.role_permissions.models import AdminRole
|
||||
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,
|
||||
nickname, login_id, contact_email, reference_id,
|
||||
nickname, login_id, contact_email,
|
||||
quota_total_mb, institution_name,
|
||||
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
|
||||
if is_active is not None:
|
||||
user.is_active = is_active
|
||||
if is_active == False:
|
||||
if not is_active:
|
||||
# del tokens and personal repo api tokens (not department)
|
||||
from seahub.utils import inactive_user
|
||||
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)
|
||||
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:
|
||||
Profile.objects.add_or_update(email, institution=institution_name)
|
||||
if institution_name == '':
|
||||
@ -445,7 +437,6 @@ def get_user_info(email):
|
||||
|
||||
info['is_staff'] = user.is_staff
|
||||
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)
|
||||
try:
|
||||
@ -591,7 +582,7 @@ class AdminUsers(APIView):
|
||||
users = [u for u in users if u.is_active]
|
||||
elif is_active == '0':
|
||||
users = [u for u in users if not u.is_active]
|
||||
|
||||
|
||||
if role:
|
||||
users = [u for u in users if get_user_role(u) == role]
|
||||
|
||||
@ -1335,14 +1326,6 @@ class AdminUser(APIView):
|
||||
|
||||
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)
|
||||
if quota_total_mb:
|
||||
try:
|
||||
@ -1422,7 +1405,6 @@ class AdminUser(APIView):
|
||||
nickname=name,
|
||||
login_id=login_id,
|
||||
contact_email=contact_email,
|
||||
reference_id=reference_id,
|
||||
quota_total_mb=quota_total_mb,
|
||||
institution_name=institution,
|
||||
upload_rate_limit=upload_rate_limit,
|
||||
@ -2150,12 +2132,12 @@ class AdminUserConvertToTeamView(APIView):
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
permission_classes = (IsAdminUser,)
|
||||
throttle_classes = (UserRateThrottle,)
|
||||
|
||||
|
||||
def post(self, request):
|
||||
username = request.data.get('email')
|
||||
if not username:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'email invalid.')
|
||||
|
||||
|
||||
# resource check
|
||||
try:
|
||||
user = User.objects.get(email=username)
|
||||
@ -2183,7 +2165,7 @@ class AdminUserConvertToTeamView(APIView):
|
||||
else:
|
||||
nickname_characters.append(character)
|
||||
org_name = ''.join(nickname_characters)
|
||||
|
||||
|
||||
try:
|
||||
# 1. Create a new org, and add the user(username) to org as a team admin
|
||||
# by ccnet_api.create_org
|
||||
@ -2200,5 +2182,5 @@ class AdminUserConvertToTeamView(APIView):
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
|
||||
return Response({'success': True})
|
||||
|
@ -293,7 +293,6 @@ class UserManager(object):
|
||||
user.org = emailuser.org
|
||||
user.source = emailuser.source
|
||||
user.role = emailuser.role
|
||||
user.reference_id = emailuser.reference_id
|
||||
|
||||
if user.is_staff:
|
||||
try:
|
||||
@ -330,7 +329,6 @@ class UserManager(object):
|
||||
user.org = emailuser.org
|
||||
user.source = emailuser.source
|
||||
user.role = emailuser.role
|
||||
user.reference_id = emailuser.reference_id
|
||||
|
||||
if user.is_staff:
|
||||
try:
|
||||
|
@ -341,50 +341,6 @@ class AdminUserTest(BaseTestCase):
|
||||
json_resp = json.loads(resp.content)
|
||||
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):
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
from mock import patch
|
||||
from seaserv import ccnet_api
|
||||
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.api2.serializers import AuthTokenSerializer
|
||||
from seahub.profile.models import Profile
|
||||
|
||||
|
||||
class AuthTokenSerializerTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
||||
Profile.objects.add_or_update(self.user.username,
|
||||
login_id='user_login_id',
|
||||
contact_email='contact@test.com')
|
||||
|
||||
ccnet_api.set_reference_id(self.user.username, 'another_email@test.com')
|
||||
|
||||
def assertSuccess(self, s):
|
||||
assert s.is_valid() is True
|
||||
assert s.errors == {}
|
||||
|
@ -1,19 +1,16 @@
|
||||
from seaserv import ccnet_api
|
||||
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.auth.forms import AuthenticationForm
|
||||
from seahub.profile.models import Profile
|
||||
|
||||
|
||||
class AuthenticationFormTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.inactive_user = self.create_user('inactive@test.com', is_active=False)
|
||||
Profile.objects.add_or_update(self.user.username,
|
||||
login_id='user_login_id',
|
||||
contact_email='contact@test.com')
|
||||
|
||||
ccnet_api.set_reference_id(self.user.username, 'another_email@test.com')
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_user(self.inactive_user.username)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user