Skip to content

Commit

Permalink
implement case insensitive user search (#193)
Browse files Browse the repository at this point in the history
CPCN-532
  • Loading branch information
petrjasek authored Oct 14, 2024
1 parent 5fe4e70 commit c23fc41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/cp/mgmt_api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,17 +17,20 @@ class CPUsersResource(newsroom.Resource):
datasource = UsersResource.datasource.copy()
item_methods = ["GET", "PATCH", "PUT", "DELETE"]
resource_methods = ["GET", "POST"]
collation = False


def init_app(app):
superdesk.register_resource('users', CPUsersResource, CPUsersService, _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:
Expand All @@ -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
19 changes: 19 additions & 0 deletions server/features/mgmt_api_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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

0 comments on commit c23fc41

Please sign in to comment.