Skip to content

Commit

Permalink
feat(organization)!: simplify organization detection for retrieving u…
Browse files Browse the repository at this point in the history
…sage metrics (#5332)

### 📣 Summary
Simplified the logic for detecting the organization when retrieving
project usage, storage, and NLP minutes.
Improved code readability and maintainability.


### 📖 Description
This PR refactors the organization detection logic used to retrieve
metrics such as project usage, storage, and NLP minutes. The simplified
makes the code easier to read and maintain.

The detection is now based on whether the organization is a Multi-Member
Organization (MMO). Additionally, it assumes that all projects belong
directly to the organization rather than its individual members.
  • Loading branch information
noliveleger authored Dec 9, 2024
1 parent 0bb717d commit c290b8e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions kobo/apps/organizations/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from django.db.models import (
QuerySet,
Case,
When,
Value,
CharField,
OuterRef,
)
from django.db.models import Case, CharField, OuterRef, QuerySet, Value, When
from django.db.models.expressions import Exists
from django.utils.http import http_date
from rest_framework import viewsets
Expand Down Expand Up @@ -102,7 +95,9 @@ def assets(self, request: Request, *args, **kwargs):
### Additional Information
For more details, please refer to `/api/v2/assets/`.
"""
organization = self.get_object() # Call check permissions

# `get_object()` checks permissions
organization = self.get_object()

# Permissions check is done by `OrganizationAssetViewSet` permission classes
asset_view = OrganizationAssetViewSet.as_view({'get': 'list'})
Expand Down Expand Up @@ -154,8 +149,8 @@ def service_usage(self, request, pk=None, *args, **kwargs):
> }
### CURRENT ENDPOINT
"""
self.get_object() # check permissions

self.get_object() # This call is necessary to check permissions
serializer = ServiceUsageSerializer(
get_database_user(request.user),
context=self.get_serializer_context(),
Expand Down Expand Up @@ -210,6 +205,7 @@ def asset_usage(self, request, pk=None, *args, **kwargs):
### CURRENT ENDPOINT
"""

# `get_object()` checks permissions
organization = self.get_object()

user_id = get_database_user(request.user).pk
Expand Down

0 comments on commit c290b8e

Please sign in to comment.