-
Notifications
You must be signed in to change notification settings - Fork 3
Explore page fix #715
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
Explore page fix #715
Changes from 23 commits
b7892c3
7c5043c
2152f17
3c89f57
00b81b9
7a2c92d
44db178
c187ffc
639c9ac
06dd3f4
e0edc9a
adc751c
d57a376
27071db
6cfa801
6119aad
39ee2f7
70fc307
bbdb589
884a28f
a89322a
2aed697
d823679
0f3263d
92f03b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Utils package |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||
| from app_users.models import AppUser | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def is_user_workspace_owner(user: AppUser | None, workspace_filter: str | None) -> bool: | ||||||||||||||||||||||||||||||||||||||
| """Check if the current user owns the filtered workspace.""" | ||||||||||||||||||||||||||||||||||||||
| if not (user and workspace_filter and not user.is_anonymous): | ||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| user_workspace_ids = {w.id for w in user.cached_workspaces} | ||||||||||||||||||||||||||||||||||||||
| user_workspace_handles = {w.handle.name for w in user.cached_workspaces if w.handle} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| # Check if workspace filter is numeric (workspace ID) | ||||||||||||||||||||||||||||||||||||||
| workspace_id = int(workspace_filter) | ||||||||||||||||||||||||||||||||||||||
| return workspace_id in user_workspace_ids | ||||||||||||||||||||||||||||||||||||||
| except ValueError: | ||||||||||||||||||||||||||||||||||||||
| # Workspace filter is a handle name | ||||||||||||||||||||||||||||||||||||||
| return workspace_filter in user_workspace_handles | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| try: | |
| # Check if workspace filter is numeric (workspace ID) | |
| workspace_id = int(workspace_filter) | |
| return workspace_id in user_workspace_ids | |
| except ValueError: | |
| # Workspace filter is a handle name | |
| return workspace_filter in user_workspace_handles | |
| try: | |
| # Check if workspace filter is numeric (workspace ID) | |
| workspace_id = int(workspace_filter) | |
| if workspace_id <= 0: | |
| return False | |
| return workspace_id in user_workspace_ids | |
| except (ValueError, TypeError): | |
| # Workspace filter is a handle name | |
| if not isinstance(workspace_filter, str) or not workspace_filter.strip(): | |
| return False | |
| return workspace_filter in user_workspace_handles |
🤖 Prompt for AI Agents
In utils/workspace.py around lines 12 to 18, improve the error handling by
adding input validation before attempting to convert workspace_filter to int,
and catch additional potential exceptions beyond ValueError. Validate that
workspace_filter is a string or appropriate type, and handle cases where it
might be None or an unexpected type, returning False or raising a clear error as
needed. Expand the except block to handle other exceptions that could arise
during conversion or membership checks to make the function more robust.
Uh oh!
There was an error while loading. Please reload this page.