[WEB-4479] feat: enable/disable SMTP configuration (#7393)
* feat: api update instance configuration * chore: add enable_smtp key * fix: empty string for enable_smtp key * chore: update email_port and email_from * fix: handled smtp enable disable * fix: error handling * fix: refactor * fix: removed enabled toast * fix: refactor --------- Co-authored-by: gakshita <akshitagoyal1516@gmail.com> Co-authored-by: Akshita Goyal <36129505+gakshita@users.noreply.github.com>
This commit is contained in:
parent
da5390fa03
commit
99127ff8e4
9 changed files with 155 additions and 24 deletions
|
|
@ -1,7 +1,11 @@
|
|||
from .instance import InstanceEndpoint, SignUpScreenVisitedEndpoint
|
||||
|
||||
|
||||
from .configuration import EmailCredentialCheckEndpoint, InstanceConfigurationEndpoint
|
||||
from .configuration import (
|
||||
EmailCredentialCheckEndpoint,
|
||||
InstanceConfigurationEndpoint,
|
||||
DisableEmailFeatureEndpoint,
|
||||
)
|
||||
|
||||
|
||||
from .admin import (
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from smtplib import (
|
|||
|
||||
# Django imports
|
||||
from django.core.mail import BadHeaderError, EmailMultiAlternatives, get_connection
|
||||
from django.db.models import Q, Case, When, Value
|
||||
|
||||
# Third party imports
|
||||
from rest_framework import status
|
||||
|
|
@ -57,6 +58,34 @@ class InstanceConfigurationEndpoint(BaseAPIView):
|
|||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class DisableEmailFeatureEndpoint(BaseAPIView):
|
||||
permission_classes = [InstanceAdminPermission]
|
||||
|
||||
@invalidate_cache(path="/api/instances/", user=False)
|
||||
def delete(self, request):
|
||||
try:
|
||||
InstanceConfiguration.objects.filter(
|
||||
Q(
|
||||
key__in=[
|
||||
"EMAIL_HOST",
|
||||
"EMAIL_HOST_USER",
|
||||
"EMAIL_HOST_PASSWORD",
|
||||
"ENABLE_SMTP",
|
||||
"EMAIL_PORT",
|
||||
"EMAIL_FROM",
|
||||
]
|
||||
)
|
||||
).update(
|
||||
value=Case(When(key="ENABLE_SMTP", then=Value("0")), default=Value(""))
|
||||
)
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
except Exception:
|
||||
return Response(
|
||||
{"error": "Failed to disable email configuration"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
|
||||
class EmailCredentialCheckEndpoint(BaseAPIView):
|
||||
def post(self, request):
|
||||
receiver_email = request.data.get("receiver_email", False)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,12 @@ class Command(BaseCommand):
|
|||
"category": "GITLAB",
|
||||
"is_encrypted": False,
|
||||
},
|
||||
{
|
||||
"key": "ENABLE_SMTP",
|
||||
"value": os.environ.get("ENABLE_SMTP", "0"),
|
||||
"category": "SMTP",
|
||||
"is_encrypted": False,
|
||||
},
|
||||
{
|
||||
"key": "GITLAB_CLIENT_SECRET",
|
||||
"value": os.environ.get("GITLAB_CLIENT_SECRET"),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from plane.license.api.views import (
|
|||
InstanceAdminSignInEndpoint,
|
||||
InstanceAdminSignUpEndpoint,
|
||||
InstanceConfigurationEndpoint,
|
||||
DisableEmailFeatureEndpoint,
|
||||
InstanceEndpoint,
|
||||
SignUpScreenVisitedEndpoint,
|
||||
InstanceAdminUserMeEndpoint,
|
||||
|
|
@ -35,6 +36,11 @@ urlpatterns = [
|
|||
InstanceConfigurationEndpoint.as_view(),
|
||||
name="instance-configuration",
|
||||
),
|
||||
path(
|
||||
"configurations/disable-email-feature/",
|
||||
DisableEmailFeatureEndpoint.as_view(),
|
||||
name="disable-email-configuration",
|
||||
),
|
||||
path(
|
||||
"admins/sign-in/",
|
||||
InstanceAdminSignInEndpoint.as_view(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue