@@ -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 )
0 commit comments