Skip to content

Commit

Permalink
feat(server): add disableGravatarProfiles to Project settings (medp…
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatOneBro committed Jun 9, 2024
1 parent 6c9c842 commit 437b575
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/docs/docs/access/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ You can find the full `Project` resource schema [here](/docs/api/fhir/medplum/pr
| `checkReferencesOnWrite` | If `true`, the the server will reject any create or write operations to a FHIR resource with invalid references. | `false` |
| `features` | A list of optional features that are enabled for the project. Allowed values are: <ul><li>`bots`: This [`Project`](/docs/api/fhir/medplum/project) is allowed to create and run [Bots](/docs/bots/bot-basics).</li><li>`email`: Bots in this project can [send emails](/docs/sdk/core.medplumclient.sendemail). </li><li>`cron`: This [`Project`](/docs/api/fhir/medplum/project) can run Bots on [CRON timers](https://www.medplum.com/docs/bots/bot-cron-job)</li><li>`google-auth-required`: [Google authentication](/docs/auth/methods/google-auth) is the only method allowed for this [`Project`](/docs/api/fhir/medplum/project)</li></ul> | |
| `defaultPatientAccessPolicy` | The default [`AccessPolicy`](/docs/access/access-policies) applied to all [Patient Users](/docs/auth/user-management-guide#project-scoped-users) invited to this [`Project`](/docs/api/fhir/medplum/project). This is required to enable [open patient registration](/docs/auth/open-patient-registration). | |
| `disableGravatarProfiles` | If `true`, the Gravatar for the associated email of a newly invited user will not be fetched and used as the avatar for the user. | `false` |

## Project Secrets

Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export async function createProfile(
let photo: Attachment[] | undefined = undefined;
if (email) {
telecom = [{ system: 'email', use: 'work', value: email }];
photo = [{ url: getGravatar(email), contentType: 'image/png', title: 'profile.png' }];
if (!project.setting?.find((setting) => setting.name === 'disableGravatarProfiles')?.valueBoolean) {
photo = [{ url: getGravatar(email), contentType: 'image/png', title: 'profile.png' }];
}
}

const systemRepo = getSystemRepo();
Expand Down
55 changes: 55 additions & 0 deletions packages/server/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import express from 'express';
import { initApp, shutdownApp } from './app';
import { createProfile } from './auth/utils';
import { MedplumServerConfig, loadTestConfig } from './config';
import { createTestProject, withTestContext } from './test.setup';

describe('Utils', () => {
let app: express.Express;
let config: MedplumServerConfig;

beforeAll(async () => {
app = express();
config = await loadTestConfig();
await initApp(app, config);
});

afterAll(async () => {
await shutdownApp();
});

describe('createProfile', () => {
test('disableGravatarProfiles -- true', async () => {
const { project } = await withTestContext(async () =>
createTestProject({
project: {
setting: [{ name: 'disableGravatarProfiles', valueBoolean: true }],
},
})
);
const profile = await createProfile(project, 'Patient', 'Alice', 'Doe', '[email protected]');
expect(profile.photo).toBeUndefined();
});

test.each([false, undefined])('disableGravatarProfiles -- %s', async (val) => {
const { project } = await withTestContext(async () =>
createTestProject({
project:
val !== undefined
? {
setting: [{ name: 'disableGravatarProfiles', valueBoolean: val }],
}
: {},
})
);
const profile = await createProfile(project, 'Patient', 'Alice', 'Doe', '[email protected]');
expect(profile.photo).toEqual([
{
contentType: 'image/png',
title: 'profile.png',
url: 'https://gravatar.com/avatar/ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976?s=256&r=pg&d=retro',
},
]);
});
});
});

0 comments on commit 437b575

Please sign in to comment.