Skip to content

Dev#196

Merged
RokuSennyou merged 164 commits into
mainfrom
dev
Dec 30, 2025
Merged

Dev#196
RokuSennyou merged 164 commits into
mainfrom
dev

Conversation

@RokuSennyou
Copy link
Copy Markdown
Member

This pull request introduces several new features and improvements across the codebase, with a focus on assignments and announcements functionality. Key highlights include the addition of IP whitelist support for assignments, expanded serializer and API test coverage, and adjustments to authentication handling for consistency. Below are the most important changes grouped by theme:

Assignments: IP Whitelist & Serializer Enhancements

  • Added an ip_whitelist field to the Assignments model, including a custom validate_cidr_whitelist validator and corresponding database migration. This allows specifying allowed IP ranges for assignment access. [1] [2] [3]
  • Expanded assignment serializers: added fields such as max_attempts with validation, improved scoreboard and stats serializers, and fixed several field types for better API consistency. [1] [2] [3] [4] [5] [6] [7] [8]
  • Introduced assignments/tests/test_assignments_api.py with tests for creating, retrieving, updating, and listing assignments, improving API reliability.

Announcements: API Test Coverage & Permissions

  • Added announcements/tests/test_announcements_api.py with comprehensive tests for listing, retrieving, creating, updating, and deleting announcements, including permission checks for teacher and student roles.
  • Removed redundant permission_classes declarations from announcement views to rely on global defaults, reducing code duplication and centralizing permission logic. [1] [2]

API Authentication & User Serializers

  • Commented out explicit authentication_classes and permission_classes in API token and user activity views to use global default authentication, simplifying configuration and ensuring consistency. [1] [2] [3] [4]
  • Enhanced the MeSerializer to include an access_course field, listing all courses where the user is a TA or teacher, improving user context in API responses. [1] [2]

Miscellaneous Improvements

  • Updated the ForgotPasswordSerializer to require an email field, strengthening password reset security.
  • Adjusted the deployment workflow trigger branches in .github/workflows/deploy.yml to reflect recent branch naming changes.

noyapoyo and others added 30 commits December 25, 2025 00:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds custom checker support to problem settings
feat: Adds database seeding management command for demo data
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
feat: Adds database seeding management command with demo data
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ons-assignments

fix: remove per-view IsAuthenticated to enforce email verification
happylittle7 and others added 26 commits December 29, 2025 01:40
Fix quota enforcement race conditions and transaction safety
Refines user submission quota enforcement logic
… into helper functions

Co-authored-by: happylittle7 <7501374+happylittle7@users.noreply.github.com>
Refactor: Extract duplicated static analysis and network config logic
fix: align homework scoreboard response keys with frontend
…置的 authentication_classes (auths, api_tokens, copycat)\n2. 實現 copycat 管理員特權 - 允許 superuser 訪問所有課程報告\n3. 修復所有 RBAC 測試:\n - 使用 JWT token 認證替代 force_authenticate\n - 正確創建 UserProfile 並設置 email_verified\n - 修正測試數據欄位名稱和值\n\n測試結果:\n- auths: 9/9 通過 (100%)\n- copycat: 13/13 通過 (100%)\n- 整體:28/34 通過 (82.4%,剩餘為 api-tokens 已知問題)
…eld 改為 IntegerField\n- 修正 homework scoreboard 欄位命名\n- 添加 Course_members import 修復 NameError
Copilot AI review requested due to automatic review settings December 29, 2025 02:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces several new features and improvements across the codebase, with a focus on assignments, announcements, submissions, and enhanced test coverage. Key highlights include:

  • Added comprehensive test coverage for RBAC, API tokens, submissions, and copycat detection
  • Implemented IP whitelist support and submission quota enforcement
  • Enhanced submission callback handling with better error diagnostics
  • Added database seeding command for development and testing
  • Improved static analysis and custom checker settings for problems
  • Enhanced API documentation with updated field descriptions

Reviewed changes

