Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(operator-pass): Labs roles follow badge visibility (#3797)

Hampusa82d319c211d
diff --git a/fluxer_api/src/api/Config.ts b/fluxer_api/src/api/Config.ts
index 96bd66b63..59e884cbb 100644
--- a/fluxer_api/src/api/Config.ts
+++ b/fluxer_api/src/api/Config.ts
@@ -297,6 +297,10 @@ function buildOperatorPassConfig(master: MasterConfig): OperatorPassConfig {
if (labsVisionaryRoleId !== null && labsGuildId === null) {
throw new Error('FLUXER_LABS_VISIONARY_ROLE_ID needs FLUXER_LABS_GUILD_ID');
}
+ const labsAccessRoleId = parseOptionalSnowflake(source.labs_access_role_id, 'FLUXER_LABS_ACCESS_ROLE_ID');
+ if (labsAccessRoleId !== null && labsGuildId === null) {
+ throw new Error('FLUXER_LABS_ACCESS_ROLE_ID needs FLUXER_LABS_GUILD_ID');
+ }
const labsOperatorsChannelId = parseOptionalSnowflake(
source.labs_operators_channel_id,
'FLUXER_LABS_OPERATORS_CHANNEL_ID',
@@ -330,6 +334,7 @@ function buildOperatorPassConfig(master: MasterConfig): OperatorPassConfig {
labsGuildId,
labsOperatorRoleId,
labsVisionaryRoleId,
+ labsAccessRoleId,
labsOperatorsChannelId,
standardPricesMinor,
releaseLists: parseOperatorPassReleaseLists(source.release_lists),
diff --git a/fluxer_api/src/api/config/APIConfig.ts b/fluxer_api/src/api/config/APIConfig.ts
index 57b2e7b27..7887fb850 100644
--- a/fluxer_api/src/api/config/APIConfig.ts
+++ b/fluxer_api/src/api/config/APIConfig.ts
@@ -52,6 +52,7 @@ export interface OperatorPassConfig {
labsGuildId: bigint | null;
labsOperatorRoleId: bigint | null;
labsVisionaryRoleId: bigint | null;
+ labsAccessRoleId: bigint | null;
labsOperatorsChannelId: bigint | null;
standardPricesMinor: OperatorPassPriceTable | null;
releaseLists: OperatorPassReleaseListTable;
diff --git a/fluxer_api/src/api/middleware/ServiceMiddleware.ts b/fluxer_api/src/api/middleware/ServiceMiddleware.ts
index f00a1d05f..055fe0b09 100644
--- a/fluxer_api/src/api/middleware/ServiceMiddleware.ts
+++ b/fluxer_api/src/api/middleware/ServiceMiddleware.ts
@@ -906,6 +906,7 @@ class RequestServices implements RequestScopedServices {
getUserCacheService(),
getGatewayService(),
Config.instance.selfHosted ? null : getOperatorPassEntitlementService(),
+ Config.instance.selfHosted ? null : this.operatorPassServices.roleService,
);
}
return this.cachedUserAccountRequestService;
diff --git a/fluxer_api/src/api/operator_pass/OperatorPassHoldingService.ts b/fluxer_api/src/api/operator_pass/OperatorPassHoldingService.ts
index b7f44c8c1..54de3a1a9 100644
--- a/fluxer_api/src/api/operator_pass/OperatorPassHoldingService.ts
+++ b/fluxer_api/src/api/operator_pass/OperatorPassHoldingService.ts
@@ -970,7 +970,7 @@ export class OperatorPassHoldingService {
const user = await this.deps.userRepository.findUnique(userId);
const entitled =
user !== null && isOperatorPassEntitled(await loadOperatorPassEntitlementState(this.deps.repository, userId));
- await this.deps.roleService.syncOperatorRole(userId, entitled);
+ await this.deps.roleService.syncLabsRoles(userId, user, entitled);
await this.dispatchPassesUpdate([userId]);
await dispatchOperatorPassUserUpdate(
{
diff --git a/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.test.ts b/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.test.ts
index 3cf1fd349..58da96143 100644
--- a/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.test.ts
+++ b/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.test.ts
@@ -1,67 +1,67 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {createUserID} from '@app/api/BrandedTypes';
import {Config} from '@app/api/Config';
-import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository';
-import type {GuildService} from '@app/api/guild/services/GuildService';
-import type {User} from '@app/api/models/User';
-import {OperatorPassLabsRoleService} from '@app/api/operator_pass/OperatorPassLabsRole';
-import {UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
-import {afterEach, beforeEach, expect, test, vi} from 'vitest';
-
-const LABS_GUILD_ID = 7001n;
-const OPERATOR_ROLE_ID = 7002n;
-const VISIONARY_ROLE_ID = 7003n;
+import {labsRolesFor} from '@app/api/operator_pass/OperatorPassLabsRole';
+import type {ProfileBadgeKey} from '@fluxer/constants/src/BadgeConstants';
+import {PremiumFlags, UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
+import {afterEach, beforeEach, expect, test} from 'vitest';
const original = {...Config.operatorPass};
-const originalSelfHosted = Config.instance.selfHosted;
beforeEach(() => {
- Config.instance.selfHosted = false;
- Config.operatorPass.labsGuildId = LABS_GUILD_ID;
- Config.operatorPass.labsOperatorRoleId = OPERATOR_ROLE_ID;
- Config.operatorPass.labsVisionaryRoleId = VISIONARY_ROLE_ID;
+ Config.operatorPass.labsGuildId = 7001n;
+ Config.operatorPass.labsOperatorRoleId = 7002n;
+ Config.operatorPass.labsVisionaryRoleId = 7003n;
+ Config.operatorPass.labsAccessRoleId = 7004n;
});
afterEach(() => {
Object.assign(Config.operatorPass, original);
- Config.instance.selfHosted = originalSelfHosted;
});
-test('the Labs sync takes the Visionary role from someone who lost Visionary and keeps an Operator role they earned', async () => {
- const downgraded = createUserID(8001n);
- const visionary = createUserID(8002n);
- const plain = createUserID(8003n);
- const members = [
- {userId: downgraded, roleIds: new Set([VISIONARY_ROLE_ID, OPERATOR_ROLE_ID])},
- {userId: visionary, roleIds: new Set<bigint>()},
- {userId: plain, roleIds: new Set<bigint>()},
- ];
- const guildRepository = {
- getRole: vi.fn(async () => ({id: VISIONARY_ROLE_ID})),
- listMembersPaginated: vi.fn(async (_guildId: bigint, _size: number, after?: bigint) => (after ? [] : members)),
- };
- const systemAddMemberRole = vi.fn(async () => {});
- const systemRemoveMemberRole = vi.fn(async () => {});
- const users = [
- {id: downgraded, premiumType: UserPremiumTypes.SUBSCRIPTION},
- {id: visionary, premiumType: UserPremiumTypes.LIFETIME},
- {id: plain, premiumType: null},
- ] as Array<User>;
- const service = new OperatorPassLabsRoleService(
- guildRepository as unknown as GuildRepository,
- {members: {systemAddMemberRole, systemRemoveMemberRole}} as unknown as GuildService,
- );
+function account(premiumType: number | null, hidden: Array<ProfileBadgeKey> = [], premiumFlags = 0) {
+ return {premiumType, premiumFlags, hiddenProfileBadges: new Set(hidden)} as Parameters<typeof labsRolesFor>[0];
+}
- const summary = await service.syncVisionaryRoleForLabsMembers({listUsers: vi.fn(async () => users)}, 500);
+test('Labs shows the Operator and Visionary roles only to people who show the badge, and everyone with access gets the access role', () => {
+ expect(labsRolesFor(account(null), true)).toEqual({operator: true, visionary: false, access: true});
+ expect(labsRolesFor(account(null, ['operator_pass']), true)).toEqual({
+ operator: false,
+ visionary: false,
+ access: true,
+ });
+ expect(labsRolesFor(account(UserPremiumTypes.LIFETIME), false)).toEqual({
+ operator: false,
+ visionary: true,
+ access: true,
+ });
+ expect(labsRolesFor(account(UserPremiumTypes.LIFETIME, ['visionary']), false)).toEqual({
+ operator: false,
+ visionary: false,
+ access: true,
+ });
+ expect(labsRolesFor(account(UserPremiumTypes.LIFETIME, [], PremiumFlags.BADGE_MASKED), false)).toEqual({
+ operator: false,
+ visionary: false,
+ access: true,
+ });
+ expect(labsRolesFor(account(UserPremiumTypes.SUBSCRIPTION), false)).toEqual({
+ operator: false,
+ visionary: false,
+ access: false,
+ });
+});
- expect(summary).toEqual({granted: 1, removed: 1, failed: 0});
- expect(systemRemoveMemberRole).toHaveBeenCalledOnce();
- expect(systemRemoveMemberRole).toHaveBeenCalledWith(
- expect.objectContaining({targetId: downgraded, roleId: VISIONARY_ROLE_ID}),
- );
- expect(systemAddMemberRole).toHaveBeenCalledOnce();
- expect(systemAddMemberRole).toHaveBeenCalledWith(
- expect.objectContaining({targetId: visionary, roleId: VISIONARY_ROLE_ID}),
- );
+test('without an access role, Operators and Visionaries keep their roles whether or not they show the badge', () => {
+ Config.operatorPass.labsAccessRoleId = null;
+ expect(labsRolesFor(account(null, ['operator_pass']), true)).toEqual({
+ operator: true,
+ visionary: false,
+ access: false,
+ });
+ expect(labsRolesFor(account(UserPremiumTypes.LIFETIME, ['visionary']), false)).toEqual({
+ operator: false,
+ visionary: true,
+ access: false,
+ });
});
diff --git a/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.ts b/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.ts
index a1db54a32..9d542f523 100644
--- a/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.ts
+++ b/fluxer_api/src/api/operator_pass/OperatorPassLabsRole.ts
@@ -18,7 +18,7 @@ import {OperatorPassRepository} from '@app/api/operator_pass/OperatorPassReposit
import {isAccountLimited} from '@app/api/user/AccountLimit';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {JoinSourceTypes} from '@fluxer/constants/src/GuildConstants';
-import {UserFlags, UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
+import {PremiumFlags, UserFlags, UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
import {BannedFromGuildError} from '@fluxer/errors/src/domains/guild/BannedFromGuildError';
import {IpBannedFromGuildError} from '@fluxer/errors/src/domains/guild/IpBannedFromGuildError';
import {ms} from 'itty-time';
@@ -93,8 +93,20 @@ type LabsAccount = Pick<
| 'deletionStartedAt'
| 'contentHiddenSince'
| 'tempBannedUntil'
+ | 'premiumFlags'
+ | 'hiddenProfileBadges'
>;
+type VisionaryAccount = Pick<User, 'id' | 'premiumType' | 'premiumFlags' | 'hiddenProfileBadges'>;
+
+function showsVisionaryInLabs(user: Omit<VisionaryAccount, 'id'>): boolean {
+ return (
+ user.premiumType === UserPremiumTypes.LIFETIME &&
+ !user.hiddenProfileBadges.has('visionary') &&
+ (user.premiumFlags & PremiumFlags.BADGE_MASKED) === 0
+ );
+}
+
export function isBlockedFromLabsAutoJoin(user: Omit<LabsAccount, 'id' | 'premiumType'>, now: Date): boolean {
return (
user.isBot ||
@@ -187,6 +199,28 @@ function getLabsVisionaryRoleId(): RoleID | null {
return getLabsOperatorRole() && labsVisionaryRoleId != null ? createRoleID(labsVisionaryRoleId) : null;
}
+function getLabsAccessRoleId(): RoleID | null {
+ const {labsAccessRoleId} = Config.operatorPass;
+ return getLabsOperatorRole() && labsAccessRoleId != null ? createRoleID(labsAccessRoleId) : null;
+}
+
+interface LabsRoleWants {
+ operator: boolean;
+ visionary: boolean;
+ access: boolean;
+}
+
+export function labsRolesFor(user: Omit<VisionaryAccount, 'id'> | null, entitled: boolean): LabsRoleWants {
+ const lifetime = user?.premiumType === UserPremiumTypes.LIFETIME;
+ const split = getLabsAccessRoleId() !== null;
+ return {
+ operator: entitled && (!split || !user?.hiddenProfileBadges.has('operator_pass')),
+ visionary:
+ getLabsVisionaryRoleId() !== null && lifetime && (!split || (user !== null && showsVisionaryInLabs(user))),
+ access: split && (entitled || lifetime),
+ };
+}
+
export function keepsOperatorsThroughVisionary(user: Pick<User, 'premiumType'> | null): boolean {
return getLabsVisionaryRoleId() !== null && user?.premiumType === UserPremiumTypes.LIFETIME;
}
@@ -200,14 +234,13 @@ export async function resolveOperatorPassJoinRoleIds(
if (!labs || labs.guildId !== guildId) {
return null;
}
- const candidates: Array<RoleID> = [];
- const visionaryRoleId = getLabsVisionaryRoleId();
- if (visionaryRoleId && user.premiumType === UserPremiumTypes.LIFETIME) {
- candidates.push(visionaryRoleId);
- }
- if (isOperatorPassEntitled(await loadOperatorPassEntitlementState(labsRepository, user.id))) {
- candidates.push(labs.roleId);
- }
+ const wants = labsRolesFor(
+ user,
+ isOperatorPassEntitled(await loadOperatorPassEntitlementState(labsRepository, user.id)),
+ );
+ const candidates = labsRoleTargets(labs.roleId)
+ .filter(({key}) => wants[key])
+ .map(({roleId}) => roleId);
const roleIds = new Set<RoleID>();
for (const roleId of candidates) {
if (await guildRepository.getRole(roleId, guildId)) {
@@ -217,6 +250,15 @@ export async function resolveOperatorPassJoinRoleIds(
return roleIds.size > 0 ? roleIds : null;
}
+function labsRoleTargets(operatorRoleId: RoleID): Array<{key: keyof LabsRoleWants; roleId: RoleID}> {
+ const targets: Array<{key: keyof LabsRoleWants; roleId: RoleID}> = [{key: 'operator', roleId: operatorRoleId}];
+ const visionaryRoleId = getLabsVisionaryRoleId();
+ if (visionaryRoleId) targets.push({key: 'visionary', roleId: visionaryRoleId});
+ const accessRoleId = getLabsAccessRoleId();
+ if (accessRoleId) targets.push({key: 'access', roleId: accessRoleId});
+ return targets;
+}
+
export class OperatorPassLabsRoleService {
constructor(
private readonly guildRepository: GuildRepository,
@@ -301,7 +343,8 @@ export class OperatorPassLabsRoleService {
continue;
}
const member = await this.guildRepository.getMember(labs.guildId, user.id);
- if (member?.roleIds.has(labs.roleId)) {
+ const accessRoleId = getLabsAccessRoleId();
+ if (member && (member.roleIds.has(labs.roleId) || (accessRoleId && member.roleIds.has(accessRoleId)))) {
continue;
}
if (!isOperatorPassEntitled(await loadOperatorPassEntitlementState(labsRepository, user.id))) {
@@ -352,8 +395,7 @@ export class OperatorPassLabsRoleService {
}
private async finishLabsMembership(user: LabsAccount, now: Date): Promise<void> {
- await this.grantOperatorRoleIfMember(user.id);
- await this.syncVisionaryRole(user);
+ await this.resyncLabsRoles(user);
await this.queueGreetingIfDue(user, now);
}
@@ -421,51 +463,32 @@ export class OperatorPassLabsRoleService {
return labs !== null && (await this.guildRepository.getMember(labs.guildId, userId)) !== null;
}
- private async grantOperatorRoleIfMember(userId: UserID): Promise<boolean> {
- const labs = getLabsOperatorRole();
- if (!labs) {
- return false;
- }
- const member = await this.guildRepository.getMember(labs.guildId, userId);
- if (!member || member.roleIds.has(labs.roleId)) {
- return false;
- }
- await this.guildService.members.systemAddMemberRole({
- targetId: userId,
- guildId: labs.guildId,
- roleId: labs.roleId,
- initiatorId: SYSTEM_USER_ID,
- requestCache: createRequestCache(),
- });
- return true;
+ async resyncLabsRoles(user: VisionaryAccount): Promise<void> {
+ const entitled = isOperatorPassEntitled(await loadOperatorPassEntitlementState(labsRepository, user.id));
+ await this.syncLabsRoles(user.id, user, entitled);
}
- async syncVisionaryRole(user: Pick<User, 'id' | 'premiumType'>): Promise<void> {
+ async syncLabsRoles(userId: UserID, user: VisionaryAccount | null, entitled: boolean): Promise<void> {
const labs = getLabsOperatorRole();
- const visionaryRoleId = getLabsVisionaryRoleId();
- if (!labs || !visionaryRoleId) {
+ if (!labs) {
return;
}
try {
- const member = await this.guildRepository.getMember(labs.guildId, user.id);
+ const member = await this.guildRepository.getMember(labs.guildId, userId);
if (member) {
- await this.applyVisionaryRole(labs.guildId, visionaryRoleId, member, user);
+ await this.applyLabsRoles(labs, member, userId, labsRolesFor(user, entitled));
}
} catch (error) {
- Logger.error(
- {userId: user.id, guildId: labs.guildId, roleId: visionaryRoleId, error},
- 'Failed to update the Visionary role in Fluxer Labs',
- );
+ Logger.error({userId, guildId: labs.guildId, error}, 'Failed to update the Fluxer Labs roles');
}
}
- async syncVisionaryRoleForLabsMembers(
+ async syncLabsRolesForMembers(
userRepository: Pick<UserRepository, 'listUsers'>,
pageSize: number,
): Promise<LabsVisionaryRoleSyncSummary | null> {
const labs = getLabsOperatorRole();
- const visionaryRoleId = getLabsVisionaryRoleId();
- if (!labs || !visionaryRoleId || !(await this.guildRepository.getRole(visionaryRoleId, labs.guildId))) {
+ if (!labs) {
return null;
}
const summary: LabsVisionaryRoleSyncSummary = {granted: 0, removed: 0, failed: 0};
@@ -481,21 +504,16 @@ export class OperatorPassLabsRoleService {
);
for (const member of members) {
try {
- const change = await this.applyVisionaryRole(
- labs.guildId,
- visionaryRoleId,
- member,
- users.get(member.userId) ?? {id: member.userId, premiumType: null},
- );
- if (change) {
- summary[change]++;
- }
+ const user = users.get(member.userId) ?? null;
+ const entitled =
+ user !== null &&
+ isOperatorPassEntitled(await loadOperatorPassEntitlementState(labsRepository, member.userId));
+ const changes = await this.applyLabsRoles(labs, member, member.userId, labsRolesFor(user, entitled));
+ summary.granted += changes.granted;
+ summary.removed += changes.removed;
} catch (error) {
summary.failed++;
- Logger.error(
- {userId: member.userId, guildId: labs.guildId, roleId: visionaryRoleId, error},
- 'Failed to update the Visionary role in Fluxer Labs',
- );
+ Logger.error({userId: member.userId, guildId: labs.guildId, error}, 'Failed to update the Fluxer Labs roles');
}
}
if (members.length < pageSize) {
@@ -505,66 +523,32 @@ export class OperatorPassLabsRoleService {
return summary;
}
- private async applyVisionaryRole(
- guildId: GuildID,
- visionaryRoleId: RoleID,
+ private async applyLabsRoles(
+ labs: LabsOperatorRole,
member: {roleIds: ReadonlySet<RoleID>},
- user: Pick<User, 'id' | 'premiumType'>,
- ): Promise<'granted' | 'removed' | null> {
- const visionary = user.premiumType === UserPremiumTypes.LIFETIME;
- const hasRole = member.roleIds.has(visionaryRoleId);
- if (visionary === hasRole) {
- return null;
- }
- const change = {
- targetId: user.id,
- guildId,
- roleId: visionaryRoleId,
- initiatorId: SYSTEM_USER_ID,
- requestCache: createRequestCache(),
- };
- if (visionary) {
- await this.guildService.members.systemAddMemberRole(change);
- return 'granted';
- }
- await this.guildService.members.systemRemoveMemberRole(change);
- return 'removed';
- }
-
- async syncOperatorRole(userId: UserID, entitled: boolean): Promise<void> {
- if (!entitled) {
- await this.removeOperatorRole(userId);
- return;
- }
- try {
- await this.grantOperatorRoleIfMember(userId);
- } catch (error) {
- Logger.error({userId, error}, 'Failed to give the Operator role back in Fluxer Labs');
- }
- }
-
- private async removeOperatorRole(userId: UserID): Promise<void> {
- const labs = getLabsOperatorRole();
- if (!labs) {
- return;
- }
- try {
- const member = await this.guildRepository.getMember(labs.guildId, userId);
- if (!member?.roleIds.has(labs.roleId)) {
- return;
+ userId: UserID,
+ wants: LabsRoleWants,
+ ): Promise<{granted: number; removed: number}> {
+ const changes = {granted: 0, removed: 0};
+ for (const {key, roleId} of labsRoleTargets(labs.roleId)) {
+ if (wants[key] === member.roleIds.has(roleId)) {
+ continue;
}
- await this.guildService.members.systemRemoveMemberRole({
+ const change = {
targetId: userId,
guildId: labs.guildId,
- roleId: labs.roleId,
+ roleId,
initiatorId: SYSTEM_USER_ID,
requestCache: createRequestCache(),
- });
- } catch (error) {
- Logger.error(
- {userId, guildId: labs.guildId, roleId: labs.roleId, error},
- 'Failed to remove the Operator role in Fluxer Labs',
- );
+ };
+ if (wants[key]) {
+ await this.guildService.members.systemAddMemberRole(change);
+ changes.granted++;
+ } else {
+ await this.guildService.members.systemRemoveMemberRole(change);
+ changes.removed++;
+ }
}
+ return changes;
}
}
diff --git a/fluxer_api/src/api/operator_pass/OperatorPassRemovalService.ts b/fluxer_api/src/api/operator_pass/OperatorPassRemovalService.ts
index a3a54d428..cc7c6bb07 100644
--- a/fluxer_api/src/api/operator_pass/OperatorPassRemovalService.ts
+++ b/fluxer_api/src/api/operator_pass/OperatorPassRemovalService.ts
@@ -297,7 +297,7 @@ export class OperatorPassRemovalService {
const user = await this.userRepository.findUnique(userId);
const entitled =
user !== null && isOperatorPassEntitled(await loadOperatorPassEntitlementState(this.repository, userId));
- await this.roleService.syncOperatorRole(userId, entitled);
+ await this.roleService.syncLabsRoles(userId, user, entitled);
await dispatchOperatorPassUserUpdate(
{repository: this.repository, userRepository: this.userRepository, gatewayService: this.gatewayService},
userId,
diff --git a/fluxer_api/src/api/stripe/services/StripePremiumService.ts b/fluxer_api/src/api/stripe/services/StripePremiumService.ts
index 07d2a25c2..0cdd2cafc 100644
--- a/fluxer_api/src/api/stripe/services/StripePremiumService.ts
+++ b/fluxer_api/src/api/stripe/services/StripePremiumService.ts
@@ -385,9 +385,12 @@ export class StripePremiumService {
}
private async syncLabsVisionaryRole(userId: UserID): Promise<void> {
- await new OperatorPassLabsRoleService(this.guildRepository, this.guildService).syncVisionaryRole({
+ const user = await this.userRepository.findUnique(userId);
+ await new OperatorPassLabsRoleService(this.guildRepository, this.guildService).resyncLabsRoles({
id: userId,
premiumType: UserPremiumTypes.LIFETIME,
+ premiumFlags: user?.premiumFlags ?? 0,
+ hiddenProfileBadges: user?.hiddenProfileBadges ?? new Set(),
});
}
}
diff --git a/fluxer_api/src/api/user/services/UserAccountRequestService.ts b/fluxer_api/src/api/user/services/UserAccountRequestService.ts
index 2784ba777..3c6a971a1 100644
--- a/fluxer_api/src/api/user/services/UserAccountRequestService.ts
+++ b/fluxer_api/src/api/user/services/UserAccountRequestService.ts
@@ -21,6 +21,7 @@ import {
profileOperatorPassSince,
resolveOperatorPassHolder,
} from '@app/api/operator_pass/OperatorPassEntitlementService';
+import type {OperatorPassLabsRoleService} from '@app/api/operator_pass/OperatorPassLabsRole';
import type {AuthTokenType, HonoEnv} from '@app/api/types/HonoEnv';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
import {
@@ -132,6 +133,7 @@ export class UserAccountRequestService {
private readonly userCacheService: UserCacheService,
private readonly gatewayService: IGatewayService,
private readonly operatorPassEntitlementService: OperatorPassEntitlementService | null = null,
+ private readonly labsRoleService: OperatorPassLabsRoleService | null = null,
) {}
async getCurrentUserResponse(params: {
@@ -286,6 +288,14 @@ export class UserAccountRequestService {
Logger.warn({error, userId: updatedUser.id}, 'Failed to issue email revert token');
}
}
+ if (
+ this.labsRoleService &&
+ (user.hiddenProfileBadges.has('visionary') !== updatedUser.hiddenProfileBadges.has('visionary') ||
+ user.hiddenProfileBadges.has('operator_pass') !== updatedUser.hiddenProfileBadges.has('operator_pass') ||
+ userUpdateData.premium_badge_masked !== undefined)
+ ) {
+ await this.labsRoleService.resyncLabsRoles(updatedUser);
+ }
if (
(user.hiddenProfileBadges.has('operator_pass') !== updatedUser.hiddenProfileBadges.has('operator_pass') ||
userUpdateData.operator_pass_badge_timestamp_hidden !== undefined ||
diff --git a/fluxer_api/src/api/worker/tasks/OperatorPassLabsVisionaryRoleSync.ts b/fluxer_api/src/api/worker/tasks/OperatorPassLabsVisionaryRoleSync.ts
index 27d5797c7..d8b657d9c 100644
--- a/fluxer_api/src/api/worker/tasks/OperatorPassLabsVisionaryRoleSync.ts
+++ b/fluxer_api/src/api/worker/tasks/OperatorPassLabsVisionaryRoleSync.ts
@@ -25,7 +25,7 @@ const operatorPassLabsVisionaryRoleSync: WorkerTaskHandler = async (payload) =>
await visionary?.endIfVisionaryEnded(userId);
const user = await userRepository.findUnique(userId);
if (user) {
- await roles.syncVisionaryRole(user);
+ await roles.resyncLabsRoles(user);
}
return;
}
@@ -33,11 +33,11 @@ const operatorPassLabsVisionaryRoleSync: WorkerTaskHandler = async (payload) =>
if (ended && (ended.ended > 0 || ended.failed > 0)) {
Logger.info(ended, 'Ended the Operator Pass of accounts whose Visionary ended');
}
- const summary = await roles.syncVisionaryRoleForLabsMembers(userRepository, PAGE_SIZE);
+ const summary = await roles.syncLabsRolesForMembers(userRepository, PAGE_SIZE);
if (!summary) {
- Logger.warn('Skipped the Labs Visionary role sync, the role does not exist in Fluxer Labs yet');
+ Logger.warn('Skipped the Fluxer Labs role sync, Fluxer Labs is not configured');
} else if (summary.granted > 0 || summary.removed > 0 || summary.failed > 0) {
- Logger.info(summary, 'Matched the Visionary role in Fluxer Labs to who has Visionary');
+ Logger.info(summary, 'Matched the Fluxer Labs roles to who has a pass or Visionary');
}
const failed = (summary?.failed ?? 0) + (ended?.failed ?? 0);
if (failed > 0) throw new Error(`Labs Visionary role sync failed for ${failed} accounts`);
diff --git a/packages/config/src/MasterConfig.ts b/packages/config/src/MasterConfig.ts
index 3c1065721..206a1185e 100644
--- a/packages/config/src/MasterConfig.ts
+++ b/packages/config/src/MasterConfig.ts
@@ -339,6 +339,7 @@ export interface MasterConfig {
labs_guild_id?: string;
labs_operator_role_id?: string;
labs_visionary_role_id?: string;
+ labs_access_role_id?: string;
labs_operators_channel_id?: string;
standard_prices_minor?: Partial<Record<string, number>>;
release_lists?: string;
diff --git a/packages/config/src/config_loader/EnvironmentOverrides.ts b/packages/config/src/config_loader/EnvironmentOverrides.ts
index c0cf34d51..8d752d56c 100644
--- a/packages/config/src/config_loader/EnvironmentOverrides.ts
+++ b/packages/config/src/config_loader/EnvironmentOverrides.ts
@@ -309,6 +309,7 @@ const NAMED_FLUXER_ENV_OVERRIDES: Record<string, NamedEnvOverride> = {
FLUXER_LABS_GUILD_ID: {path: ['operator_pass', 'labs_guild_id']},
FLUXER_LABS_OPERATOR_ROLE_ID: {path: ['operator_pass', 'labs_operator_role_id']},
FLUXER_LABS_VISIONARY_ROLE_ID: {path: ['operator_pass', 'labs_visionary_role_id']},
+ FLUXER_LABS_ACCESS_ROLE_ID: {path: ['operator_pass', 'labs_access_role_id']},
FLUXER_LABS_OPERATORS_CHANNEL_ID: {path: ['operator_pass', 'labs_operators_channel_id']},
FLUXER_PAYMENT_DISPUTE_CLOSURE_EFFECTIVE_AT: {path: ['payment_disputes', 'closure_effective_at']},
FLUXER_OPERATOR_PASS_SALE_OPENS_AT: {path: ['operator_pass', 'sale_opens_at']},