mirror of
https://github.com/makeplane/plane.git
synced 2026-07-14 06:25:58 +02:00
[SILO-286] feat: added migration for sentry integration (#3606)
* feat: added migration for sentry integration * Apply suggestion from @Prashant-Surya * fix: redirect uri --------- Co-authored-by: Surya Prashanth <prashantsurya002@gmail.com>
This commit is contained in:
36
apps/api/plane/silo/migrations/0005_create_sentry_app.py
Normal file
36
apps/api/plane/silo/migrations/0005_create_sentry_app.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 4.2.22 on 2025-06-23 15:11
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
def create_sentry_app(apps, schema_editor):
|
||||
# Getting the models from apps to avoid circular imports
|
||||
Application = apps.get_model("authentication", "Application")
|
||||
ApplicationSecret = apps.get_model("silo", "ApplicationSecret")
|
||||
User = apps.get_model("db", "User")
|
||||
InstanceAdmin = apps.get_model("license", "InstanceAdmin")
|
||||
|
||||
# Importing the function and constants directly here to avoid circular imports
|
||||
from plane.silo.services.generate_application import generate_application
|
||||
from plane.silo.utils.constants import APPLICATIONS
|
||||
|
||||
# Getting the first instance admin
|
||||
instance_admin = InstanceAdmin.objects.first()
|
||||
if instance_admin:
|
||||
generate_application(
|
||||
user_id=instance_admin.user.id,
|
||||
app_key=APPLICATIONS["sentry"]["key"],
|
||||
application_model=Application,
|
||||
application_secret_model=ApplicationSecret,
|
||||
user_model=User,
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('silo', '0004_create_github_enterprise_app'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_sentry_app, reverse_code=migrations.RunPython.noop)
|
||||
]
|
||||
@@ -44,6 +44,8 @@ def generate_application(
|
||||
app_slug = app_data["slug"]
|
||||
user = user_model.objects.get(id=user_id)
|
||||
|
||||
webhook_url = app_data.get("webhook_url", None)
|
||||
|
||||
with transaction.atomic():
|
||||
client_secret = generate_client_secret()
|
||||
|
||||
@@ -59,6 +61,7 @@ def generate_application(
|
||||
"authorization_grant_type": "authorization-code",
|
||||
"user_id": user_id,
|
||||
"client_secret": client_secret,
|
||||
"webhook_url": webhook_url,
|
||||
}
|
||||
|
||||
# check if application already exists
|
||||
@@ -67,6 +70,7 @@ def generate_application(
|
||||
# Application already exists, update client_secret
|
||||
application.client_secret = client_secret
|
||||
application.redirect_uris = app_data["redirect_uris"]
|
||||
application.webhook_url = webhook_url
|
||||
application.save()
|
||||
else:
|
||||
application = application_model.objects.create(**application_data)
|
||||
|
||||
@@ -33,6 +33,15 @@ APPLICATIONS = {
|
||||
"description_html": "<p>Slack Integration</p>",
|
||||
"redirect_uris": f"{settings.SILO_URL}/api/slack/plane-oauth/callback",
|
||||
},
|
||||
"sentry": {
|
||||
"key": "sentry",
|
||||
"name": "Sentry",
|
||||
"slug": "sentry",
|
||||
"short_description": "Sentry Integration",
|
||||
"description_html": "<p>Sentry Integration</p>",
|
||||
"redirect_uris": f"{settings.SILO_URL}/api/oauth/sentry/plane-oauth/callback",
|
||||
"webhook_url": f"{settings.SILO_URL}/api/sentry/plane/events",
|
||||
},
|
||||
"importer": {
|
||||
"key": "importer",
|
||||
"name": "Importer",
|
||||
|
||||
Reference in New Issue
Block a user