Copilot reviewed 67 out of 68 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
user/management/commands/seed_data.py New Django management command for seeding test data with demo users, courses, problems, and submissions
tests/rbac_tests/*.py New comprehensive RBAC test suites for authentication, API tokens, and copycat detection
submissions/views.py Enhanced with IP filtering, rate limiting, quota enforcement, and improved callback handling
submissions/test_file/*.py New and updated test files for submission flows, callbacks, and sandbox integration
submissions/models.py Updated SubmissionResult with composite primary key and compile_error status support
submissions/serializers.py Simplified Editorial serializers by removing title and other fields
submissions/sandbox_client.py Enhanced with static analysis and network configuration support
problems/views/api.py Added testcase hash support, improved meta.json generation, and enhanced permission handling
problems/models.py Added custom checker, static analysis rules, and network whitelist support
problems/migrations/*.py Database migrations for new problem features
problems/tests/test_api.py Extended tests for custom checkers, static analysis, and testcase uploads
docs/*.MD Updated documentation for user authentication and submission APIs
courses/views/*.py Removed redundant permission_classes declarations to use global defaults
search/tests/test_search_api.py New API tests for search functionality
profiles/tests/test_profiles_api.py New API tests for profile views
Comments suppressed due to low confidence (9)

submissions/views.py:616

  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:771
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:1390
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:1394
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:1586
  • This import of module logging is redundant, as it was previously imported on line 15.
    submissions/views.py:1769
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:1905
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:1954
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.
    submissions/views.py:2209
  • This import of module logging is redundant, as it was previously imported on line 15.
    This import of module logging is redundant, as it was previously imported on line 1586.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

url = reverse('announcements:course', kwargs={'course_id': self.course.id})
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(len(response.data['data']) >= 1)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

assertTrue(a >= b) cannot provide an informative message. Using assertGreaterEqual(a, b) instead will give more informative messages.

Suggested change
self.assertTrue(len(response.data['data']) >= 1)
self.assertGreaterEqual(len(response.data['data']), 1)

Copilot uses AI. Check for mistakes.
# Check if wrapped in api_response or similar
# If response.data is list or dict with data
data = response.data.get('data', response.data)
self.assertTrue(len(data) > 0)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

assertTrue(a > b) cannot provide an informative message. Using assertGreater(a, b) instead will give more informative messages.

Suggested change
self.assertTrue(len(data) > 0)
self.assertGreater(len(data), 0)

Copilot uses AI. Check for mistakes.
results = data['results']
else:
results = data
self.assertTrue(len(results) > 0)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

assertTrue(a > b) cannot provide an informative message. Using assertGreater(a, b) instead will give more informative messages.

Copilot uses AI. Check for mistakes.
# 確認 Django 伺服器正在運行
print_section("檢查 Django 伺服器")
try:
response = requests.get(f"{BACKEND_URL}/", timeout=5)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Variable response is not used.

Copilot uses AI. Check for mistakes.
except requests.RequestException as e:
print_error(f"無法連接到 Django Server: {str(e)}")
print_warning("請先啟動 Django Server: python manage.py runserver")
response = requests.get(f"{BACKEND_URL}/", timeout=5)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Variable response is not used.

Copilot uses AI. Check for mistakes.
Comment thread submissions/views.py
except Exception as e:
# 其他系統錯誤
return api_response(data=None, message="invalid data!", status_code=status.HTTP_400_BAD_REQUEST)
import logging
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

This import of module logging is redundant, as it was previously imported on line 15.
This import of module logging is redundant, as it was previously imported on line 1586.

Copilot uses AI. Check for mistakes.

try:
submit_to_sandbox(mock_submission)
except:
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Except block directly handles BaseException.

Copilot uses AI. Check for mistakes.
Comment thread submissions/views.py
try:
profile = user.userprofile
avatar_url = profile.avatar.url if profile.avatar else None
except:
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Except block directly handles BaseException.

Copilot uses AI. Check for mistakes.
try:
if _storage.exists(rel):
_storage.delete(rel)
except Exception:
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
Comment thread submissions/views.py
except (ValueError, TypeError) as e:
logger = logging.getLogger(__name__)
logger.warning(f'Invalid ip_prefix parameter: {ip_prefix}, error: {e}')
pass # 忽略無效的 IP 前綴
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Unnecessary 'pass' statement.

Copilot uses AI. Check for mistakes.
@RokuSennyou RokuSennyou merged commit 413badc into main Dec 30, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants