Skip to content

Commit

Permalink
fix: api keys wont create on team if you are the owner
Browse files Browse the repository at this point in the history
Signed-off-by: Trey <[email protected]>
  • Loading branch information
TreyWW committed Oct 19, 2024
1 parent e4189cd commit a25ce39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions backend/core/api/settings/api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from backend.core.service.permissions.scopes import get_permissions_from_request

from backend.core.types.requests import WebRequest
from backend.decorators import web_require_scopes


@require_http_methods(["POST"])
@web_require_scopes("api_keys:write")
def generate_api_key_endpoint(request: WebRequest) -> HttpResponse:
name = request.POST.get("name")
expiry = request.POST.get("expiry")
Expand Down
4 changes: 2 additions & 2 deletions backend/core/service/api_keys/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate_public_api_key(
if api_key_exists_under_name(owner, api_key_name):
return None, "A key with this name already exists in your account"

if validate_scopes(permissions).failed or not has_permission_to_create(request, owner):
if validate_scopes(permissions).failed: # or not has_permission_to_create(request, owner):
return None, "Invalid permissions"

administrator_service_type = None
Expand Down Expand Up @@ -105,6 +105,6 @@ def has_permission_to_create(request, owner: User | Organization) -> bool:
if isinstance(owner, User):
return True

if "api_keys:write" in owner.permissions.get(user=request.user).scopes:
if owner.permissions.filter(user=request.user).exists() and "api_keys:write" in owner.permissions.get(user=request.user).scopes:
return True
return False

0 comments on commit a25ce39

Please sign in to comment.