dev: instance admin

This commit is contained in:
pablohashescobar 2023-11-14 09:08:24 +00:00
parent aca0f5eadb
commit 1eac8ead86
7 changed files with 38 additions and 5 deletions

View File

@ -21,7 +21,7 @@ def instance_registration():
try:
# Module imports
from plane.db.models import User
from plane.license.models import Instance
from plane.license.models import Instance, InstanceAdmin
# Check if the instance is registered
instance = Instance.objects.first()
@ -66,18 +66,26 @@ def instance_registration():
if response.status_code == 201:
data = response.json()
# Create instance
instance = Instance.objects.create(
instance_name="Plane Free",
instance_id=data.get("id"),
license_key=data.get("license_key"),
api_key=data.get("api_key"),
version=0.1,
version=data.get("version"),
email=data.get("email"),
owner=user,
last_checked_at=timezone.now(),
)
# Create instance admin
_ = InstanceAdmin.objects.create(
user=user,
instance=instance,
)
print(f"Instance succesfully registered with owner: {instance.owner.email}")
return
print("Instance could not be registered")
return
else:

View File

@ -5,14 +5,14 @@ from plane.api.serializers import UserAdminLiteSerializer
class InstanceSerializer(BaseSerializer):
user_details = UserAdminLiteSerializer(source="user", read_only=True)
owner_details = UserAdminLiteSerializer(source="owner", read_only=True)
class Meta:
model = Instance
fields = "__all__"
read_only_fields = [
"id",
"user",
"owner",
"instance_id",
"license_key",
"api_key",

View File

@ -79,3 +79,13 @@ class TransferOwnerEndpoint(BaseAPIView):
return Response(
{"message": "Owner successfully updated"}, status=status.HTTP_200_OK
)
class InstanceAdminEndpoint(BaseAPIView):
def get(self, request, pk=None):
instance = Instance.objects.first()
if instance is None:

View File

@ -1 +1 @@
from .instance import Instance, InstanceConfiguration
from .instance import Instance, InstanceAdmin, InstanceConfiguration

View File

@ -36,6 +36,21 @@ class Instance(BaseModel):
ordering = ("-created_at",)
class InstanceAdmin(BaseModel):
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,
null=True,
related_name="instance_owner",
)
instance = models.ForeignKey("db.Instance", on_delete=models.CASCADE, related_name="admins")
class Meta:
verbose_name = "Instance Admin"
verbose_name_plural = "Instance Admins"
db_table = "instance_admins"
ordering = ("-created_at",)
class InstanceConfiguration(BaseModel):
# The instance configuration variables