From a43c173a125423557f93ee51a1891b7ea4d7700a Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 21 Mar 2018 11:04:41 -0600 Subject: [PATCH 1/2] Added support for forcing the notification settings pane --- middleware/staticTemplate.js | 27 ++++++++++++++----- plugin-api/beta/client/selectors/index.js | 1 + .../client/containers/Settings.js | 20 ++++++++++++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/middleware/staticTemplate.js b/middleware/staticTemplate.js index b7d01feb4..01503cca0 100644 --- a/middleware/staticTemplate.js +++ b/middleware/staticTemplate.js @@ -13,6 +13,25 @@ const { const { RECAPTCHA_PUBLIC, WEBSOCKET_LIVE_URI } = require('../config'); +// Grab TALK_CLIENT_* environment variables. +const TALK_CLIENT = /^TALK_CLIENT_/i; + +// TALK_CLIENT_ENV is all the environment keys that are loaded at runtime. +const TALK_CLIENT_ENV = Object.keys(process.env) + .filter(key => TALK_CLIENT.test(key)) + .reduce( + (env, key) => { + env[key] = process.env[key]; + return env; + }, + { + TALK_RECAPTCHA_PUBLIC: RECAPTCHA_PUBLIC, + LIVE_URI: WEBSOCKET_LIVE_URI, + STATIC_URL, + STATIC_ORIGIN, + } + ); + // TEMPLATE_LOCALS stores the static data that is provided as a `text/json` on // to the client from the template. const TEMPLATE_LOCALS = { @@ -20,12 +39,8 @@ const TEMPLATE_LOCALS = { BASE_PATH, MOUNT_PATH, STATIC_URL, - data: { - TALK_RECAPTCHA_PUBLIC: RECAPTCHA_PUBLIC, - LIVE_URI: WEBSOCKET_LIVE_URI, - STATIC_URL, - STATIC_ORIGIN, - }, + TALK_CLIENT_ENV, + data: TALK_CLIENT_ENV, }; // attachStaticLocals will attach the locals to the response only. diff --git a/plugin-api/beta/client/selectors/index.js b/plugin-api/beta/client/selectors/index.js index c3a0b6821..605711dbc 100644 --- a/plugin-api/beta/client/selectors/index.js +++ b/plugin-api/beta/client/selectors/index.js @@ -1 +1,2 @@ export const pluginsConfigSelector = state => state.config.plugins_config; +export const staticConfigSelector = state => state.config.static; diff --git a/plugins/talk-plugin-notifications/client/containers/Settings.js b/plugins/talk-plugin-notifications/client/containers/Settings.js index 27af031e8..5862650ec 100644 --- a/plugins/talk-plugin-notifications/client/containers/Settings.js +++ b/plugins/talk-plugin-notifications/client/containers/Settings.js @@ -9,6 +9,8 @@ import { } from 'plugin-api/beta/client/hocs'; import { getSlotFragmentSpreads } from 'plugin-api/beta/client/utils'; import { withUpdateNotificationSettings } from '../mutations'; +import { connect } from 'plugin-api/beta/client/hocs'; +import { staticConfigSelector } from 'plugin-api/beta/client/selectors'; const slots = ['notificationSettings']; @@ -42,8 +44,11 @@ class SettingsContainer extends React.Component { }; getNeedEmailVerification() { - return !this.props.root.me.profiles.some( - profile => profile.provider === 'local' && profile.confirmedAt + return ( + this.props.root.settings.notificationsRequireConfirmation && + !this.props.root.me.profiles.some( + profile => profile.provider === 'local' && profile.confirmedAt + ) ); } @@ -94,11 +99,22 @@ const enhance = compose( } } } + settings { + notificationsRequireConfirmation + } } `, }), + // Grab the static configuration from the redux store. + connect(state => ({ + static: staticConfigSelector(state), + })), excludeIf( props => + // If the environment variable for TALK_CLIENT_FORCE_NOTIFICATION_SETTINGS + // is `TRUE`, then always show it. + props.static.TALK_CLIENT_FORCE_NOTIFICATION_SETTINGS !== 'TRUE' && + // Only show the settings pane if we have a local profile otherwise. !props.root.me.profiles.some(profile => profile.provider === 'local') ), withUpdateNotificationSettings, From 0b017002358097fbce19f92b9e747d9a399500e4 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 21 Mar 2018 11:12:04 -0600 Subject: [PATCH 2/2] updated docs --- plugins/talk-plugin-notifications/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/talk-plugin-notifications/README.md b/plugins/talk-plugin-notifications/README.md index 0ce1b61a8..9e8318a0f 100644 --- a/plugins/talk-plugin-notifications/README.md +++ b/plugins/talk-plugin-notifications/README.md @@ -16,6 +16,7 @@ anything. You need to enable one of the `talk-plugin-notifications-category-*` p Configuration: - `DISABLE_REQUIRE_EMAIL_VERIFICATIONS` - When `TRUE`, it will disable the verification email check before sending notifications for those emails. **Note that organizations implementing a custom authentication system _must_ disable this feature, as they don't use our integrated auth**. (Default `FALSE`). +- `TALK_CLIENT_FORCE_NOTIFICATION_SETTINGS` - When `TRUE`, the settings pane for notifications will show always, even if the user does not have a `local` profile. (Default `FALSE`). You can enable other notification options by adding more `talk-plugin-notification-*` plugins! \ No newline at end of file