Skip to content

Commit

Permalink
Draft of the user admin
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz committed Jun 21, 2023
1 parent 81b226d commit b4595b0
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 10 deletions.
9 changes: 9 additions & 0 deletions invenio_users_resources/administration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
#
# invenio-administration is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration module for user resources."""
9 changes: 9 additions & 0 deletions invenio_users_resources/administration/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
#
# invenio-administration is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration module for user resources."""
72 changes: 72 additions & 0 deletions invenio_users_resources/administration/views/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
#
# invenio-administration is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration users view module."""
from flask import current_app
from invenio_administration.views.base import (
AdminResourceDetailView,
AdminResourceListView,
)
from invenio_i18n import lazy_gettext as _


class UsersListView(AdminResourceListView):
"""Configuration for users sets list view."""

api_endpoint = "/users"
name = "users"
resource_config = "users_resource"
title = "User management"
menu_label = "Users"
category = "User management"
pid_path = "id"
icon = "exchange"

display_search = True
display_delete = False
display_edit = False
display_create = False

item_field_list = {
"username": {"text": _("Username"), "order": 1},
"email": {"text": _("Email"), "order": 2},
"created": {"text": _("Created"), "order": 4},
"updated": {"text": _("Updated"), "order": 5},
}

search_config_name = "USERS_RESOURCES_SEARCH"
search_sort_config_name = "USERS_RESOURCES_SORT_OPTIONS"

@staticmethod
def disabled():
"""Disable the view on demand."""
return current_app.config["USERS_RESOURCES_ADMINISTRATION_DISABLED"]


class UsersDetailView(AdminResourceDetailView):
"""Configuration for users sets detail view."""

url = "/users/<pid_value>"
api_endpoint = "/users/"
search_request_headers = {"Accept": "application/json"}
name = "User details"
resource_config = "users_resource"
title = "User Details"
display_delete = False
display_edit = False

pid_path = "username"

item_field_list = {
"username": {"text": _("Username"), "order": 1},
"email": {"text": _("Email"), "order": 2},
"created": {"text": _("Created"), "order": 3},
"updated": {"text": _("Updated"), "order": 4},
"active": {"bool": _("Active"), "order": 5},
"confirmed": {"bool": _("Confirmed"), "order": 6},
}
25 changes: 25 additions & 0 deletions invenio_users_resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

"""Invenio module providing management APIs for users and roles/groups."""

from invenio_i18n import lazy_gettext as _

from invenio_users_resources.services.schemas import UserSchema

Expand Down Expand Up @@ -44,3 +45,27 @@

USERS_RESOURCES_SERVICE_SCHEMA = UserSchema
"""Schema used by the users service."""

USERS_RESOURCES_SEARCH = {
"facets": [],
"sort": [
"email",
"username",
],
}
"""User search configuration (i.e list of banners)"""

USERS_RESOURCES_SORT_OPTIONS = {
"username": dict(
title=_("Username"),
fields=["username"],
),
"email": dict(
title=_("Email"),
fields=["email"],
),
}
"""Definitions of available Users sort options. """

USERS_RESOURCES_ADMINISTRATION_DISABLED = True
"""Disable the user administration"""
3 changes: 2 additions & 1 deletion invenio_users_resources/services/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class UserSchema(BaseRecordSchema, FieldPermissionsMixin):
# NOTE: API should only deliver users that are active & confirmed
active = fields.Boolean()
confirmed = fields.Boolean(dump_only=True)
is_current_user = fields.Method("is_self", dump_only=True)
# psaiz: I don't understand why I have to comment this out :(
# is_current_user = fields.Method("is_self", dump_only=True)

email = fields.String()
username = fields.String()
Expand Down
25 changes: 16 additions & 9 deletions invenio_users_resources/services/users/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

"""Users service configuration."""

from invenio_records_resources.services import (
RecordServiceConfig,
SearchOptions,
pagination_links,
from invenio_records_resources.services import RecordServiceConfig, pagination_links


from invenio_records_resources.services.base.config import (
ConfiguratorMixin,
FromConfig,
FromConfigSearchOptions,
SearchOptionsMixin,
)
from invenio_records_resources.services.base.config import ConfiguratorMixin, FromConfig
from invenio_records_resources.services.records.config import SearchOptions
from invenio_records_resources.services.records.params import QueryStrParam, SortParam
from invenio_records_resources.services.records.queryparser import (
QueryParser,
Expand All @@ -29,14 +33,13 @@
from .results import UserItem, UserList


class UserSearchOptions(SearchOptions):
class UserSearchOptions(SearchOptions, SearchOptionsMixin):
"""Search options."""

pagination_options = {
"default_results_per_page": 10,
"default_max_results": 10,
}

query_parser_cls = QueryParser.factory(
tree_transformer_cls=SearchFieldTransformer,
fields=["username^2", "email^2", "profile.full_name^3", "profile.affiliations"],
Expand Down Expand Up @@ -64,8 +67,12 @@ class UsersServiceConfig(RecordServiceConfig, ConfiguratorMixin):
permission_policy_cls = UsersPermissionPolicy
result_item_cls = UserItem
result_list_cls = UserList
search = UserSearchOptions

search = FromConfigSearchOptions(
"USERS_RESOURCES_SEARCH",
"USERS_RESOURCES_SORT_OPTIONS",
None,
search_option_cls=UserSearchOptions,
)
# specific configuration
service_id = "users"
record_cls = UserAggregate
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ packages = find:
python_requires = >=3.7
zip_safe = False
install_requires =
invenio-administration>=1.1.0,<2.0.0
invenio-accounts>=3.0.0,<4.0.0
invenio-i18n>=2.0.0
invenio-notifications>=0.1.0,<1.0.0
Expand Down Expand Up @@ -64,6 +65,9 @@ invenio_search.mappings =
invenio_i18n.translations =
messages = invenio_users_resources

invenio_administration.views =
invenio_users_resources_users_list = invenio_users_resources.administration.views.users:UsersListView
invenio_users_resources_users_details = invenio_users_resources.administration.views.users:UsersDetailView
[build_sphinx]
source-dir = docs/
build-dir = docs/_build
Expand Down

0 comments on commit b4595b0

Please sign in to comment.