-
Notifications
You must be signed in to change notification settings - Fork 28
/
config.py
86 lines (72 loc) · 2.35 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 TU Wien.
# Copyright (C) 2022 CERN.
#
# Invenio-Users-Resources is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.
"""Users service configuration."""
from invenio_records_resources.services import (
RecordServiceConfig,
SearchOptions,
pagination_links,
)
from invenio_records_resources.services.records.params import QueryStrParam, SortParam
from invenio_records_resources.services.records.queryparser import (
QueryParser,
SearchFieldTransformer,
)
from ...records.api import UserAggregate
from ..common import Link
from ..params import FixedPagination
from ..permissions import UsersPermissionPolicy
from ..schemas import UserSchema
from .results import UserItem, UserList
class UserSearchOptions(SearchOptions):
"""Search options."""
pagination_options = {
"default_results_per_page": 10,
"default_max_results": 10,
}
query_parser_cls = QueryParser.factory(
fields=["username^2", "email^2", "profile.full_name^3", "profile.affiliations"],
tree_transformer_factory=SearchFieldTransformer.factory(
mapping={
"affiliation": "profile.affiliations",
"affiliations": "profile.affiliations",
"email": "email",
"full_name": "profile.full_name",
"fullname": "profile.full_name",
"name": "profile.full_name",
"username": "username",
}
),
)
params_interpreters_cls = [
QueryStrParam,
SortParam,
FixedPagination,
]
class UsersServiceConfig(RecordServiceConfig):
"""Requests service configuration."""
# common configuration
permission_policy_cls = UsersPermissionPolicy
result_item_cls = UserItem
result_list_cls = UserList
search = UserSearchOptions
# specific configuration
service_id = "users"
record_cls = UserAggregate
schema = UserSchema
indexer_queue_name = "users"
index_dumper = None
# links configuration
links_item = {
"self": Link("{+api}/users/{id}"),
"avatar": Link("{+api}/users/{id}/avatar.svg"),
}
links_search = pagination_links("{+api}/users{?args*}")
components = [
# order of components are important!
]