-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ffe8e9
commit 26442fd
Showing
11 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 @@ | ||
# TODO: split this into a private package? |
This file contains 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,19 @@ | ||
import typing | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class LicenceInformation(BaseModel): | ||
organisation_name: str | ||
plan_id: str | ||
|
||
department_name: typing.Optional[str] = None | ||
expiry_date: typing.Optional[datetime] = None | ||
|
||
# TODO: should these live in a nested object? | ||
num_seats: int | ||
num_projects: int # TODO: what about Flagsmith on Flagsmith project? | ||
num_api_calls: typing.Optional[ | ||
int | ||
] = None # required to support private cloud installs |
26 changes: 26 additions & 0 deletions
26
api/organisations/subscriptions/licensing/migrations/0001_initial.py
This file contains 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,26 @@ | ||
# Generated by Django 3.2.24 on 2024-03-15 15:52 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('organisations', '0052_create_hubspot_organisation'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='OrganisationLicence', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('content', models.TextField(blank=True)), | ||
('organisation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')), | ||
], | ||
), | ||
] |
Empty file.
This file contains 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,18 @@ | ||
from django.db import models | ||
|
||
from organisations.subscriptions.licensing.licensing import LicenceInformation | ||
|
||
|
||
class OrganisationLicence(models.Model): | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
organisation = models.OneToOneField( | ||
"organisations.Organisation", related_name="licence", on_delete=models.CASCADE | ||
) | ||
|
||
content = models.TextField(blank=True) | ||
|
||
def get_licence_information(self) -> LicenceInformation: | ||
# TODO: decryption | ||
return LicenceInformation.parse_raw(self.content) |
This file contains 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,20 @@ | ||
from rest_framework import serializers | ||
from rest_framework.decorators import api_view | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
from organisations.subscriptions.licensing.models import OrganisationLicence | ||
|
||
|
||
@api_view(http_method_names=["PUT"]) | ||
def create_or_update_licence( | ||
request: Request, organisation_id: int, **kwargs | ||
) -> Response: | ||
if "licence" not in request.FILES: | ||
raise serializers.ValidationError("No licence file provided.") | ||
|
||
OrganisationLicence.objects.update_or_create( | ||
organisation_id=organisation_id, | ||
defaults={"content": request.FILES["licence"].read().decode("utf-8")}, | ||
) | ||
return Response(200) |
This file contains 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
This file contains 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
This file contains 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