Skip to content

Commit f0cf555

Browse files
authored
Merge pull request #299 from VariantEffect/release-2024.3.1
Release 2024.3.1 as part of Release 2024.4.0
2 parents d9582a1 + 2542feb commit f0cf555

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/mavedb/lib/mave/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
22

3+
import pandas as pd
4+
35
NA_VALUE = "NA"
46

57
NULL_VALUES = ("", "na", "nan", "nil", "none", "null", "n/a", "undefined", NA_VALUE)
@@ -22,6 +24,9 @@
2224

2325
def is_csv_null(value):
2426
"""Return True if a string from a CSV file represents a NULL value."""
27+
# Avoid any boolean miscasts from comparisons by handling NA types up front.
28+
if pd.isna(value):
29+
return True
2530
# Number 0 is treated as False so that all 0 will be converted to NA value.
2631
if value == 0:
2732
return value

src/mavedb/lib/permissions.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
9595
elif private:
9696
# Do not acknowledge the existence of a private entity.
9797
return PermissionResponse(False, 404, f"experiment set with URN '{item.urn}' not found")
98+
elif user_data is None or user_data.user is None:
99+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
98100
else:
99-
return PermissionResponse(False)
101+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
100102
elif action == Action.UPDATE:
101103
if user_may_edit:
102104
return PermissionResponse(True)
@@ -106,8 +108,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
106108
elif private:
107109
# Do not acknowledge the existence of a private entity.
108110
return PermissionResponse(False, 404, f"experiment set with URN '{item.urn}' not found")
111+
elif user_data is None or user_data.user is None:
112+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
109113
else:
110-
return PermissionResponse(False)
114+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
111115
elif action == Action.DELETE:
112116
# Owner may only delete an experiment set if it has not already been published.
113117
if user_may_edit:
@@ -143,8 +147,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
143147
elif private:
144148
# Do not acknowledge the existence of a private entity.
145149
return PermissionResponse(False, 404, f"experiment with URN '{item.urn}' not found")
150+
elif user_data is None or user_data.user is None:
151+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
146152
else:
147-
return PermissionResponse(False)
153+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
148154
elif action == Action.UPDATE:
149155
if user_may_edit:
150156
return PermissionResponse(True)
@@ -154,8 +160,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
154160
elif private:
155161
# Do not acknowledge the existence of a private entity.
156162
return PermissionResponse(False, 404, f"experiment with URN '{item.urn}' not found")
163+
elif user_data is None or user_data.user is None:
164+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
157165
else:
158-
return PermissionResponse(False)
166+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
159167
elif action == Action.DELETE:
160168
# Owner may only delete an experiment if it has not already been published.
161169
if user_may_edit:
@@ -191,8 +199,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
191199
elif private:
192200
# Do not acknowledge the existence of a private entity.
193201
return PermissionResponse(False, 404, f"score set with URN '{item.urn}' not found")
202+
elif user_data is None or user_data.user is None:
203+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
194204
else:
195-
return PermissionResponse(False)
205+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
196206
elif action == Action.UPDATE:
197207
if user_may_edit:
198208
return PermissionResponse(True)
@@ -202,8 +212,10 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
202212
elif private:
203213
# Do not acknowledge the existence of a private entity.
204214
return PermissionResponse(False, 404, f"score set with URN '{item.urn}' not found")
215+
elif user_data is None or user_data.user is None:
216+
return PermissionResponse(False, 401, f"insufficient permissions for URN '{item.urn}'")
205217
else:
206-
return PermissionResponse(False)
218+
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
207219
elif action == Action.DELETE:
208220
# Owner may only delete a score set if it has not already been published.
209221
if user_may_edit:
@@ -247,7 +259,7 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
247259
elif roles_permitted(active_roles, [UserRole.admin]):
248260
return PermissionResponse(True)
249261
else:
250-
return PermissionResponse(False)
262+
return PermissionResponse(False, 403, "Insufficient permissions for user update.")
251263
elif action == Action.UPDATE:
252264
if user_is_self:
253265
return PermissionResponse(True)

src/mavedb/routers/score_sets.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,13 @@ async def update_score_set(
854854
scores_data = pd.DataFrame(
855855
variants_to_csv_rows(item.variants, columns=score_columns, dtype="score_data")
856856
).replace("NA", pd.NA)
857-
count_data = pd.DataFrame(
858-
variants_to_csv_rows(item.variants, columns=count_columns, dtype="count_data")
859-
).replace("NA", pd.NA)
857+
858+
if item.dataset_columns["count_columns"]:
859+
count_data = pd.DataFrame(
860+
variants_to_csv_rows(item.variants, columns=count_columns, dtype="count_data")
861+
).replace("NA", pd.NA)
862+
else:
863+
count_data = None
860864

861865
# Although this is also updated within the variant creation job, update it here
862866
# as well so that we can display the proper UI components (queue invocation delay

src/mavedb/routers/statistics.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ def record_object_statistics(
332332
Model names and fields should be members of the Enum classes defined above. Providing an invalid model name or
333333
model field will yield a 422 Unprocessable Entity error with details about valid enum values.
334334
"""
335+
# Validation to ensure 'keywords' is only used with 'experiment'.
336+
if model == RecordNames.scoreSet and field == RecordFields.keywords:
337+
raise HTTPException(status_code=422,
338+
detail="The 'keywords' field can only be used with the 'experiment' model.")
339+
335340
count_data = _record_from_field_and_model(db, model, field)
336341

337342
return {field_val: count for field_val, count in count_data if field_val is not None}

0 commit comments

Comments
 (0)