dev: initiate cron

This commit is contained in:
pablohashescobar 2023-10-27 15:41:25 +05:30
parent 7a550dd2f7
commit cc82fae0e1
8 changed files with 61 additions and 8 deletions

View File

@ -1,2 +1,13 @@
from .workspace import WorkSpaceBasePermission, WorkSpaceAdminPermission, WorkspaceEntityPermission, WorkspaceViewerPermission
from .project import ProjectBasePermission, ProjectEntityPermission, ProjectMemberPermission, ProjectLitePermission
from .workspace import (
WorkspaceOwnerPermission,
WorkSpaceBasePermission,
WorkSpaceAdminPermission,
WorkspaceEntityPermission,
WorkspaceViewerPermission,
)
from .project import (
ProjectBasePermission,
ProjectEntityPermission,
ProjectMemberPermission,
ProjectLitePermission,
)

View File

@ -12,6 +12,20 @@ Member = 10
Guest = 5
class WorkspaceOwnerPermission(BasePermission):
def has_permission(self, request, view):
if request.user.is_anonymous:
return False
return WorkspaceMember.objects.filter(
member=request.user,
workspace__slug=view.workspace_slug,
role__in=[
Owner,
],
).exists()
# TODO: Move the below logic to python match - python v3.10
class WorkSpaceBasePermission(BasePermission):
def has_permission(self, request, view):

View File

@ -12,21 +12,29 @@ from rest_framework.response import Response
# Module imports
from plane.api.views.base import BaseAPIView
from plane.api.permissions import WorkspaceOwnerPermission
from plane.db.models import Workspace, WorkspaceMember
from plane.license.models import License
class CheckoutEndpoint(BaseAPIView):
permission_classes = [
WorkspaceOwnerPermission,
]
def post(self, request, slug):
LICENSE_ENGINE_BASE_URL = os.environ.get("LICENSE_ENGINE_BASE_URL", "")
license = License.objects.first()
if license is None:
return Response({"error": "Instance is not activated"}, status=status.HTTP_403_FORBIDDEN)
return Response(
{"error": "Instance is not activated"}, status=status.HTTP_403_FORBIDDEN
)
price_id = request.data.get("price_id", False)
metadata = request.data.get("metadata", {})
if not price_id:
return Response(
@ -35,7 +43,9 @@ class CheckoutEndpoint(BaseAPIView):
)
workspace = Workspace.objects.get(slug=slug)
total_workspace_members = WorkspaceMember.objects.filter(workspace__slug=slug).count()
total_workspace_members = WorkspaceMember.objects.filter(
workspace__slug=slug, member__is_bot=False
).count()
payload = {
"user": {
@ -50,6 +60,7 @@ class CheckoutEndpoint(BaseAPIView):
"slug": str(slug),
},
"priceId": price_id,
"metadata": metadata,
"seats": total_workspace_members,
"return_url": settings.WEB_URL,
}
@ -68,4 +79,7 @@ class CheckoutEndpoint(BaseAPIView):
if response.status_code == 200:
return Response(response.json(), status=status.HTTP_200_OK)
return Response({"error": "Unable to create a checkout try again later"}, status=response.status_code)
return Response(
{"error": "Unable to create a checkout try again later"},
status=response.status_code,
)

View File

@ -3,6 +3,9 @@ import os
import json
import requests
# Django imports
from django.utils import timezone
# Third party imports
from rest_framework import status
from rest_framework.response import Response
@ -51,6 +54,7 @@ class InstanceEndpoint(BaseAPIView):
api_key=data.get("api_key"),
version=data.get("version"),
email=data.get("email"),
last_checked_at=timezone.now(),
)
return Response(
{

View File

@ -33,6 +33,8 @@ class ProductEndpoint(BaseAPIView):
headers=headers,
)
print(response.json())
if response.status_code == 200:
return Response(response.json(), status=status.HTTP_200_OK)
return Response(

View File

@ -0,0 +1,7 @@
from celery import shared_task
def license_check_task():
pass

View File

@ -11,6 +11,7 @@ class License(BaseModel):
api_key = models.CharField(max_length=16)
version = models.CharField(max_length=10)
email = models.CharField(max_length=256)
# last_checked_at = models.DateTimeField(null=True)
class Meta:
verbose_name = "License"