Public Access
feat(settings): remove the platform mails switch
Broadcasts go to every active user, so the settings switch and its API call are gone. Admin broadcast texts no longer mention an opt-out.
This commit is contained in:
1 parent
6dda186bdf
commit
80259cb0e9
8 files changed
+19
-60
No files matched your search
@@ -11,7 +11,7 @@ import {usePreferences} from '../context/PreferencesContext.jsx';
|
||||
import usePersistSettings from '../hooks/usePersistSettings.js';
|
||||
import useSaveResponse from '../hooks/useSaveResponse.js';
|
||||
import {FAVORITE_PLATFORMS, saveFavoritePlatform} from '../utils/platforms.js';
|
||||
import {LANGUAGES, savePlatformMails, saveSettings} from '../utils/settings.js';
|
||||
import {LANGUAGES, saveSettings} from '../utils/settings.js';
|
||||
|
||||
// Radix Select has no empty value.
|
||||
const NO_FAVORITE = 'NONE';
|
||||
@@ -41,13 +41,6 @@ export default function PreferencesCard() {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePlatformMailsChange = async (next) => {
|
||||
if (await runSave(() => savePlatformMails(next))) {
|
||||
updateProfile((p) => ({...p, settings: {...p.settings, platformMails: next}}));
|
||||
toast.success(t('SETTINGS.SAVED'));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -90,14 +83,6 @@ export default function PreferencesCard() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="platformMails">{t('SETTINGS.PLATFORM_MAILS')}</Label>
|
||||
<p className="text-xs text-muted-foreground">{t('SETTINGS.PLATFORM_MAILS_HINT')}</p>
|
||||
</div>
|
||||
<Switch id="platformMails" checked={profile?.settings?.platformMails ?? true}
|
||||
onCheckedChange={handlePlatformMailsChange}/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -20,3 +20,14 @@ describe('translation files', () => {
|
||||
expect(loadPath).toBe(`/i18n/{{lng}}.json?v=${hash.digest('hex').slice(0, 12)}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('admin broadcast texts', () => {
|
||||
it('adminBroadcastTexts_DoNotMentionAnOptOut', () => {
|
||||
const dir = path.resolve(import.meta.dirname, '../public/i18n');
|
||||
for (const file of ['en.json', 'de.json']) {
|
||||
const texts = JSON.parse(readFileSync(path.join(dir, file), 'utf8')).ADMIN_BROADCAST;
|
||||
expect(texts.TEXT_HELP, file).not.toMatch(/opt-out|Abschalten/i);
|
||||
expect(texts.NO_RECIPIENTS, file).not.toMatch(/mails on|Mails an/i);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -31,7 +31,6 @@ const authRoutes = (me) => ({
|
||||
'PUT /api/users/settings/appearance': noBody,
|
||||
'PUT /api/users/settings/profile-style': noBody,
|
||||
'PUT /api/users/settings/favorite-platform': noBody,
|
||||
'PUT /api/users/settings/platform-mails': noBody,
|
||||
'GET /api/version': json(404, {}),
|
||||
});
|
||||
|
||||
@@ -257,29 +256,6 @@ describe('SettingsPage favorite platform', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('SettingsPage platform mails', () => {
|
||||
beforeEach(() => localStorage.setItem('tbp_session', '1'));
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it('is on by default and saves the opt-out', async () => {
|
||||
toast.success.mockClear();
|
||||
renderPage(profile());
|
||||
|
||||
const mails = await screen.findByRole('switch', {name: 'SETTINGS.PLATFORM_MAILS'});
|
||||
expect(mails.getAttribute('aria-checked')).toBe('true');
|
||||
fireEvent.click(mails);
|
||||
|
||||
await waitFor(() => expect(puts()).toEqual([{enabled: false}]));
|
||||
expect(fetch.mock.calls.find(([, init]) => init?.method === 'PUT')[0]).toContain('/api/users/settings/platform-mails');
|
||||
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('SETTINGS.SAVED'));
|
||||
expect(mails.getAttribute('aria-checked')).toBe('false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SettingsPage session', () => {
|
||||
beforeEach(() => localStorage.setItem('tbp_session', '1'));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const JSON_HEADERS = {'Content-Type': 'application/json'};
|
||||
export const fetchBroadcasts = () => apiFetch(`${AUTH()}/api/admin/broadcasts`);
|
||||
|
||||
/**
|
||||
* {count}: the active users with platform mails on, among `userIds`; all of them when `userIds` is null.
|
||||
* {count}: the active users among `userIds`; all of them when `userIds` is null.
|
||||
*/
|
||||
export const fetchRecipientCount = (userIds) =>
|
||||
apiFetch(`${AUTH()}/api/admin/broadcasts/recipient-count${userIds ? `?userIds=${userIds.join(',')}` : ''}`);
|
||||
|
||||
@@ -58,11 +58,3 @@ export const markWelcomeSeen = () =>
|
||||
method: 'PUT',
|
||||
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||
});
|
||||
|
||||
/** PUT on Auth, 204: turns the broadcast mails on or off. The caller handles the response status. */
|
||||
export const savePlatformMails = (enabled) =>
|
||||
apiFetch(`${import.meta.env.VITE_API_URL}/api/users/settings/platform-mails`, {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({enabled}),
|
||||
});
|
||||
Reference in new issue
Block a user