forked from github/plane
dev: initiate cron
This commit is contained in:
parent
7a550dd2f7
commit
cc82fae0e1
@ -1,2 +1,13 @@
|
|||||||
from .workspace import WorkSpaceBasePermission, WorkSpaceAdminPermission, WorkspaceEntityPermission, WorkspaceViewerPermission
|
from .workspace import (
|
||||||
from .project import ProjectBasePermission, ProjectEntityPermission, ProjectMemberPermission, ProjectLitePermission
|
WorkspaceOwnerPermission,
|
||||||
|
WorkSpaceBasePermission,
|
||||||
|
WorkSpaceAdminPermission,
|
||||||
|
WorkspaceEntityPermission,
|
||||||
|
WorkspaceViewerPermission,
|
||||||
|
)
|
||||||
|
from .project import (
|
||||||
|
ProjectBasePermission,
|
||||||
|
ProjectEntityPermission,
|
||||||
|
ProjectMemberPermission,
|
||||||
|
ProjectLitePermission,
|
||||||
|
)
|
||||||
|
@ -12,6 +12,20 @@ Member = 10
|
|||||||
Guest = 5
|
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
|
# TODO: Move the below logic to python match - python v3.10
|
||||||
class WorkSpaceBasePermission(BasePermission):
|
class WorkSpaceBasePermission(BasePermission):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
|
@ -12,21 +12,29 @@ from rest_framework.response import Response
|
|||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.api.views.base import BaseAPIView
|
from plane.api.views.base import BaseAPIView
|
||||||
|
from plane.api.permissions import WorkspaceOwnerPermission
|
||||||
from plane.db.models import Workspace, WorkspaceMember
|
from plane.db.models import Workspace, WorkspaceMember
|
||||||
from plane.license.models import License
|
from plane.license.models import License
|
||||||
|
|
||||||
|
|
||||||
class CheckoutEndpoint(BaseAPIView):
|
class CheckoutEndpoint(BaseAPIView):
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
WorkspaceOwnerPermission,
|
||||||
|
]
|
||||||
|
|
||||||
def post(self, request, slug):
|
def post(self, request, slug):
|
||||||
LICENSE_ENGINE_BASE_URL = os.environ.get("LICENSE_ENGINE_BASE_URL", "")
|
LICENSE_ENGINE_BASE_URL = os.environ.get("LICENSE_ENGINE_BASE_URL", "")
|
||||||
|
|
||||||
license = License.objects.first()
|
license = License.objects.first()
|
||||||
|
|
||||||
if license is None:
|
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)
|
price_id = request.data.get("price_id", False)
|
||||||
|
metadata = request.data.get("metadata", {})
|
||||||
|
|
||||||
if not price_id:
|
if not price_id:
|
||||||
return Response(
|
return Response(
|
||||||
@ -35,7 +43,9 @@ class CheckoutEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
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 = {
|
payload = {
|
||||||
"user": {
|
"user": {
|
||||||
@ -50,6 +60,7 @@ class CheckoutEndpoint(BaseAPIView):
|
|||||||
"slug": str(slug),
|
"slug": str(slug),
|
||||||
},
|
},
|
||||||
"priceId": price_id,
|
"priceId": price_id,
|
||||||
|
"metadata": metadata,
|
||||||
"seats": total_workspace_members,
|
"seats": total_workspace_members,
|
||||||
"return_url": settings.WEB_URL,
|
"return_url": settings.WEB_URL,
|
||||||
}
|
}
|
||||||
@ -68,4 +79,7 @@ class CheckoutEndpoint(BaseAPIView):
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return Response(response.json(), status=status.HTTP_200_OK)
|
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,
|
||||||
|
)
|
||||||
|
@ -3,6 +3,9 @@ import os
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@ -51,6 +54,7 @@ class InstanceEndpoint(BaseAPIView):
|
|||||||
api_key=data.get("api_key"),
|
api_key=data.get("api_key"),
|
||||||
version=data.get("version"),
|
version=data.get("version"),
|
||||||
email=data.get("email"),
|
email=data.get("email"),
|
||||||
|
last_checked_at=timezone.now(),
|
||||||
)
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,8 @@ class ProductEndpoint(BaseAPIView):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(response.json())
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return Response(response.json(), status=status.HTTP_200_OK)
|
return Response(response.json(), status=status.HTTP_200_OK)
|
||||||
return Response(
|
return Response(
|
||||||
|
0
apiserver/plane/license/bgtasks/__init__.py
Normal file
0
apiserver/plane/license/bgtasks/__init__.py
Normal file
7
apiserver/plane/license/bgtasks/license_task.py
Normal file
7
apiserver/plane/license/bgtasks/license_task.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from celery import shared_task
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def license_check_task():
|
||||||
|
pass
|
||||||
|
|
@ -11,6 +11,7 @@ class License(BaseModel):
|
|||||||
api_key = models.CharField(max_length=16)
|
api_key = models.CharField(max_length=16)
|
||||||
version = models.CharField(max_length=10)
|
version = models.CharField(max_length=10)
|
||||||
email = models.CharField(max_length=256)
|
email = models.CharField(max_length=256)
|
||||||
|
# last_checked_at = models.DateTimeField(null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "License"
|
verbose_name = "License"
|
||||||
|
Loading…
Reference in New Issue
Block a user