Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add desk members api to fetch users for specific desk #2733

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion apps/desks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from superdesk.activity import add_activity, ACTIVITY_UPDATE
from superdesk.metadata.item import FAMILY_ID, ITEM_STATE, CONTENT_STATE
from eve.utils import ParsedRequest
from superdesk.utils import ListCursor
from flask_babel import _, lazy_gettext


Expand Down Expand Up @@ -103,6 +102,9 @@ def init_app(app) -> None:
endpoint_name = "desk_overview"
service = OverviewService(endpoint_name, backend=superdesk.get_backend())
OverviewResource(endpoint_name, app=app, service=service)
endpoint_name = "desk_users"
service = DeskUsersService(endpoint_name, backend=superdesk.get_backend())
DeskUsersResource(endpoint_name, app=app, service=service)


superdesk.privilege(
Expand Down Expand Up @@ -371,6 +373,42 @@ def get_by_user(self, user_id):
return list(self.get(req=None, lookup={"user_id": user_id}))


class DeskUsersResource(Resource):
url = 'desks/<regex("[a-f0-9]{24}"):desk_id>/users'
resource_title = "desk_users"
datasource = {
"source": "users",
"default_sort": [("username", 1)],
"projection": {
"username": 1,
"first_name": 1,
"last_name": 1,
"display_name": 1,
"email": 1,
"picture_url": 1,
"avatar": 1,
"avatar_renditions": 1,
"role": 1,
"last_activity_at": 1,
"sign_off": 1,
},
}
resource_methods = ["GET"]


class DeskUsersService(BaseService):
def get(self, req, lookup):
desk_id = lookup.pop("desk_id", None)
desks_service = superdesk.get_resource_service("desks")
if desk_id:
desk = desks_service.find_one(req=None, _id=ObjectId(desk_id))
if desk and desk.get("members"):
lookup["_id"] = {"$in": [member["user"] for member in desk.get("members", [])]}
else:
lookup["_id"] = "" # return empty result
return super().get(req, lookup)


class SluglineDesksResource(Resource):
url = 'desks/<regex("[a-f0-9]{24}"):desk_id>/sluglines'
datasource = {
Expand Down
23 changes: 22 additions & 1 deletion features/desks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -788,4 +788,25 @@ Feature: Desks
"template_desks": ["#desks._id#"]
}
"""


@auth
Scenario: Desk members resource
Given "users"
"""
[
{"username": "foo", "email": "[email protected]", "display_name": "foo"},
{"username": "bar", "email": "[email protected]", "display_name": "bar"}
]
"""
And "desks"
"""
[
{"name": "Finance", "members": []},
{"name": "Sports", "members": [{"user": "#users._id#"}]}
]
"""
When we get "/desks/#desks._id#/users"
Then we get list with 1 items
"""
{"_items": [{"username": "bar", "display_name": "bar"}]}
"""
Loading