diff --git a/apiserver/bin/instance_registration.py b/apiserver/bin/instance_registration.py index 3cd7b9c37..2d838af74 100644 --- a/apiserver/bin/instance_registration.py +++ b/apiserver/bin/instance_registration.py @@ -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: diff --git a/apiserver/plane/license/api/permissions/__init__.py b/apiserver/plane/license/api/permissions/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/apiserver/plane/license/api/permissions/instance.py b/apiserver/plane/license/api/permissions/instance.py new file mode 100644 index 000000000..e69de29bb diff --git a/apiserver/plane/license/api/serializers/instance.py b/apiserver/plane/license/api/serializers/instance.py index 47093b676..aab4b9c90 100644 --- a/apiserver/plane/license/api/serializers/instance.py +++ b/apiserver/plane/license/api/serializers/instance.py @@ -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", diff --git a/apiserver/plane/license/api/views/instance.py b/apiserver/plane/license/api/views/instance.py index 901758dd2..4a812b5c6 100644 --- a/apiserver/plane/license/api/views/instance.py +++ b/apiserver/plane/license/api/views/instance.py @@ -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: + + \ No newline at end of file diff --git a/apiserver/plane/license/models/__init__.py b/apiserver/plane/license/models/__init__.py index 603ecb7af..28f2c4352 100644 --- a/apiserver/plane/license/models/__init__.py +++ b/apiserver/plane/license/models/__init__.py @@ -1 +1 @@ -from .instance import Instance, InstanceConfiguration \ No newline at end of file +from .instance import Instance, InstanceAdmin, InstanceConfiguration \ No newline at end of file diff --git a/apiserver/plane/license/models/instance.py b/apiserver/plane/license/models/instance.py index cdef23f8c..f5af2195b 100644 --- a/apiserver/plane/license/models/instance.py +++ b/apiserver/plane/license/models/instance.py @@ -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