Repository navigation
fix(club,project): 清理解散社团视图并支持教师导师 #238
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| using System.Net.Http.Headers; | ||
| using System.Text.Json; | ||
| using ClubHub.Api.Data; | ||
| using ClubHub.Api.Data.Entities; | ||
| using ClubHub.Api.Services; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace ClubHub.Api.Tests; | ||
|
|
||
| public sealed class ClubVisibilityTests : IClassFixture<ClubHubWebApplicationFactory> | ||
| { | ||
| private readonly ClubHubWebApplicationFactory _factory; | ||
| private static int _sequence; | ||
|
|
||
| public ClubVisibilityTests(ClubHubWebApplicationFactory factory) => _factory = factory; | ||
|
|
||
| [Fact] | ||
| public async Task PublicClubList_ExcludesUnapprovedOrInactiveClubs() | ||
| { | ||
| var baseId = 9_300_000 + Interlocked.Increment(ref _sequence) * 10; | ||
| await using var scope = _factory.Services.CreateAsyncScope(); | ||
| var db = scope.ServiceProvider.GetRequiredService<ClubHubDbContext>(); | ||
| db.Clubs.AddRange( | ||
| new Club | ||
| { | ||
| ClubId = baseId, | ||
| ClubName = "可见运营社团", | ||
| AuditStatus = "approved", | ||
| ClubStatus = "active", | ||
| CreatedAt = DateTime.UtcNow | ||
| }, | ||
| new Club | ||
| { | ||
| ClubId = baseId + 1, | ||
| ClubName = "已解散社团", | ||
| AuditStatus = "approved", | ||
| ClubStatus = "inactive", | ||
| CreatedAt = DateTime.UtcNow | ||
| }, | ||
| new Club | ||
| { | ||
| ClubId = baseId + 2, | ||
| ClubName = "待审核社团", | ||
| AuditStatus = "pending", | ||
| ClubStatus = "pending", | ||
| CreatedAt = DateTime.UtcNow | ||
| }); | ||
| await db.SaveChangesAsync(); | ||
|
|
||
| using var client = _factory.CreateClient(); | ||
| using var response = await client.GetAsync("/api/v1/clubs"); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
| using var body = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); | ||
| var names = body.RootElement.EnumerateArray() | ||
| .Select(club => club.GetProperty("name").GetString()) | ||
| .ToArray(); | ||
| Assert.Contains("可见运营社团", names); | ||
| Assert.DoesNotContain("已解散社团", names); | ||
| Assert.DoesNotContain("待审核社团", names); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task MemberClubList_ExcludesDissolvedClubFromOperationalWorkspaces() | ||
| { | ||
| var baseId = 9_301_000 + Interlocked.Increment(ref _sequence) * 10; | ||
| await using var scope = _factory.Services.CreateAsyncScope(); | ||
| var db = scope.ServiceProvider.GetRequiredService<ClubHubDbContext>(); | ||
| var now = DateTime.UtcNow; | ||
| db.Users.Add(new User | ||
| { | ||
| UserId = baseId, | ||
| Username = $"club-visibility-user-{baseId}", | ||
| PasswordHash = "unused", | ||
| RealName = "社团可见性测试用户", | ||
| AccountStatus = "normal", | ||
| CreatedAt = now | ||
| }); | ||
| db.Clubs.AddRange( | ||
| new Club | ||
| { | ||
| ClubId = baseId + 1, | ||
| ClubName = "成员可见运营社团", | ||
| AuditStatus = "approved", | ||
| ClubStatus = "active", | ||
| CreatedAt = now | ||
| }, | ||
| new Club | ||
| { | ||
| ClubId = baseId + 2, | ||
| ClubName = "成员不可见解散社团", | ||
| AuditStatus = "approved", | ||
| ClubStatus = "inactive", | ||
| CreatedAt = now | ||
| }); | ||
| db.ClubMembers.AddRange( | ||
| new ClubMember | ||
| { | ||
| MemberId = baseId + 3, | ||
| ClubId = baseId + 1, | ||
| UserId = baseId, | ||
| MemberStatus = "active", | ||
| TermStart = now.AddDays(-1), | ||
| TermEnd = now.AddDays(30) | ||
| }, | ||
| new ClubMember | ||
| { | ||
| MemberId = baseId + 4, | ||
| ClubId = baseId + 2, | ||
| UserId = baseId, | ||
| MemberStatus = "active", | ||
| TermStart = now.AddDays(-1), | ||
| TermEnd = now.AddDays(30) | ||
| }); | ||
| await db.SaveChangesAsync(); | ||
|
|
||
| var token = scope.ServiceProvider.GetRequiredService<AuthTokenService>().CreateToken( | ||
| new User { UserId = baseId, Username = $"club-visibility-user-{baseId}" }); | ||
| using var client = _factory.CreateClient(); | ||
| client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
| using var response = await client.GetAsync("/api/v1/clubs"); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
| using var body = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); | ||
| var names = body.RootElement.EnumerateArray() | ||
| .Select(club => club.GetProperty("name").GetString()) | ||
| .ToArray(); | ||
| Assert.Contains("成员可见运营社团", names); | ||
| Assert.DoesNotContain("成员不可见解散社团", names); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
统一导师资格判定。
Line 169-170 使用
TEACHER或ADVISOR角色筛选候选人。backend/Controllers/ProjectMembersController.csLine 152-155 使用五位数字StudentNo判定教师。账号正常且工号有效、但未分配这两个角色的教师可以直接调用 POST 添加,却不会出现在候选列表。反之,角色记录不满足工号规则时,候选列表会返回最终被 POST 拒绝的用户。选择一个权威教师资格规则,并让候选查询与添加校验复用该规则。若角色代码是权威来源,可将校验收敛到服务层:
建议修改
🤖 Prompt for AI Agents