Skip to content

Commit

Permalink
plumb dsaFeaturesEnabled through to Local relay
Browse files Browse the repository at this point in the history
allows folks to do the following anywhere in the
stream or admin:

```
const [{ dsaFeaturesEnabled }] =
  useLocal<SomeLocal>(graphql`
    fragment SomeLocal on Local {
      dsaFeaturesEnabled
    }
  `);
```
  • Loading branch information
nick-funk committed Sep 26, 2023
1 parent 1e17cca commit a04a2f9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions client/src/core/client/admin/local/initLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import {
ADMIN_REDIRECT_PATH_KEY,
MOD_QUEUE_SORT_ORDER,
} from "coral-admin/constants";
import { DEFAULT_AUTO_ARCHIVE_OLDER_THAN } from "coral-common/common/lib/constants";
import { clearHash, getParamsFromHash } from "coral-framework/helpers";
import { parseAccessToken } from "coral-framework/lib/auth";
import { InitLocalState } from "coral-framework/lib/bootstrap/createManaged";
import { initLocalBaseState, LOCAL_ID } from "coral-framework/lib/relay";
import { GQLCOMMENT_SORT } from "coral-framework/schema";

import { DEFAULT_AUTO_ARCHIVE_OLDER_THAN } from "coral-common/common/lib/constants";

/**
* Initializes the local state, before we start the App.
*/
Expand Down Expand Up @@ -66,6 +65,8 @@ const initLocalState: InitLocalState = async ({
const autoArchiveOlderThanMs =
staticConfig?.autoArchiveOlderThanMs ?? DEFAULT_AUTO_ARCHIVE_OLDER_THAN;

const dsaFeaturesEnabled = staticConfig?.dsaFeaturesEnabled ?? false;

commitLocalUpdate(environment, (s) => {
const localRecord = s.get(LOCAL_ID)!;

Expand All @@ -83,6 +84,8 @@ const initLocalState: InitLocalState = async ({

localRecord.setValue(archivingEnabled, "archivingEnabled");
localRecord.setValue(autoArchiveOlderThanMs, "autoArchiveOlderThanMs");

localRecord.setValue(dsaFeaturesEnabled, "dsaFeaturesEnabled");
});
};

Expand Down
2 changes: 2 additions & 0 deletions client/src/core/client/admin/local/local.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ extend type Local {

archivingEnabled: Boolean!
autoArchiveOlderThanMs: Int!

dsaFeaturesEnabled: Boolean
}
15 changes: 14 additions & 1 deletion client/src/core/client/stream/local/initLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AUTH_POPUP_ID, AUTH_POPUP_TYPE } from "./constants";
interface ResolvedConfig {
readonly featureFlags: string[];
readonly flattenReplies?: boolean | null;
readonly dsaFeaturesEnabled?: boolean;
}

async function resolveConfig(
Expand All @@ -39,13 +40,22 @@ async function resolveConfig(
settings {
flattenReplies
featureFlags
dsa {
enabled
}
}
}
`,
{}
);

return data.settings as ResolvedConfig;
const { settings } = data;

return {
flattenReplies: settings.flattenReplies,
featureFlags: settings.featureFlags,
dsaFeaturesEnabled: settings.dsa.enabled ?? false,
} as ResolvedConfig;
}
return {
featureFlags: [],
Expand Down Expand Up @@ -166,5 +176,8 @@ export const createInitLocalState: (options: Options) => InitLocalState =

localRecord.setValue(false, "showCommentIDs");
localRecord.setValue(false, "refreshStream");

const dsaFeaturesEnabled = staticConfig?.dsaFeaturesEnabled ?? false;
localRecord.setValue(dsaFeaturesEnabled, "dsaFeaturesEnabled");
});
};
2 changes: 2 additions & 0 deletions client/src/core/client/stream/local/local.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ extend type Local {

# Refreshes stream for refresh comments button
refreshStream: Boolean

dsaFeaturesEnabled: Boolean
}
6 changes: 6 additions & 0 deletions config/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export interface StaticConfig {
* be kept before being auto-archived.
*/
autoArchiveOlderThanMs: number;

/**
* dsaFeaturesEnabled is true when the DSA European Union features for content
* moderation and illegal reporting are enabled on the tenant.
*/
dsaFeaturesEnabled?: boolean;
}

export interface EmbedBootstrapConfig {
Expand Down
3 changes: 3 additions & 0 deletions server/src/core/server/app/router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ const populateStaticConfig = (staticConfig: StaticConfig, req: Request) => {
req.coral.tenant?.featureFlags?.filter(validFeatureFlagsFilter(req.user)) ||
[];
const flattenReplies = req.coral.tenant?.flattenReplies || false;
const dsaFeaturesEnabled = req.coral.tenant?.dsa?.enabled ?? false;

return {
...staticConfig,
featureFlags,
tenantDomain: req.coral.tenant?.domain,
flattenReplies,
dsaFeaturesEnabled,
};
};

Expand Down

0 comments on commit a04a2f9

Please sign in to comment.