Skip to content

Commit

Permalink
schemas: move user notifications schemas from config to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
rekt-hard authored and kpsherva committed Jun 30, 2023
1 parent a856acf commit 70d7e7b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
33 changes: 5 additions & 28 deletions invenio_app_rdm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
from invenio_stats.contrib.event_builders import build_file_unique_id
from invenio_stats.processors import EventsIndexer, anonymize_user, flag_robots
from invenio_stats.queries import TermsQuery
from invenio_users_resources.services.schemas import (
NotificationPreferences,
UserPreferencesSchema,
UserSchema,
)
from invenio_vocabularies.config import (
VOCABULARIES_DATASTREAM_READERS,
VOCABULARIES_DATASTREAM_TRANSFORMERS,
Expand All @@ -85,9 +80,9 @@
from invenio_vocabularies.contrib.names.datastreams import (
VOCABULARIES_DATASTREAM_WRITERS as NAMES_WRITERS,
)
from marshmallow import fields

from invenio_app_rdm.theme.views import notification_settings
from .theme.views import notification_settings
from .users.schemas import NotificationsUserSchema, UserPreferencesNotificationsSchema

# TODO: Remove when records-rest is out of communities and files
RECORDS_REST_ENDPOINTS = {}
Expand Down Expand Up @@ -278,12 +273,6 @@ def files_rest_permission_factory(obj, action):
"""


class UserPreferencesNotificationsSchema(UserPreferencesSchema):
"""Schema extending preferences with notification preferences."""

notifications = fields.Nested(NotificationPreferences)


ACCOUNTS_USER_PREFERENCES_SCHEMA = UserPreferencesNotificationsSchema()
"""The schema to use for validation of the user preferences."""

Expand Down Expand Up @@ -1154,26 +1143,14 @@ def github_link_render(record):
]
"""List of entity resolvers used by notification builders."""


class UserPreferencesNotificationsSchema(UserPreferencesSchema):
"""Schema extending preferences with notification preferences for model validation."""

notifications = fields.Nested(NotificationPreferences)
NOTIFICATIONS_SETTINGS_VIEW_FUNCTION = notification_settings
"""View function for notification settings."""


# Invenio-Notifications
# Invenio-Users-Resources
# =================
# See https://github.com/inveniosoftware/invenio-users-resources/blob/master/invenio_users_resources/config.py # noqa


class NotificationsUserSchema(UserSchema):
"""Schema extending preferences with notification preferences for user service."""

preferences = fields.Nested(UserPreferencesNotificationsSchema)


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

NOTIFICATIONS_SETTINGS_VIEW_FUNCTION = notification_settings
"""View function for notification settings."""
28 changes: 28 additions & 0 deletions invenio_app_rdm/users/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""RDM User Schemas."""


from invenio_users_resources.services.schemas import (
NotificationPreferences,
UserPreferencesSchema,
UserSchema,
)
from marshmallow import fields


class UserPreferencesNotificationsSchema(UserPreferencesSchema):
"""Schema extending preferences with notification preferences for model validation."""

notifications = fields.Nested(NotificationPreferences)


class NotificationsUserSchema(UserSchema):
"""Schema extending preferences with notification preferences for user service."""

preferences = fields.Nested(UserPreferencesNotificationsSchema)

0 comments on commit 70d7e7b

Please sign in to comment.