mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 06:33:48 +00:00
Merge pull request #1782 from haiwen/org-search-user
use ccnet_api.get_org_users_by_url_prefix()
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
@@ -9,8 +10,6 @@ from rest_framework.permissions import IsAuthenticated
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
import seaserv
|
|
||||||
|
|
||||||
from seaserv import ccnet_api
|
from seaserv import ccnet_api
|
||||||
|
|
||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
@@ -26,6 +25,8 @@ from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
|||||||
from seahub.settings import ENABLE_GLOBAL_ADDRESSBOOK, \
|
from seahub.settings import ENABLE_GLOBAL_ADDRESSBOOK, \
|
||||||
ENABLE_SEARCH_FROM_LDAP_DIRECTLY
|
ENABLE_SEARCH_FROM_LDAP_DIRECTLY
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from seahub.settings import CLOUD_MODE
|
from seahub.settings import CLOUD_MODE
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -59,8 +60,12 @@ class SearchUser(APIView):
|
|||||||
|
|
||||||
# get all org users
|
# get all org users
|
||||||
url_prefix = request.user.org.url_prefix
|
url_prefix = request.user.org.url_prefix
|
||||||
# TODO all_org_users = ccnet_api.get_org_users_by_url_prefix(url_prefix, -1, -1)
|
try:
|
||||||
all_org_users = seaserv.get_org_users_by_url_prefix(url_prefix, -1, -1)
|
all_org_users = ccnet_api.get_org_users_by_url_prefix(url_prefix, -1, -1)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
error_msg = 'Internal Server Error'
|
||||||
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
limited_emails = []
|
limited_emails = []
|
||||||
for org_user in all_org_users:
|
for org_user in all_org_users:
|
||||||
@@ -150,17 +155,17 @@ def format_searched_user_result(request, users, size):
|
|||||||
def search_user_from_ccnet(q):
|
def search_user_from_ccnet(q):
|
||||||
users = []
|
users = []
|
||||||
|
|
||||||
db_users = seaserv.ccnet_threaded_rpc.search_emailusers('DB', q, 0, 10)
|
db_users = ccnet_api.search_emailusers('DB', q, 0, 10)
|
||||||
users.extend(db_users)
|
users.extend(db_users)
|
||||||
|
|
||||||
count = len(users)
|
count = len(users)
|
||||||
if count < 10:
|
if count < 10:
|
||||||
ldap_imported_users = seaserv.ccnet_threaded_rpc.search_emailusers('LDAP', q, 0, 10 - count)
|
ldap_imported_users = ccnet_api.search_emailusers('LDAP', q, 0, 10 - count)
|
||||||
users.extend(ldap_imported_users)
|
users.extend(ldap_imported_users)
|
||||||
|
|
||||||
count = len(users)
|
count = len(users)
|
||||||
if count < 10 and ENABLE_SEARCH_FROM_LDAP_DIRECTLY:
|
if count < 10 and ENABLE_SEARCH_FROM_LDAP_DIRECTLY:
|
||||||
all_ldap_users = seaserv.ccnet_threaded_rpc.search_ldapusers(q, 0, 10 - count)
|
all_ldap_users = ccnet_api.search_ldapusers(q, 0, 10 - count)
|
||||||
users.extend(all_ldap_users)
|
users.extend(all_ldap_users)
|
||||||
|
|
||||||
# `users` is already search result, no need search more
|
# `users` is already search result, no need search more
|
||||||
|
Reference in New Issue
Block a user