|
36 | 36 | from warehouse.admin.flags import AdminFlagValue
|
37 | 37 | from warehouse.email import send_pending_trusted_publisher_invalidated_email
|
38 | 38 | from warehouse.events.tags import EventTag
|
39 |
| -from warehouse.helpdesk.interfaces import IAdminNotificationService |
40 | 39 | from warehouse.metrics import IMetricsService
|
41 | 40 | from warehouse.oidc.models import PendingOIDCPublisher
|
42 | 41 | from warehouse.packaging.interfaces import (
|
@@ -485,6 +484,9 @@ def check_project_name(self, name: str) -> None:
|
485 | 484 | ).first():
|
486 | 485 | raise ProjectNameUnavailableSimilarError(similar_project_name)
|
487 | 486 |
|
| 487 | + return None |
| 488 | + |
| 489 | + def check_project_name_after_insert(self, name: str) -> None: |
488 | 490 | # Check for typo-squatting.
|
489 | 491 | if typo_check_match := typo_check_name(canonicalize_name(name)):
|
490 | 492 | raise ProjectNameUnavailableTypoSquattingError(
|
@@ -558,85 +560,6 @@ def create_project(
|
558 | 560 | projecthelp=request.help_url(_anchor="project-name"),
|
559 | 561 | ),
|
560 | 562 | ) from None
|
561 |
| - except ProjectNameUnavailableTypoSquattingError as exc: |
562 |
| - # Don't yet raise an error here, as we want to allow the |
563 |
| - # user to proceed with the project creation. We'll log a warning |
564 |
| - # instead. |
565 |
| - request.log.warning( |
566 |
| - "ProjectNameUnavailableTypoSquattingError", |
567 |
| - check_name=exc.check_name, |
568 |
| - existing_project_name=exc.existing_project_name, |
569 |
| - ) |
570 |
| - # Send notification to Admins for review |
571 |
| - notification_service = request.find_service(IAdminNotificationService) |
572 |
| - |
573 |
| - warehouse_domain = request.registry.settings.get("warehouse.domain") |
574 |
| - new_project_page = request.route_url( |
575 |
| - "packaging.project", |
576 |
| - name=name, |
577 |
| - _host=warehouse_domain, |
578 |
| - ) |
579 |
| - new_project_text = ( |
580 |
| - f"During `file_upload`, Project Create for " |
581 |
| - f"*<{new_project_page}|{name}>* was detected as a potential " |
582 |
| - f"typo by the `{exc.check_name!r}` check." |
583 |
| - ) |
584 |
| - existing_project_page = request.route_url( |
585 |
| - "packaging.project", |
586 |
| - name=exc.existing_project_name, |
587 |
| - _host=warehouse_domain, |
588 |
| - ) |
589 |
| - existing_project_text = ( |
590 |
| - f"<{existing_project_page}|Existing project: " |
591 |
| - f"{exc.existing_project_name}>" |
592 |
| - ) |
593 |
| - |
594 |
| - webhook_payload = { |
595 |
| - "blocks": [ |
596 |
| - { |
597 |
| - "type": "header", |
598 |
| - "text": { |
599 |
| - "type": "plain_text", |
600 |
| - "text": "TypoSnyper :warning:", |
601 |
| - "emoji": True, |
602 |
| - }, |
603 |
| - }, |
604 |
| - { |
605 |
| - "type": "section", |
606 |
| - "text": { |
607 |
| - "type": "mrkdwn", |
608 |
| - "text": new_project_text, |
609 |
| - }, |
610 |
| - }, |
611 |
| - { |
612 |
| - "type": "section", |
613 |
| - "text": { |
614 |
| - "type": "mrkdwn", |
615 |
| - "text": existing_project_text, |
616 |
| - }, |
617 |
| - }, |
618 |
| - {"type": "divider"}, |
619 |
| - { |
620 |
| - "type": "context", |
621 |
| - "elements": [ |
622 |
| - { |
623 |
| - "type": "plain_text", |
624 |
| - "text": "Once reviewed/confirmed, " |
625 |
| - "react to this message with :white_check_mark:", |
626 |
| - "emoji": True, |
627 |
| - } |
628 |
| - ], |
629 |
| - }, |
630 |
| - ] |
631 |
| - } |
632 |
| - notification_service.send_notification(payload=webhook_payload) |
633 |
| - |
634 |
| - request.metrics.increment( |
635 |
| - "warehouse.packaging.services.create_project.typo_squatting", |
636 |
| - tags=[f"check_name:{exc.check_name!r}"], |
637 |
| - ) |
638 |
| - # and continue with the project creation |
639 |
| - pass |
640 | 563 |
|
641 | 564 | # The project name is valid: create it and add it
|
642 | 565 | project = Project(name=name)
|
|
0 commit comments