Skip to content

Commit 7ec319f

Browse files
authored
Merge pull request #194 from ecmwf-projects/COPDS-1842-anonymous-licences
Let anonymous user submit jobs but return disclaimer
2 parents 6772d39 + 5abacde commit 7ec319f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

cads_processing_api_service/clients.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def post_process_execution(
204204
"""
205205
user_uid, user_role = auth.authenticate_user(auth_header, portal_header)
206206
structlog.contextvars.bind_contextvars(user_uid=user_uid)
207-
accepted_licences = auth.get_accepted_licences(auth_header)
208207
request = execution_content.model_dump()
209208
catalogue_sessionmaker = db_utils.get_catalogue_sessionmaker(
210209
db_utils.ConnectionMode.read
@@ -233,7 +232,16 @@ def post_process_execution(
233232
raise exceptions.InvalidRequest(detail=str(exc)) from exc
234233
costs = auth.verify_cost(request_inputs, adaptor_properties)
235234
licences = adaptor.get_licences(request_inputs)
236-
auth.validate_licences(accepted_licences, licences)
235+
if user_uid != "anonymous":
236+
accepted_licences = auth.get_accepted_licences(auth_header)
237+
auth.validate_licences(accepted_licences, licences)
238+
job_message = None
239+
else:
240+
job_message = config.ensure_settings().anonymous_licences_message.format(
241+
licences="; ".join(
242+
[f"{licence[0]} (rev: {licence[1]})" for licence in licences]
243+
)
244+
)
237245
job_id = str(uuid.uuid4())
238246
structlog.contextvars.bind_contextvars(job_id=job_id)
239247
job_kwargs = adaptors.make_system_job_kwargs(
@@ -265,6 +273,7 @@ def post_process_execution(
265273
status_info = utils.make_status_info(
266274
job, dataset_metadata={"messages": dataset_messages}
267275
)
276+
status_info.message = job_message
268277
return status_info
269278

270279
def get_jobs(

cads_processing_api_service/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
client.retrieve(dataset, request).download()
2929
"""
3030

31+
ANONYMOUS_LICENCES_MESSAGE = (
32+
"The job has been submitted as an anonymous user. "
33+
"Please consider the following licences implicitly accepted: "
34+
"{licences}"
35+
)
36+
3137
general_settings = None
3238

3339

@@ -50,6 +56,7 @@ class Settings(pydantic_settings.BaseSettings):
5056

5157
api_request_template: str = API_REQUEST_TEMPLATE
5258
missing_dataset_title: str = "Dataset not available"
59+
anonymous_licences_message: str = ANONYMOUS_LICENCES_MESSAGE
5360

5461
@property
5562
def profiles_api_url(self) -> str:

0 commit comments

Comments
 (0)