Skip to content

Commit

Permalink
update rest api user fields (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jan 23, 2025
1 parent 6b2f88e commit fbae1ca
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 48 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Changed
- Replace ``awesome-slugify`` dependency with ``python-slugify`` (#1531, #1547)
- Use ``SODARAPI*`` API view base classes instead of ``CoreAPI*`` (#1401)
- Declare app setting definitions as ``PluginAppSettingDef`` objects (#1456)
- **Filesfolders**
- Upgrade filesfolders REST API version to 2.0 (#1553)
- Remove compability with filesfolders REST API <2.0 (#1553)
- Replace REST API ``SODARUserSerializer`` fields with UUID ``SlugRelatedField`` (#1553)
- **Projectroles**
- Deprecate ``get_user_display_name()``, use ``SODARUser.get_display_name()`` (#1487)
- Deprecate declaring app setting definitions as dict (#1456)
Expand All @@ -52,6 +56,14 @@ Changed
- Move app setting form helpers in ``SODARAppSettingFormMixin`` (#1545)
- Upgrade projectroles REST API version to v1.1 (#836)
- Allow empty ``old_owner_role`` in ``RoleAssignmentOwnerTransferAPIView`` (#836)
- **Sodarcache**
- Upgrade sodarcache REST API version to 2.0 (#1553)
- Remove compability with sodarcache REST API <2.0 (#1553)
- Replace REST API ``SODARUserSerializer`` fields with UUID ``SlugRelatedField`` (#1553)
- **Timeline**
- Upgrade timeline REST API version to 2.0 (#1553)
- Remove compability with timeline REST API <2.0 (#1553)
- Replace REST API ``SODARUserSerializer`` fields with UUID ``SlugRelatedField`` (#1553)
- **Tokens**
- Update UI for site read-only mode (#24)
- **Userprofile**
Expand Down
12 changes: 11 additions & 1 deletion docs/source/app_filesfolders_api_rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ Filesfolders REST API Views

.. autoclass:: HyperLinkListCreateAPIView

.. autoclass:: HyperLinkRetrieveUpdateDestroyAPIView
.. autoclass:: HyperLinkRetrieveUpdateDestroyAPIView


Filesfolders REST API Version Changes
=====================================

v2.0
----

- All views
* Return ``owner`` as UUID instead of ``SODARUserSerializer`` dict
13 changes: 11 additions & 2 deletions docs/source/app_sodarcache_api_rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Sodarcache REST API Versioning
Media Type
``application/vnd.bihealth.sodar-core.sodarcache+json``
Current Version
``1.0``
``2.0``
Accepted Versions
``1.0``
``2.0``
Header Example
``Accept: application/vnd.bihealth.sodar-core.sodarcache+json; version=x.y``

Expand All @@ -32,3 +32,12 @@ Sodarcache REST API Views

.. autoclass:: CacheItemSetAPIView


Sodarcache REST API Version Changes
===================================

v2.0
----

- ``CacheItemRetrieveAPIView``
* Return ``user`` as UUID instead of ``SODARUserSerializer`` dict
10 changes: 10 additions & 0 deletions docs/source/app_timeline_api_rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ Timeline REST API Views
.. autoclass:: SiteTimelineEventListAPIView

.. autoclass:: TimelineEventRetrieveAPIView


Timeline REST API Version Changes
=================================

v2.0
----

- ``TimelineEventRetrieveAPIView``
* Return ``user`` as UUID instead of ``SODARUserSerializer`` dict
26 changes: 24 additions & 2 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ Release Highlights
- Add app setting definition as objects
- Update owner transfer form to allow setting no role for old owner
- Update app settings API
- Upgrade filesfolders REST API version to v2.0
- Upgrade projectroles REST API version to v1.1
- Remove support for features deprecated in v1.0
- Upgrade sodarcache REST API version to v2.0
- Upgrade timeline REST API version to v2.0
- Remove support for filesfolders REST API <v2.0
- Remove support for sodarcache REST API <v2.0
- Remove support for timeline REST API <v2.0
- Remove support for SODAR Core features deprecated in v1.0
- Remove squashed migrations

Breaking Changes
Expand Down Expand Up @@ -81,13 +87,29 @@ changed accordingly. The same also applies to ``revert_role_modify()``.
REST API View Changes
---------------------

- Projectroles API (``vnd.bihealth.sodar-core.projectroles``)
- Filesfolders API
* Current version: ``2.0`` (breaking changes)
* Allowed versions: ``2.0`` (support for previous versions dropped)
* All views: Return ``owner`` as UUID instead of ``SODARUserSerializer``
dict
- Projectroles API
* Current version: ``1.1`` (non-breaking changes)
* Allowed versions: ``1.0``, ``1.1``
* ``ProjectDestroyAPIView``: Add view
* ``ProjectRetrieveAPIView``: Add ``children`` field
* ``RoleAssignmentOwnerTransferAPIView``: Allow empty value for
``old_owner_role``
- Sodarcache API
* Current version: ``2.0`` (breaking changes)
* Allowed versions: ``2.0`` (support for previous versions dropped)
* ``CacheItemRetrieveAPIView``: Return ``user`` as UUID instead of
``SODARUserSerializer`` dict
- Timeline API
* Current version: ``2.0`` (breaking changes)
* Allowed versions: ``2.0`` (support for previous versions dropped)
* ``TimelineEventRetrieveAPIView``: Return ``user`` as UUID instead of
``SODARUserSerializer`` dict


Deprecated Features
-------------------
Expand Down
17 changes: 10 additions & 7 deletions filesfolders/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from rest_framework.generics import get_object_or_404

# Projectroles dependency
from projectroles.serializers import (
SODARProjectModelSerializer,
SODARUserSerializer,
)
from projectroles.serializers import SODARProjectModelSerializer
from projectroles.utils import build_secret

from filesfolders.models import File, Folder, HyperLink
Expand Down Expand Up @@ -63,7 +60,9 @@ class FolderSerializer(
"""

folder = serializers.SerializerMethodField()
owner = SODARUserSerializer(read_only=True)
owner = serializers.SlugRelatedField(
slug_field='sodar_uuid', read_only=True
)

class Meta:
model = Folder
Expand Down Expand Up @@ -98,7 +97,9 @@ class FileSerializer(FilesfoldersSerializerMixin, SODARProjectModelSerializer):
"""

folder = serializers.SerializerMethodField()
owner = SODARUserSerializer(read_only=True)
owner = serializers.SlugRelatedField(
slug_field='sodar_uuid', read_only=True
)
file = serializers.FileField(write_only=True)

class Meta:
Expand Down Expand Up @@ -150,7 +151,9 @@ class HyperLinkSerializer(
"""

folder = serializers.SerializerMethodField()
owner = SODARUserSerializer(read_only=True)
owner = serializers.SlugRelatedField(
slug_field='sodar_uuid', read_only=True
)

class Meta:
model = HyperLink
Expand Down
36 changes: 18 additions & 18 deletions filesfolders/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_get_list(self):
expected = {
'name': self.folder.name,
'folder': None,
'owner': self.get_serialized_user(self.folder.owner),
'owner': str(self.folder.owner.sodar_uuid),
'project': str(self.folder.project.sodar_uuid),
'flag': self.folder.flag,
'description': self.folder.description,
Expand All @@ -87,7 +87,7 @@ def test_get_pagination(self):
{
'name': self.folder.name,
'folder': None,
'owner': self.get_serialized_user(self.folder.owner),
'owner': str(self.folder.owner.sodar_uuid),
'project': str(self.folder.project.sodar_uuid),
'flag': self.folder.flag,
'description': self.folder.description,
Expand All @@ -113,7 +113,7 @@ def test_post_create_root(self):
expected = {
**self.folder_data,
'folder': None,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'date_modified': self.get_drf_datetime(new_folder.date_modified),
'sodar_uuid': str(new_folder.sodar_uuid),
Expand All @@ -134,7 +134,7 @@ def test_post_create_folder(self):
self.assertIsNotNone(new_folder)
expected = {
**folder_data,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'date_modified': self.get_drf_datetime(new_folder.date_modified),
'sodar_uuid': str(new_folder.sodar_uuid),
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_get_retrieve(self):
expected = {
'name': self.folder.name,
'folder': None,
'owner': self.get_serialized_user(self.folder.owner),
'owner': str(self.folder.owner.sodar_uuid),
'project': str(self.folder.project.sodar_uuid),
'flag': self.folder.flag,
'description': self.folder.description,
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_put_update(self):
expected = {
**folder_data,
'folder': None,
'owner': self.get_serialized_user(self.folder.owner),
'owner': str(self.folder.owner.sodar_uuid),
'project': str(self.folder.project.sodar_uuid),
'date_modified': self.get_drf_datetime(self.folder.date_modified),
'sodar_uuid': str(self.folder.sodar_uuid),
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_get_list(self):
expected = {
'name': self.file.name,
'folder': None,
'owner': self.get_serialized_user(self.file.owner),
'owner': str(self.file.owner.sodar_uuid),
'project': str(self.file.project.sodar_uuid),
'flag': self.file.flag,
'description': self.file.description,
Expand All @@ -282,7 +282,7 @@ def test_get_pagination(self):
{
'name': self.file.name,
'folder': None,
'owner': self.get_serialized_user(self.file.owner),
'owner': str(self.file.owner.sodar_uuid),
'project': str(self.file.project.sodar_uuid),
'flag': self.file.flag,
'description': self.file.description,
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_post_create_root(self):
expected = {
**self.file_data,
'folder': None,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'secret': new_file.secret,
'public_url': new_file.public_url,
Expand All @@ -335,7 +335,7 @@ def test_post_create_folder(self):
self.assertNotEqual(new_file.file.file.size, 0)
expected = {
**file_data,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'public_url': self.file_data['public_url'],
'secret': new_file.secret,
Expand Down Expand Up @@ -396,7 +396,7 @@ def test_get_retrieve(self):
expected = {
'name': self.file.name,
'folder': None,
'owner': self.get_serialized_user(self.file.owner),
'owner': str(self.file.owner.sodar_uuid),
'project': str(self.file.project.sodar_uuid),
'flag': self.file.flag,
'description': self.file.description,
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_put_update(self):
expected = {
**self.file_data,
'folder': None,
'owner': self.get_serialized_user(self.file.owner),
'owner': str(self.file.owner.sodar_uuid),
'project': str(self.file.project.sodar_uuid),
'public_url': self.file_data['public_url'],
'secret': self.file.secret,
Expand Down Expand Up @@ -506,7 +506,7 @@ def test_get_list(self):
expected = {
'name': self.hyperlink.name,
'folder': None,
'owner': self.get_serialized_user(self.hyperlink.owner),
'owner': str(self.hyperlink.owner.sodar_uuid),
'project': str(self.hyperlink.project.sodar_uuid),
'flag': self.hyperlink.flag,
'description': self.hyperlink.description,
Expand All @@ -531,7 +531,7 @@ def test_get_pagination(self):
{
'name': self.hyperlink.name,
'folder': None,
'owner': self.get_serialized_user(self.hyperlink.owner),
'owner': str(self.hyperlink.owner.sodar_uuid),
'project': str(self.hyperlink.project.sodar_uuid),
'flag': self.hyperlink.flag,
'description': self.hyperlink.description,
Expand All @@ -558,7 +558,7 @@ def test_post_root(self):
expected = {
**self.hyperlink_data,
'folder': None,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'date_modified': self.get_drf_datetime(new_link.date_modified),
'sodar_uuid': str(new_link.sodar_uuid),
Expand All @@ -581,7 +581,7 @@ def test_post_folder(self):
self.assertIsNotNone(new_link)
expected = {
**hyperlink_data,
'owner': self.get_serialized_user(self.user),
'owner': str(self.user.sodar_uuid),
'project': str(self.project.sodar_uuid),
'date_modified': self.get_drf_datetime(new_link.date_modified),
'sodar_uuid': str(new_link.sodar_uuid),
Expand Down Expand Up @@ -626,7 +626,7 @@ def test_get_retrieve(self):
expected = {
'name': self.hyperlink.name,
'folder': None,
'owner': self.get_serialized_user(self.hyperlink.owner),
'owner': str(self.hyperlink.owner.sodar_uuid),
'project': str(self.hyperlink.project.sodar_uuid),
'flag': self.hyperlink.flag,
'description': self.hyperlink.description,
Expand Down Expand Up @@ -669,7 +669,7 @@ def test_put_update(self):
expected = {
**hyperlink_data,
'folder': None,
'owner': self.get_serialized_user(self.hyperlink.owner),
'owner': str(self.hyperlink.owner.sodar_uuid),
'project': str(self.hyperlink.project.sodar_uuid),
'date_modified': self.get_drf_datetime(
self.hyperlink.date_modified
Expand Down
4 changes: 2 additions & 2 deletions filesfolders/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
FILESFOLDERS_API_MEDIA_TYPE = (
'application/vnd.bihealth.sodar-core.filesfolders+json'
)
FILESFOLDERS_API_DEFAULT_VERSION = '1.0'
FILESFOLDERS_API_ALLOWED_VERSIONS = ['1.0']
FILESFOLDERS_API_DEFAULT_VERSION = '2.0'
FILESFOLDERS_API_ALLOWED_VERSIONS = ['2.0']


# Base Classes and Mixins ------------------------------------------------------
Expand Down
9 changes: 4 additions & 5 deletions sodarcache/serializers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Serializers for the sodarcache app REST API"""

from rest_framework import serializers

# Projectroles dependency
from projectroles.serializers import (
SODARProjectModelSerializer,
SODARUserSerializer,
)
from projectroles.serializers import SODARProjectModelSerializer

from sodarcache.models import JSONCacheItem


class JSONCacheItemSerializer(SODARProjectModelSerializer):
"""Serializer for the JSONCacheItem model"""

user = SODARUserSerializer(read_only=True)
user = serializers.SlugRelatedField(slug_field='sodar_uuid', read_only=True)

class Meta:
model = JSONCacheItem
Expand Down
2 changes: 1 addition & 1 deletion sodarcache/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_get(self):
'project': str(self.project.sodar_uuid),
'app_name': TEST_APP_NAME,
'name': ITEM_NAME,
'user': self.get_serialized_user(self.user_owner),
'user': str(self.user_owner.sodar_uuid),
'data': {DATA_KEY: DATA_VAL},
'date_modified': self.get_drf_datetime(self.item.date_modified),
}
Expand Down
6 changes: 5 additions & 1 deletion sodarcache/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ class CacheItemRetrieveAPIView(
- ``name``: Item name (string)
- ``data``: Item data (JSON)
- ``date_modified``: Item modification datetime (YYYY-MM-DDThh:mm:ssZ)
- ``user``: User who created the item (SODARUserSerializer dict or None)
- ``user``: UUID of user who created the item (string)
**Version Changes**:
- ``2.0``: Return ``user`` as UUID instead of ``SODARUserSerializer`` dict
"""

permission_required = 'sodarcache.get_cache_value'
Expand Down
Loading

0 comments on commit fbae1ca

Please sign in to comment.