-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add support for limited partner colors and force refresh of guilds #562
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
stijnvdkolk
merged 10 commits into
main
from
feature/559-restrict-partner-colors-by-server-membership
May 19, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cf66fec
feat(backend): add support for limited partner colors and force refre…
stijnvdkolk 0bb9c2a
feat(frontend): recheck guild memberships and gate partner colors
stijnvdkolk cce499a
fix(frontend): prevent pointer capture on interactive controls in `Sl…
stijnvdkolk 04da1e8
fix(frontend): update messaging in SelectedColorInfoCard
stijnvdkolk 85dc86f
fix(frontend): update button accessibility and improve messaging in R…
stijnvdkolk d8a1a4b
fix(backend): improve mock response handling and ensure consistent ca…
stijnvdkolk 1f55241
feat(frontend): add lock badge to disabled swatch and enhance StaticS…
stijnvdkolk 9d25221
fix: styling
stijnvdkolk 788d708
refactor(frontend): enhance VisuallyHidden component and update styli…
stijnvdkolk af0d10b
refactor(frontend): rename recheck variable for clarity and use css c…
stijnvdkolk 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| discordAccessToken: string; | ||
| discordRefreshToken: string; | ||
| discordGuildFlags: Awaited<ReturnType<typeof getCurrentUserGuildFlags>>; | ||
| discordGuildFlagsFetchedAt: number; | ||
| }, | ||
| ) => void, | ||
| _consume: ConsumableAPI, | ||
|
|
@@ -65,6 +66,7 @@ | |
| discordAccessToken: accessToken, | ||
| discordRefreshToken: refreshToken, | ||
| discordGuildFlags: userGuildFlags, | ||
| discordGuildFlagsFetchedAt: Date.now(), | ||
| }); | ||
| } catch (error) { | ||
| done(error as Error, undefined); | ||
|
|
@@ -83,20 +85,20 @@ | |
| passport.deserializeUser<DiscordUserProfile>((user, done) => { | ||
| done(null, user); | ||
| }); | ||
|
|
||
| app.use( | ||
| session({ | ||
| cookie: { | ||
| maxAge: 24 * 60 * 60 * 1000, // 1 day (in ms) | ||
| }, | ||
| // having a random secret would mess with persistent sessions | ||
| secret: config.expressSessionSecret, | ||
| resave: true, | ||
| saveUninitialized: false, | ||
| store: new PrismaSessionStore(prisma, { | ||
| checkPeriod: 2 * 60 * 1000, //ms | ||
| dbRecordIdIsSessionId: true, | ||
| dbRecordIdFunction: undefined, | ||
Check failureCode scanning / CodeQL Missing CSRF middleware High
This cookie middleware is serving a
request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. This cookie middleware is serving a request handler without CSRF protection. |
||
| }), | ||
| }), | ||
| ); | ||
|
|
||
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
139 changes: 139 additions & 0 deletions
139
packages/backend/src/services/discordGuildService.test.ts
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,139 @@ | ||
| import type { SessionData } from "express-session"; | ||
| import fetchWithRetries from "@/utils/fetchWithRetries"; | ||
| import { getCachedUserGuildFlags } from "./discordGuildService"; | ||
|
|
||
| vi.mock("@/utils/fetchWithRetries", () => ({ | ||
| default: vi.fn(), | ||
| })); | ||
|
|
||
| const mockFetch = vi.mocked(fetchWithRetries); | ||
|
|
||
| function mockGuildsResponse( | ||
| guilds: Array<{ | ||
| id: string; | ||
| name: string; | ||
| permissions?: string; | ||
| approximate_member_count?: number; | ||
| }>, | ||
| ) { | ||
| mockFetch.mockResolvedValueOnce( | ||
| new Response(JSON.stringify(guilds), { | ||
| headers: { | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| }, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| function makeSession(overrides: Partial<SessionData> = {}): SessionData { | ||
| return { cookie: {} as SessionData["cookie"], ...overrides }; | ||
| } | ||
|
|
||
| const sampleGuilds = [ | ||
| { | ||
| id: "1", | ||
| name: "Guild 1", | ||
| permissions: "0", | ||
| approximate_member_count: 10, | ||
| }, | ||
| ]; | ||
|
|
||
| describe("getCachedUserGuildFlags", () => { | ||
| beforeEach(() => { | ||
| mockFetch.mockReset(); | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date("2026-01-01T00:00:00Z")); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it("fetches fresh flags when the session has no cache", async () => { | ||
| mockGuildsResponse(sampleGuilds); | ||
|
|
||
| const session = makeSession(); | ||
| const result = await getCachedUserGuildFlags(session, "token"); | ||
|
|
||
| expect(result).toMatchObject({ "1": { name: "Guild 1" } }); | ||
| expect(mockFetch).toHaveBeenCalledTimes(1); | ||
| expect(session.discordGuildFlags).toEqual(result); | ||
| expect(session.discordGuildFlagsFetchedAt).toBe(Date.now()); | ||
| }); | ||
|
|
||
| it("returns cached flags within the TTL window without hitting Discord", async () => { | ||
| const cachedFlags = { | ||
| "1": { | ||
| name: "Cached Guild", | ||
| memberCount: 10, | ||
| administrator: false, | ||
| manageGuild: false, | ||
| }, | ||
| }; | ||
| const session = makeSession({ | ||
| discordGuildFlags: cachedFlags, | ||
| discordGuildFlagsFetchedAt: Date.now(), | ||
| }); | ||
|
|
||
| vi.advanceTimersByTime(14 * 60 * 1000); | ||
|
|
||
| const result = await getCachedUserGuildFlags(session, "token"); | ||
|
|
||
| expect(result).toEqual(cachedFlags); | ||
| expect(mockFetch).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("refetches when the cached flags are older than the TTL", async () => { | ||
| const cachedFlags = { | ||
| "1": { | ||
| name: "Stale Guild", | ||
| memberCount: 10, | ||
| administrator: false, | ||
| manageGuild: false, | ||
| }, | ||
| }; | ||
| const session = makeSession({ | ||
| discordGuildFlags: cachedFlags, | ||
| discordGuildFlagsFetchedAt: Date.now(), | ||
| }); | ||
|
|
||
| vi.advanceTimersByTime(15 * 60 * 1000 + 1); | ||
|
|
||
| mockGuildsResponse([ | ||
| { | ||
| id: "2", | ||
| name: "Refreshed Guild", | ||
| permissions: "0", | ||
| approximate_member_count: 5, | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await getCachedUserGuildFlags(session, "token"); | ||
|
|
||
| expect(result).toMatchObject({ "2": { name: "Refreshed Guild" } }); | ||
| expect(mockFetch).toHaveBeenCalledTimes(1); | ||
| expect(session.discordGuildFlags).toEqual(result); | ||
| expect(session.discordGuildFlagsFetchedAt).toBe(Date.now()); | ||
| }); | ||
|
|
||
| it("refetches when discordGuildFlagsFetchedAt is missing", async () => { | ||
| mockGuildsResponse(sampleGuilds); | ||
|
|
||
| const session = makeSession({ | ||
| discordGuildFlags: { | ||
| old: { | ||
| name: "Old", | ||
| memberCount: null, | ||
| administrator: false, | ||
| manageGuild: false, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const result = await getCachedUserGuildFlags(session, "token"); | ||
|
|
||
| expect(result).toMatchObject({ "1": { name: "Guild 1" } }); | ||
| expect(mockFetch).toHaveBeenCalledTimes(1); | ||
| expect(session.discordGuildFlagsFetchedAt).toBe(Date.now()); | ||
| }); | ||
| }); |
|
stijnvdkolk marked this conversation as resolved.
|
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.
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.
Uh oh!
There was an error while loading. Please reload this page.