[SILO-695] chore: Jira server/ Data center change + implemented delete for apps + removed validation from webhooks in create/edit app (#4765)
* chore: Jira server/ Data center change + implemented delete for apps + removed validation from webhooks in create/edit app * add oauth app delete fix and bgtask * fix: refactor * fix: handled delete --------- Co-authored-by: Saurabhkmr98 <[email protected]> Co-authored-by: Saurabh Kumar <[email protected]>
This commit is contained in:
co-authored by
Saurabhkmr98
Saurabh Kumar
parent
5bad47bea7
commit
4f7a45260d
@@ -0,0 +1,20 @@
|
||||
from celery import shared_task
|
||||
import logging
|
||||
|
||||
@shared_task
|
||||
def app_delete_updates(application_id: str):
|
||||
"""
|
||||
This function deletes all app installations for an application.
|
||||
"""
|
||||
from plane.authentication.models import Application, WorkspaceAppInstallation
|
||||
|
||||
application = Application.objects.get(id=application_id)
|
||||
if not application:
|
||||
logging.getLogger("plane.worker").info(f"Application {application_id} not found")
|
||||
return
|
||||
app_installations = WorkspaceAppInstallation.objects.filter(
|
||||
application_id=application_id,
|
||||
)
|
||||
for app_installation in app_installations:
|
||||
app_installation.delete()
|
||||
return
|
||||
@@ -17,6 +17,7 @@ from oauth2_provider.models import (
|
||||
|
||||
from plane.app.permissions.base import ROLE
|
||||
from plane.authentication.bgtasks.app_webhook_url_updates import app_webhook_url_updates
|
||||
from plane.authentication.bgtasks.app_delete_updates import app_delete_updates
|
||||
from plane.authentication.bgtasks.app_logo_asset_updates import app_logo_asset_updates
|
||||
from plane.db.mixins import SoftDeleteModel, UserAuditModel
|
||||
from plane.db.models import (
|
||||
@@ -152,6 +153,11 @@ class Application(AbstractApplication, UserAuditModel, SoftDeleteModel):
|
||||
|
||||
super(Application, self).save(*args, **kwargs)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
app_delete_updates.delay(self.id)
|
||||
super(Application, self).delete(*args, **kwargs)
|
||||
|
||||
|
||||
class Grant(AbstractGrant):
|
||||
id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False, db_index=True, primary_key=True)
|
||||
|
||||
@@ -168,6 +168,7 @@ class OAuthApplicationEndpoint(BaseAPIView):
|
||||
| Q(published_at__isnull=False)
|
||||
| Q(slug__in=enabled_apps_slugs)
|
||||
)
|
||||
.filter(deleted_at__isnull=True)
|
||||
.select_related("logo_asset")
|
||||
.prefetch_related("attachments", "categories")
|
||||
)
|
||||
@@ -213,6 +214,7 @@ class OAuthApplicationEndpoint(BaseAPIView):
|
||||
.select_related(
|
||||
"logo_asset",
|
||||
)
|
||||
.filter(deleted_at__isnull=True)
|
||||
.first()
|
||||
)
|
||||
|
||||
@@ -247,15 +249,10 @@ class OAuthApplicationEndpoint(BaseAPIView):
|
||||
{"error": "Application not found"}, status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
def delete(self, request, slug, pk):
|
||||
application = Application.objects.filter(
|
||||
id=pk, application_owners__workspace__slug=slug
|
||||
).first()
|
||||
if not application:
|
||||
return Response(
|
||||
{"error": "Application not found"}, status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
application.delete()
|
||||
def delete(self, request, slug, app_slug):
|
||||
application = Application.objects.filter(slug=app_slug, application_owners__workspace__slug=slug).first()
|
||||
if application:
|
||||
application.delete()
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user