forked from github/plane
feat: segregate api token workspace
This commit is contained in:
parent
e1b7e8d139
commit
0b7f0640c9
@ -15,12 +15,16 @@ from plane.api.serializers import APITokenSerializer
|
||||
class ApiTokenEndpoint(BaseAPIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
|
||||
label = request.data.get("label", str(uuid4().hex))
|
||||
workspace = request.data.get("workspace", False)
|
||||
|
||||
if not workspace:
|
||||
return Response(
|
||||
{"error": "Workspace is required"}, status=status.HTTP_200_OK
|
||||
)
|
||||
|
||||
api_token = APIToken.objects.create(
|
||||
label=label,
|
||||
user=request.user,
|
||||
label=label, user=request.user, workspace=workspace
|
||||
)
|
||||
|
||||
serializer = APITokenSerializer(api_token)
|
||||
|
@ -17,7 +17,6 @@ def generate_token():
|
||||
|
||||
|
||||
class APIToken(BaseModel):
|
||||
|
||||
token = models.CharField(max_length=255, unique=True, default=generate_token)
|
||||
label = models.CharField(max_length=255, default=generate_label_token)
|
||||
user = models.ForeignKey(
|
||||
@ -28,6 +27,9 @@ class APIToken(BaseModel):
|
||||
user_type = models.PositiveSmallIntegerField(
|
||||
choices=((0, "Human"), (1, "Bot")), default=0
|
||||
)
|
||||
workspace = models.ForeignKey(
|
||||
"db.workspace", related_name="api_tokens", on_delete=models.SET_NULL, null=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "API Token"
|
||||
|
Loading…
Reference in New Issue
Block a user