Skip to content

Commit 4d758e5

Browse files
committed
add ProjectIrodsFileListAPIView checksum field (#2039)
1 parent cd73254 commit 4d758e5

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Added
2323
- ``cleanup_file_prohibit()`` utility method (#2064)
2424
- **Samplesheets**
2525
- Site read-only mode support (#2051)
26+
- ``checksum`` field in ``ProjectIrodsFileListAPIView`` return data (#2039)
2627
- **Taskflowbackend**
2728
- Project deletion support (#2051)
2829
- Zone validation and moving progress indicators (#2024)

docs_manual/source/api_samplesheets.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Versioning
1212
Media Type
1313
``application/vnd.bihealth.sodar.samplesheets+json``
1414
Current Version
15-
``1.0``
15+
``1.1``
1616
Accepted Versions
17-
``1.0``
17+
``1.0``, ``1.1``
1818
Header Example
1919
``Accept: application/vnd.bihealth.sodar.samplesheets+json; version=x.y``
2020

@@ -71,3 +71,13 @@ iRODS Data Requests
7171
.. autoclass:: IrodsDataRequestAcceptAPIView
7272

7373
.. autoclass:: IrodsDataRequestRejectAPIView
74+
75+
76+
Version Changes
77+
===============
78+
79+
v1.1
80+
----
81+
82+
- ``ProjectIrodsFileListAPIView``
83+
* Add ``checksum`` field to return data

docs_manual/source/sodar_release_notes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Release for SODAR Core 1.1 upgrade and feature updates.
1515

1616
- Add landing zone validation and moving progress indicators
1717
- Add landing zone file type prohibiting
18+
- Upgrade Sample Sheets REST API version to v1.1
1819
- Upgrade to python-irodsclient v3.0
1920
- Upgrade to SODAR Core v1.1.2
2021
- Replace SODAR_SUPPORT_* settings with PROJECTROLES_SUPPORT_CONTACT
@@ -24,6 +25,15 @@ Release for SODAR Core 1.1 upgrade and feature updates.
2425

2526
:ref:`Administrator upgrade guide for v1.1 <admin_upgrade_v1.1>`
2627

28+
REST API Updates
29+
----------------
30+
31+
- Sample Sheets API
32+
* Current version: ``1.1`` (non-breaking changes)
33+
* Allowed versions: ``1.0``, ``1.1``
34+
* ``ProjectIrodsFileListAPIView``
35+
+ Add ``checksum`` field to return data
36+
2737

2838
v1.0.1 (2025-03-12)
2939
===================

samplesheets/tests/test_views_api_taskflow.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,7 @@ def setUp(self):
12581258

12591259
def test_get_no_collection(self):
12601260
"""Test ProjectIrodsFileListAPIView GET without collection"""
1261-
with self.login(self.user):
1262-
response = self.client.get(self.url)
1261+
response = self.request_knox(self.url)
12631262
self.assertEqual(response.status_code, 404)
12641263
self.assertEqual(
12651264
response.data['detail'],
@@ -1272,27 +1271,45 @@ def test_get_empty_collection(self):
12721271
"""Test GET with empty collection"""
12731272
# Set up iRODS collections
12741273
self.make_irods_colls(self.investigation)
1275-
with self.login(self.user):
1276-
response = self.client.get(self.url)
1274+
response = self.request_knox(self.url)
12771275
self.assertEqual(response.status_code, 200)
12781276
self.assertEqual(response.data, [])
12791277

12801278
def test_get_files(self):
12811279
"""Test GET with files"""
1282-
# Set up iRODS collections
12831280
self.make_irods_colls(self.investigation)
12841281
coll_path = self.irods_backend.get_sample_path(self.project) + '/'
12851282
self.irods.data_objects.put(
12861283
IRODS_FILE_PATH, coll_path, **{REG_CHKSUM_KW: ''}
12871284
)
1288-
with self.login(self.user):
1289-
response = self.client.get(self.url)
1285+
data_obj = self.irods.data_objects.get(coll_path + '/' + 'test1.txt')
1286+
response = self.request_knox(self.url)
12901287
self.assertEqual(response.status_code, 200)
12911288
self.assertEqual(len(response.data), 1)
12921289
self.assertEqual(response.data[0]['name'], IRODS_FILE_NAME)
12931290
self.assertEqual(response.data[0]['type'], 'obj')
1291+
self.assertEqual(
1292+
response.data[0]['modify_time'],
1293+
self.get_drf_datetime(data_obj.modify_time),
1294+
)
1295+
self.assertEqual(response.data[0]['checksum'], data_obj.checksum)
1296+
self.assertIsNotNone(response.data[0]['checksum'])
1297+
1298+
def test_get_files_v1_0(self):
1299+
"""Test GET with files and API version 1.0"""
1300+
self.make_irods_colls(self.investigation)
1301+
coll_path = self.irods_backend.get_sample_path(self.project) + '/'
1302+
self.irods.data_objects.put(
1303+
IRODS_FILE_PATH, coll_path, **{REG_CHKSUM_KW: ''}
1304+
)
12941305
data_obj = self.irods.data_objects.get(coll_path + '/' + 'test1.txt')
1306+
response = self.request_knox(self.url, version='1.0')
1307+
self.assertEqual(response.status_code, 200)
1308+
self.assertEqual(len(response.data), 1)
1309+
self.assertEqual(response.data[0]['name'], IRODS_FILE_NAME)
1310+
self.assertEqual(response.data[0]['type'], 'obj')
12951311
self.assertEqual(
12961312
response.data[0]['modify_time'],
12971313
self.get_drf_datetime(data_obj.modify_time),
12981314
)
1315+
self.assertNotIn('checksum', response.data[0]) # Should not be included

samplesheets/views_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from irods.exception import CAT_NO_ROWS_FOUND
88
from irods.models import DataObject
9+
from packaging.version import parse as parse_version
910

1011
from django.conf import settings
1112
from django.urls import reverse
@@ -85,8 +86,8 @@
8586

8687
# Local constants
8788
SAMPLESHEETS_API_MEDIA_TYPE = 'application/vnd.bihealth.sodar.samplesheets+json'
88-
SAMPLESHEETS_API_ALLOWED_VERSIONS = ['1.0']
89-
SAMPLESHEETS_API_DEFAULT_VERSION = '1.0'
89+
SAMPLESHEETS_API_ALLOWED_VERSIONS = ['1.0', '1.1']
90+
SAMPLESHEETS_API_DEFAULT_VERSION = '1.1'
9091
MD5_RE = re.compile(r'([a-fA-F\d]{32})')
9192
APP_NAME = 'samplesheets'
9293
IRODS_QUERY_ERROR_MSG = 'Exception querying iRODS objects'
@@ -993,6 +994,7 @@ def get(self, request, *args, **kwargs):
993994
'path': serializers.CharField(),
994995
'size': serializers.IntegerField(),
995996
'modify_time': serializers.DateTimeField(),
997+
'checksum': serializers.CharField(),
996998
},
997999
),
9981000
}
@@ -1016,6 +1018,11 @@ class ProjectIrodsFileListAPIView(
10161018
- ``path``: Full path to file
10171019
- ``size``: Size in bytes
10181020
- ``modify_time``: Datetime of last modification (YYYY-MM-DDThh:mm:ssZ)
1021+
- ``checksum``: Checksum of data object
1022+
1023+
**Version Changes**:
1024+
1025+
- ``1.1``: Add ``checksum`` field to return data
10191026
"""
10201027

10211028
http_method_names = ['get']
@@ -1027,10 +1034,12 @@ def get(self, request, *args, **kwargs):
10271034
irods_backend = get_backend_api('omics_irods')
10281035
project = self.get_project()
10291036
path = irods_backend.get_sample_path(project)
1037+
version = parse_version(self.request.version)
1038+
checksum = True if version >= parse_version('1.1') else False
10301039
try:
10311040
with irods_backend.get_session() as irods:
10321041
obj_list = irods_backend.get_objects(
1033-
irods, path, api_format=True
1042+
irods, path, api_format=True, checksum=checksum
10341043
)
10351044
except Exception as ex:
10361045
return Response(

0 commit comments

Comments
 (0)