Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/origin_save.py
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | ) -> SaveOriginRequestInfo: | ||||
if must_save: | if must_save: | ||||
save_request.save() | save_request.save() | ||||
return save_request.to_dict() | return save_request.to_dict() | ||||
def create_save_origin_request( | def create_save_origin_request( | ||||
visit_type: str, origin_url: str, bypass_pending_review: bool = False | visit_type: str, | ||||
origin_url: str, | |||||
bypass_pending_review: bool = False, | |||||
user_id: Optional[int] = None, | |||||
) -> SaveOriginRequestInfo: | ) -> SaveOriginRequestInfo: | ||||
""" | """ | ||||
Create a loading task to save a software origin into the archive. | Create a loading task to save a software origin into the archive. | ||||
This function aims to create a software origin loading task | This function aims to create a software origin loading task | ||||
trough the use of the swh-scheduler component. | trough the use of the swh-scheduler component. | ||||
First, some checks are performed to see if the visit type and origin | First, some checks are performed to see if the visit type and origin | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | if save_request_status == SAVE_REQUEST_ACCEPTED: | ||||
sor.loading_task_id = task["id"] | sor.loading_task_id = task["id"] | ||||
sor.save() | sor.save() | ||||
else: | else: | ||||
sor = SaveOriginRequest.objects.create( | sor = SaveOriginRequest.objects.create( | ||||
visit_type=visit_type, | visit_type=visit_type, | ||||
origin_url=origin_url, | origin_url=origin_url, | ||||
status=save_request_status, | status=save_request_status, | ||||
loading_task_id=task["id"], | loading_task_id=task["id"], | ||||
user_id=str(user_id) if user_id else None, | |||||
) | ) | ||||
# save request must be manually reviewed for acceptation | # save request must be manually reviewed for acceptation | ||||
elif save_request_status == SAVE_REQUEST_PENDING: | elif save_request_status == SAVE_REQUEST_PENDING: | ||||
# check if there is already such a save request already submitted, | # check if there is already such a save request already submitted, | ||||
# no need to add it to the database in that case | # no need to add it to the database in that case | ||||
try: | try: | ||||
sor = SaveOriginRequest.objects.get( | sor = SaveOriginRequest.objects.get( | ||||
visit_type=visit_type, origin_url=origin_url, status=save_request_status | visit_type=visit_type, origin_url=origin_url, status=save_request_status | ||||
) | ) | ||||
# if not add it to the database | # if not add it to the database | ||||
except ObjectDoesNotExist: | except ObjectDoesNotExist: | ||||
sor = SaveOriginRequest.objects.create( | sor = SaveOriginRequest.objects.create( | ||||
visit_type=visit_type, origin_url=origin_url, status=save_request_status | visit_type=visit_type, | ||||
origin_url=origin_url, | |||||
status=save_request_status, | |||||
user_id=str(user_id) if user_id else None, | |||||
) | ) | ||||
# origin can not be saved as its url is blacklisted, | # origin can not be saved as its url is blacklisted, | ||||
# log the request to the database anyway | # log the request to the database anyway | ||||
else: | else: | ||||
sor = SaveOriginRequest.objects.create( | sor = SaveOriginRequest.objects.create( | ||||
visit_type=visit_type, origin_url=origin_url, status=save_request_status | visit_type=visit_type, | ||||
origin_url=origin_url, | |||||
status=save_request_status, | |||||
user_id=str(user_id) if user_id else None, | |||||
) | ) | ||||
if save_request_status == SAVE_REQUEST_REJECTED: | if save_request_status == SAVE_REQUEST_REJECTED: | ||||
raise ForbiddenExc( | raise ForbiddenExc( | ||||
( | ( | ||||
'The "save code now" request has been rejected ' | 'The "save code now" request has been rejected ' | ||||
"because the provided origin url is blacklisted." | "because the provided origin url is blacklisted." | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |