@@ -183,17 +183,25 @@ def get_accepted_licences(auth_header: tuple[str, str]) -> set[tuple[str, int]]:
183
183
return accepted_licences
184
184
185
185
186
- def check_licences (
187
- required_licences : set [tuple [str , int ]], accepted_licences : set [tuple [str , int ]]
186
+ def verify_licences (
187
+ accepted_licences : set [tuple [str , int ]] | list [tuple [str , int ]],
188
+ required_licences : set [tuple [str , int ]] | list [tuple [str , int ]],
189
+ api_request_url : str ,
190
+ process_id : str ,
188
191
) -> set [tuple [str , int ]]:
189
- """Check if accepted licences satisfy required ones.
192
+ """
193
+ Verify if all the licences required for the process submission have been accepted.
190
194
191
195
Parameters
192
196
----------
193
- required_licences : set[tuple[str, int]]
194
- Required licences.
195
- accepted_licences : set[tuple[str, int]]
196
- Accepted licences.
197
+ accepted_licences : set[tuple[str, int]] | list[tuple[str, int]],
198
+ Licences accepted by a user stored in the Extended Profiles database.
199
+ required_licences : set[tuple[str, int]] | list[tuple[str, int]],
200
+ Licences bound to the required process/dataset.
201
+ api_request_url : str
202
+ API request URL, required to generate the URL to the dataset licences page.
203
+ process_id : str
204
+ Process identifier, required to generate the URL to the dataset licences page.
197
205
198
206
Returns
199
207
-------
@@ -205,39 +213,30 @@ def check_licences(
205
213
exceptions.PermissionDenied
206
214
Raised if not all required licences have been accepted.
207
215
"""
216
+ if not isinstance (accepted_licences , set ):
217
+ accepted_licences = set (accepted_licences )
218
+ if not isinstance (required_licences , set ):
219
+ required_licences = set (required_licences )
208
220
missing_licences = required_licences - accepted_licences
209
221
if not len (missing_licences ) == 0 :
210
- missing_licences_detail = [
211
- {"id" : licence [0 ], "revision" : licence [1 ]} for licence in missing_licences
212
- ]
222
+ missing_licences_message_template = (
223
+ config .ensure_settings ().missing_licences_message
224
+ )
225
+ dataset_licences_url_template = config .ensure_settings ().dataset_licences_url
226
+ parsed_api_request_url = urllib .parse .urlparse (api_request_url )
227
+ base_url = f"{ parsed_api_request_url .scheme } ://{ parsed_api_request_url .netloc } "
228
+ dataset_licences_url = dataset_licences_url_template .format (
229
+ base_url = base_url , process_id = process_id
230
+ )
231
+ missing_licences_message = missing_licences_message_template .format (
232
+ dataset_licences_url = dataset_licences_url
233
+ )
213
234
raise exceptions .PermissionDenied (
214
- title = "required licences not accepted" ,
215
- detail = (
216
- "required licences not accepted; "
217
- "please accept the following licences to proceed: "
218
- f"{ missing_licences_detail } "
219
- ),
235
+ title = "required licences not accepted" , detail = missing_licences_message
220
236
)
221
237
return missing_licences
222
238
223
239
224
- def validate_licences (
225
- accepted_licences : set [tuple [str , str ]],
226
- licences : list [tuple [str , int ]],
227
- ) -> None :
228
- """Validate process execution request's payload in terms of required licences.
229
-
230
- Parameters
231
- ----------
232
- stored_accepted_licences : set[tuple[str, str]]
233
- Licences accepted by a user stored in the Extended Profiles database.
234
- licences : list[tuple[str, int]]
235
- Licences bound to the required process/dataset.
236
- """
237
- required_licences = set (licences )
238
- check_licences (required_licences , accepted_licences ) # type: ignore
239
-
240
-
241
240
def verify_if_disabled (disabled_reason : str | None , user_role : str | None ) -> None :
242
241
"""Verify if a dataset's disabling reason grant access to the dataset for a specific user role.
243
242
0 commit comments