-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[WEB-5512]feat: workspace api tokens #8463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sangeethailango
wants to merge
31
commits into
preview
Choose a base branch
from
feat-workspace-api-tokens
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
64328f6
migration: added version field in webhook
sangeethailango 04ec99f
chore: add max_length
sangeethailango b028d83
feat: add API tokens management to workspace settings
b-saikrishnakanth ab47d4c
chore: added product tour fields
NarayanBavisetti 1d9390d
chore: updated the migration file
NarayanBavisetti e76d368
chore: removed the duplicated migration file
NarayanBavisetti 56a41a8
chore: added allowed_rate_limit for api_tokens
sangeethailango 10f4418
Merge branch 'preview' of github.com:makeplane/plane into migration-w…
NarayanBavisetti 9cc3f81
chore: changed key feature tour to product tour
NarayanBavisetti 07cf029
Merge branch 'migration-webhook' of github.com:makeplane/plane into m…
NarayanBavisetti 0bf6e1c
feat: implement workspace-specific API token management
pablohashescobar 42d5407
chore: separate rate limit class for workspace api token
sangeethailango d21f106
chore: set header
sangeethailango 0a20a47
feat: add API tokens management to workspace settings
b-saikrishnakanth bc52fa1
chore: workspace api token permission check
sangeethailango 97e18f5
fix: workspace tokens are returned in user tokens
sangeethailango b031dea
fix: expired_at set as a read only field
sangeethailango 466bccc
chore: added translations
vamsikrishnamathala 1705037
Merge branch 'feat-workspace-api-tokens' of github.com:makeplane/plan…
sangeethailango ae0550e
merge preview
sangeethailango 26eba89
fix: error handling for APIToken not exist
sangeethailango 0fd1f66
fix: error handling for APIToken not exist
sangeethailango a2fcc06
chore: added is_subscribed_to_changelog field
sangeethailango 42f060b
Merge branch 'migration-webhook' into feat-workspace-api-tokens
sangeethailango 5004073
merge preview
sangeethailango 3a5d01c
chore: updated routes and headings
vamsikrishnamathala a32412e
Merge branch 'feat-workspace-api-tokens' of github.com:makeplane/plan…
vamsikrishnamathala fea647d
Merge branch 'preview' of github.com:makeplane/plane into feat-worksp…
vamsikrishnamathala d3911dc
chore: removed event capture
vamsikrishnamathala 03e2c5a
fix: error handling
sangeethailango f1ae07e
chore: Resolver404 error handling
sangeethailango File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .base import ApiTokenEndpoint | ||
| from .service import ServiceApiTokenEndpoint | ||
| from .workspace import WorkspaceAPITokenEndpoint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Python import | ||
| from uuid import uuid4 | ||
|
|
||
| # Third party | ||
| from rest_framework.response import Response | ||
| from rest_framework.request import Request | ||
| from rest_framework import status | ||
|
|
||
| # Module import | ||
| from .base import BaseAPIView | ||
| from plane.db.models import APIToken, Workspace | ||
| from plane.app.permissions import WorkspaceEntityPermission | ||
|
|
||
|
|
||
| class ServiceApiTokenEndpoint(BaseAPIView): | ||
| permission_classes = [WorkspaceEntityPermission] | ||
|
|
||
| def post(self, request: Request, slug: str) -> Response: | ||
| workspace = Workspace.objects.get(slug=slug) | ||
|
|
||
| api_token = APIToken.objects.filter(workspace=workspace, is_service=True).first() | ||
|
|
||
| if api_token: | ||
| return Response({"token": str(api_token.token)}, status=status.HTTP_200_OK) | ||
sangeethailango marked this conversation as resolved.
Show resolved
Hide resolved
sangeethailango marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: | ||
| # Check the user type | ||
| user_type = 1 if request.user.is_bot else 0 | ||
|
|
||
| api_token = APIToken.objects.create( | ||
| label=str(uuid4().hex), | ||
| description="Service Token", | ||
| user=request.user, | ||
| workspace=workspace, | ||
| user_type=user_type, | ||
| is_service=True, | ||
| ) | ||
| return Response({"token": str(api_token.token)}, status=status.HTTP_201_CREATED) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Python import | ||
| from typing import Optional | ||
| from uuid import uuid4 | ||
|
|
||
|
|
||
| # Third party | ||
| from rest_framework.response import Response | ||
| from rest_framework.request import Request | ||
| from rest_framework import status | ||
|
|
||
| # Module import | ||
| from plane.app.views import BaseAPIView | ||
| from plane.db.models import APIToken, Workspace | ||
| from plane.app.serializers import APITokenSerializer, APITokenReadSerializer | ||
| from plane.app.permissions import WorkSpaceAdminPermission | ||
|
|
||
|
|
||
| class WorkspaceAPITokenEndpoint(BaseAPIView): | ||
| permission_classes = [ | ||
| WorkSpaceAdminPermission, | ||
| ] | ||
|
|
||
| def post(self, request: Request, slug: str) -> Response: | ||
| label = request.data.get("label", str(uuid4().hex)) | ||
| description = request.data.get("description", "") | ||
| expired_at = request.data.get("expired_at", None) | ||
|
|
||
| # Check the user type | ||
| user_type = 1 if request.user.is_bot else 0 | ||
|
|
||
| workspace = Workspace.objects.get(slug=slug) | ||
|
|
||
| api_token = APIToken.objects.create( | ||
| label=label, | ||
| description=description, | ||
| user=request.user, | ||
| user_type=user_type, | ||
| expired_at=expired_at, | ||
| workspace=workspace, | ||
| ) | ||
|
|
||
| serializer = APITokenSerializer(api_token) | ||
|
|
||
| return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
sangeethailango marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def get(self, request: Request, slug: str, pk: Optional[str] = None) -> Response: | ||
| if pk is None: | ||
| api_tokens = APIToken.objects.filter(workspace__slug=slug, is_service=False, user=request.user) | ||
|
|
||
| serializer = APITokenReadSerializer(api_tokens, many=True) | ||
| return Response(serializer.data, status=status.HTTP_200_OK) | ||
| else: | ||
| try: | ||
| api_tokens = APIToken.objects.get(workspace__slug=slug, pk=pk, user=request.user) | ||
| except APIToken.DoesNotExist: | ||
| return Response({"error": "API token does not exist"}, status=status.HTTP_404_NOT_FOUND) | ||
|
|
||
| serializer = APITokenReadSerializer(api_tokens) | ||
| return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
|
||
| def delete(self, request: Request, slug: str, pk: str) -> Response: | ||
| try: | ||
| api_token = APIToken.objects.get(workspace__slug=slug, pk=pk, is_service=False, user=request.user) | ||
| except APIToken.DoesNotExist: | ||
| return Response({"error": "API token does not exist"}, status=status.HTTP_404_NOT_FOUND) | ||
|
|
||
| api_token.delete() | ||
| return Response(status=status.HTTP_204_NO_CONTENT) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.