diff --git a/server/cp/mgmt_api/users.py b/server/cp/mgmt_api/users.py index c7fa3b9..c12f6d0 100644 --- a/server/cp/mgmt_api/users.py +++ b/server/cp/mgmt_api/users.py @@ -2,9 +2,11 @@ import superdesk from bson.objectid import ObjectId +from pymongo.collation import Collation from flask import current_app as app from newsroom.users.users import UsersResource, UsersService from superdesk.errors import SuperdeskApiError +from typing_extensions import override from cp.mgmt_api.utils import validate_product_refs @@ -15,6 +17,7 @@ class CPUsersResource(newsroom.Resource): datasource = UsersResource.datasource.copy() item_methods = ["GET", "PATCH", "PUT", "DELETE"] resource_methods = ["GET", "POST"] + collation = False def init_app(app): @@ -22,10 +25,12 @@ def init_app(app): class CPUsersService(UsersService): + @override def check_permissions(self, doc, updates=None): """Avoid testing if user has permissions.""" pass + @override def on_create(self, docs): super().on_create(docs) for doc in docs: @@ -41,6 +46,14 @@ def on_create(self, docs): if doc.get("products"): validate_product_refs(doc["products"]) + @override def on_update(self, updates, original): if updates.get("products"): validate_product_refs(updates["products"]) + + @override + def get(self, req, lookup): + """""" + cursor = super().get(req, lookup) + cursor.collation(Collation(locale='en', strength=1)) + return cursor diff --git a/server/features/mgmt_api_users.feature b/server/features/mgmt_api_users.feature index 4862600..91f811b 100644 --- a/server/features/mgmt_api_users.feature +++ b/server/features/mgmt_api_users.feature @@ -206,3 +206,22 @@ Feature: Management API - Users } """ Then we get response code 201 + + Scenario: Search case insensitive + Given "users" + """ + [ + { + "first_name": "John", + "last_name": "Cena", + "email": "JohnCena@wwe.com", + "user_type": "administrator" + } + ] + """ + + When we get "/users?where={"email": "johncena@wwe.com"}" + Then we get list with 1 items + + When we get "/users?where={"email": "JohnCena@wwe.com"}" + Then we get list with 1 items \ No newline at end of file