Skip to content

Commit d19699f

Browse files
authored
[SILO-269] Migration for SILO's Importer App (#3232)
* add importer app create migration for silo importers * add silo logger to log settings
1 parent 2cb3ec9 commit d19699f

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

apiserver/plane/settings/production.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
"handlers": ["console"],
8888
"propagate": False,
8989
},
90+
"plane.silo": {
91+
"level": "DEBUG" if DEBUG else "INFO",
92+
"handlers": ["console"],
93+
"propagate": False,
94+
},
9095
},
9196
}
9297

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated by Django 4.2.20 on 2025-05-21 08:39
2+
3+
from django.db import migrations
4+
5+
6+
def create_importer_app(apps, schema_editor):
7+
# Getting the models from apps to avoid circular imports
8+
Application = apps.get_model("authentication", "Application")
9+
ApplicationSecret = apps.get_model("silo", "ApplicationSecret")
10+
User = apps.get_model("db", "User")
11+
InstanceAdmin = apps.get_model("license", "InstanceAdmin")
12+
13+
# Importing the function and constants directly here to avoid circular imports
14+
from plane.silo.services.generate_application import generate_application
15+
from plane.silo.utils.constants import APPLICATIONS
16+
17+
# Getting the first instance admin
18+
instance_admin = InstanceAdmin.objects.first()
19+
if instance_admin:
20+
generate_application(
21+
user_id=instance_admin.user.id,
22+
app_key=APPLICATIONS["importer"]["key"],
23+
application_model=Application,
24+
application_secret_model=ApplicationSecret,
25+
user_model=User
26+
)
27+
28+
class Migration(migrations.Migration):
29+
30+
dependencies = [
31+
('silo', '0002_create_apps'),
32+
]
33+
34+
operations = [
35+
migrations.RunPython(create_importer_app, reverse_code=migrations.RunPython.noop)
36+
]

apiserver/plane/silo/services/generate_application.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def generate_application(
3030
adds the application owner to the application
3131
and create a new application secret
3232
"""
33+
34+
# check if application secret already exists skip if it does
35+
if application_secret_model.objects.filter(key=f"x-{app_key}-id").exists():
36+
logger.info(f"Application for {app_key} already exists, skipping...")
37+
return None
38+
3339
app_data = APPLICATIONS[app_key]
3440
app_slug = app_data["slug"]
3541
user = user_model.objects.get(id=user_id)
@@ -101,14 +107,11 @@ def create_applications(
101107
user_model = user_model or User
102108
# create applications
103109
for app_key in APPLICATIONS.keys():
104-
if not application_secret_model.objects.filter(key=f"x-{app_key}-id").exists():
105-
logger.info(f"Creating application for {app_key}")
106-
generate_application(
107-
user_id,
108-
app_key,
109-
application_model,
110-
application_secret_model,
111-
user_model,
112-
)
113-
else:
114-
logger.info(f"Application for {app_key} already exists, skipping...")
110+
logger.info(f"Creating application for {app_key}")
111+
generate_application(
112+
user_id,
113+
app_key,
114+
application_model,
115+
application_secret_model,
116+
user_model,
117+
)

apiserver/plane/silo/utils/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
APPLICATIONS = {
22
"github": {
3+
"key": "github",
34
"name": "Github",
45
"slug": "silo-github",
56
"short_description": "Github Integration",
67
"description_html": "<p>Github Integration</p>",
78
},
89
"gitlab": {
10+
"key": "gitlab",
911
"name": "Gitlab",
1012
"slug": "silo-gitlab",
1113
"short_description": "Gitlab Integration",
1214
"description_html": "<p>Gitlab Integration</p>",
1315
},
1416
"slack": {
17+
"key": "slack",
1518
"name": "Slack",
1619
"slug": "silo-slack",
1720
"short_description": "Slack Integration",
1821
"description_html": "<p>Slack Integration</p>",
1922
},
2023
"jira": {
24+
"key": "jira",
2125
"name": "Jira",
2226
"slug": "silo-jira",
2327
"short_description": "Jira Importer",
@@ -30,15 +34,24 @@
3034
"description_html": "<p>Jira Server Importer</p>",
3135
},
3236
"linear": {
37+
"key": "linear",
3338
"name": "Linear",
3439
"slug": "silo-linear",
3540
"short_description": "Linear Importer",
3641
"description_html": "<p>Linear Importer</p>",
3742
},
3843
"asana": {
44+
"key": "asana",
3945
"name": "Asana",
4046
"slug": "silo-asana",
4147
"short_description": "Asana Importer",
4248
"description_html": "<p>Asana Importer</p>",
4349
},
50+
"importer": {
51+
"key": "importer",
52+
"name": "Importer",
53+
"slug": "silo-importer",
54+
"short_description": "Importer",
55+
"description_html": "<p>Importer</p>",
56+
},
4457
}

0 commit comments

Comments
 (0)