-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+43
−7
Merged
Dev #22
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d573339
feat: add template field for organization model
ngovinh2k2 8239272
Merge pull request #20 from Space-DF/feat/add-template-field-for-orga…
ngovinh2k2 d1e8789
fix: prevent crashing using itemgetter
ngovinh2k2 0121fd8
Merge pull request #21 from Space-DF/fix/prevent-crashing-using-itemg…
ngovinh2k2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/organization/migrations/0002_organization_template.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Generated by Django 5.0.6 on 2026-05-13 04:03 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("organization", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="organization", | ||
| name="template", | ||
| field=models.CharField( | ||
| blank=True, | ||
| choices=[ | ||
| ("smart_building", "Smart Building"), | ||
| ("smart_fleet_monitor", "Smart Fleet Monitor"), | ||
| ], | ||
| max_length=256, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import logging | ||
|
|
||
| from common.apps.organization.constants import OrganizationTemplate | ||
| from common.models.base_model import BaseModel | ||
| from django.core.exceptions import ValidationError | ||
| from django.core.validators import MinValueValidator | ||
|
|
@@ -32,3 +33,6 @@ class Organization(BaseModel): | |
| rabbitmq_provisioned_at = models.DateTimeField( | ||
| blank=True, null=True, help_text="When RabbitMQ resources were provisioned" | ||
| ) | ||
| template = models.CharField( | ||
| max_length=256, choices=OrganizationTemplate.choices, blank=True, null=True | ||
| ) | ||
|
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ def _get_config(self, **kwargs): | |
| return { | ||
| "org_name": kwargs.get("org_name") or os.getenv("ORG_NAME"), | ||
| "org_slug": kwargs.get("org_slug") or os.getenv("ORG_SLUG"), | ||
| "org_template": kwargs.get("org_template") or os.getenv("ORG_TEMPLATE"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "owner_email": kwargs.get("owner_email") or os.getenv("OWNER_EMAIL"), | ||
| "owner_password": kwargs.get("owner_password") | ||
| or os.getenv("OWNER_PASSWORD"), | ||
|
|
@@ -136,7 +137,7 @@ def _create_organization_with_roles(self, org_id, org_name, org_slug, result): | |
| self.stdout.write(self.style.SUCCESS("Created default roles")) | ||
| return organization, owner_role | ||
|
|
||
| def _send_celery_task(self, org_id, org_name, org_slug, user): | ||
| def _send_celery_task(self, org_id, org_name, org_slug, org_template, user): | ||
| """Send initialization task to Celery.""" | ||
| send_task( | ||
| name="new_organization", | ||
|
|
@@ -145,6 +146,7 @@ def _send_celery_task(self, org_id, org_name, org_slug, user): | |
| "name": org_name, | ||
| "slug_name": org_slug, | ||
| "is_active": True, | ||
| "template": org_template, | ||
| "owner": model_to_dict( | ||
| user, | ||
| fields=[ | ||
|
|
@@ -198,7 +200,11 @@ def _delete_organization(self, provisioner, organization): | |
|
|
||
| def handle(self, *args, **kwargs): | ||
| config = self._get_config(**kwargs) | ||
| org_name, org_slug = config["org_name"], config["org_slug"] | ||
| org_name, org_slug, org_template = ( | ||
| config["org_name"], | ||
| config["org_slug"], | ||
| config.get("org_template", ""), | ||
| ) | ||
| owner_email, owner_password = config["owner_email"], config["owner_password"] | ||
| encrypted_password = make_password(owner_password) | ||
| org_id = str(uuid.uuid4()) | ||
|
|
@@ -235,7 +241,7 @@ def handle(self, *args, **kwargs): | |
|
|
||
| # Publish organization event | ||
| self._publish_org_event(org_id, org_slug, org_name, result) | ||
| self._send_celery_task(org_id, org_name, org_slug, user) | ||
| self._send_celery_task(org_id, org_name, org_slug, org_template, user) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| else: | ||
| self.stdout.write( | ||
| self.style.WARNING( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing
emaildirectly fromuser_info_dictmay raise aKeyErrorif the key is missing from the provider's response. It is safer to use.get()and handle the missing value explicitly, for example by raising aValidationError.