Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/homepage/serializers/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def get_queryset(self, auth):
).exclude(chat_user_id="")

if name:
base_queryset = base_queryset.filter(asker__username__contains=name)
base_queryset = base_queryset.filter(asker__username__icontains=name)

# ---- 权限过滤 ----
base_queryset = self._apply_permission_filter(base_queryset, auth, workspace_id, user_id)
Expand Down Expand Up @@ -329,7 +329,7 @@ def export(self, auth, with_valid=True):
]
worksheet.append(row)
response = HttpResponse(content_type="application/vnd.ms-excel")
response["Content-Disposition"] = f'attachment; filename="data.xlsx"'
response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
workbook.save(response)
return response

Expand Down Expand Up @@ -400,9 +400,10 @@ def get_queryset(self, auth):
queryset = QuerySet(Application)
is_resource_filter = True
if name:
queryset = queryset.filter(name__contains=name)
queryset = queryset.filter(name__icontains=name)
if is_workspace_manage(auth, workspace_id):
queryset = queryset.filter(workspace_id=workspace_id)
is_resource_filter = False
elif is_extends_workspace_manage(auth, workspace_id):
if has_extends_workspace_manage_permission(
auth, PermissionConstants.APPLICATION_READ.value, workspace_id
Expand Down Expand Up @@ -500,7 +501,7 @@ def export(self, auth, with_valid=True):
]
worksheet.append(row)
response = HttpResponse(content_type="application/vnd.ms-excel")
response["Content-Disposition"] = f'attachment; filename="data.xlsx"'
response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
workbook.save(response)
return response

Expand Down Expand Up @@ -532,7 +533,7 @@ def get_queryset(self, auth):
is_resource_filter = True
queryset = QuerySet(Application)
if name:
queryset = queryset.filter(name__contains=name)
queryset = queryset.filter(name__icontains=name)
if is_workspace_manage(auth, workspace_id):
queryset = queryset.filter(workspace_id=workspace_id)
is_resource_filter = False
Expand Down Expand Up @@ -630,7 +631,7 @@ def export(self, auth, with_valid=True):
]
worksheet.append(row)
response = HttpResponse(content_type="application/vnd.ms-excel")
response["Content-Disposition"] = f'attachment; filename="data.xlsx"'
response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
workbook.save(response)
return response

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff

1. __contains → __icontains (lines 245, 400, 533)

Good change. Case-insensitive search is usually what users expect for a name filter.

⚠️ Potential issue: In PostgreSQL, icontains uses ILIKE '%...%', which cannot use a normal btree index. If these tables can become large, consider:

  • A pg_trgm GIN index on asker.username / name, or
  • Using full-text search (SearchVector) if search is a first-class feature.

Also note: Django's contains already escapes %/_, so no injection risk — just performance.

2. Content-Disposition f-string → plain string (lines 329, 500, 630)

Correct cleanup. The f-string has no placeholders, so removing it is safe and slightly faster/branch-free.

Minor suggestion: since a filename is being hardcoded repeatedly, consider extracting a constant or helper, e.g.:

def _xlsx_response(workbook):
    response = HttpResponse(content_type="application/vnd.ms-excel")
    response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
    workbook.save(response)
    return response

This removes triplicate code and ensures future header changes (e.g. adding RFC 5987 filename*=UTF-8''... for non-ASCII names) only need to happen once.

💡 The MIME type application/vnd.ms-excel is for legacy .xls. Since you're writing .xlsx via openpyxl, the correct type is:

"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

3. Added is_resource_filter = False (line ~408)

This aligns the branch with the sibling method at line ~536, where the same workspace_manage branch already sets the flag to False.

✅ Behavioral fix: when the user is a workspace manager, the extra "resource filter" step was previously still applied. Now it's skipped consistently. Confirm that this is intentional — before, managers were likely getting results filtered by _apply_resource_filter(...) even though they had full access, which would silently hide records. If tests exist for manager-scoped listing, they should be updated.

Summary table

Change Verdict Notes
icontains ×3 ✅ Add trigram/GIN index if tables grow
Drop f-string in header ✅ Factor out duplicate into helper
is_resource_filter = False ✅ (verify) Fixes inconsistency with sibling method
MIME type ⚠️ Should be xlsx-specific MIME

No correctness regressions spotted; the main open questions are the intent of the is_resource_filter change (tests?) and the MIME-type mismatch.

Expand Down
Loading