|
42 | 42 | from readthedocs.core.notifications import MESSAGE_EMAIL_VALIDATION_PENDING
|
43 | 43 | from readthedocs.integrations.models import HttpExchange, Integration
|
44 | 44 | from readthedocs.invitations.models import Invitation
|
| 45 | +from readthedocs.notifications.messages import registry as messages_registry |
45 | 46 | from readthedocs.notifications.models import Notification
|
46 | 47 | from readthedocs.oauth.services import registry
|
47 | 48 | from readthedocs.oauth.tasks import attach_webhook
|
48 | 49 | from readthedocs.oauth.utils import update_webhook
|
| 50 | +from readthedocs.projects.exceptions import ( |
| 51 | + ProjectAutomaticCreationDisallowed, |
| 52 | + ProjectManualCreationDisallowed, |
| 53 | +) |
49 | 54 | from readthedocs.projects.filters import ProjectListFilterSet
|
50 | 55 | from readthedocs.projects.forms import (
|
51 | 56 | AddonsConfigForm,
|
@@ -397,9 +402,55 @@ def post(self, request, *args, **kwargs):
|
397 | 402 | def get_context_data(self, **kwargs):
|
398 | 403 | context = super().get_context_data(**kwargs)
|
399 | 404 | context['view_csrf_token'] = get_token(self.request)
|
400 |
| - context['has_connected_accounts'] = SocialAccount.objects.filter( |
401 |
| - user=self.request.user, |
402 |
| - ).exists() |
| 405 | + |
| 406 | + if settings.RTD_EXT_THEME_ENABLED: |
| 407 | + error_import_manually = None |
| 408 | + error_import_automatically = None |
| 409 | + |
| 410 | + has_connected_account = SocialAccount.objects.filter( |
| 411 | + user=self.request.user, |
| 412 | + ).exists() |
| 413 | + |
| 414 | + # First check ability for automatic project creation |
| 415 | + # NOTE that try catch is used here, but isn't super useful yet. But |
| 416 | + # if it makes more sense to house this logic outside this view, |
| 417 | + # somewhere central to organization/user modeling, then we don't |
| 418 | + # have to change any code here. |
| 419 | + try: |
| 420 | + if has_connected_account: |
| 421 | + raise ProjectAutomaticCreationDisallowed( |
| 422 | + message_id=ProjectAutomaticCreationDisallowed.NO_CONNECTED_ACCOUNT, |
| 423 | + format_values={ |
| 424 | + "url": reverse("socialaccount_connections"), |
| 425 | + }, |
| 426 | + ) |
| 427 | + # TODO if organization sso enabled and user is not an owner |
| 428 | + if True: |
| 429 | + raise ProjectAutomaticCreationDisallowed( |
| 430 | + message_id=ProjectAutomaticCreationDisallowed.SSO_ENABLED, |
| 431 | + ) |
| 432 | + except ProjectAutomaticCreationDisallowed as exc: |
| 433 | + error_import_automatically = messages_registry.get( |
| 434 | + exc.message_id, |
| 435 | + format_values=exc.format_values, |
| 436 | + ) |
| 437 | + |
| 438 | + # Next check ability for manual project creation |
| 439 | + try: |
| 440 | + # TODO if organization sso enabled |
| 441 | + if True: |
| 442 | + raise ProjectManualCreationDisallowed( |
| 443 | + ProjectManualCreationDisallowed.SSO_ENABLED |
| 444 | + ) |
| 445 | + except ProjectManualCreationDisallowed as exc: |
| 446 | + error_import_manually = messages_registry.get( |
| 447 | + exc.message_id, |
| 448 | + format_values=exc.format_values, |
| 449 | + ) |
| 450 | + |
| 451 | + context["error_import_automatically"] = error_import_automatically |
| 452 | + context["error_import_manually"] = error_import_manually |
| 453 | + |
403 | 454 | return context
|
404 | 455 |
|
405 | 456 |
|
|
0 commit comments