diff --git a/Dockerfile.onbuild b/Dockerfile.onbuild index 5739d6f95..3e837aad6 100644 --- a/Dockerfile.onbuild +++ b/Dockerfile.onbuild @@ -18,5 +18,6 @@ ONBUILD COPY . /usr/src/app # clear out the development dependencies again. After this we of course need to # clear out the yarn cache, this saves quite a lot of size. ONBUILD RUN cli plugins reconcile && \ + yarn && \ yarn build && \ yarn cache clean \ No newline at end of file diff --git a/plugins/talk-plugin-notifications/server/hooks.js b/plugins/talk-plugin-notifications/server/hooks.js new file mode 100644 index 000000000..2a7eab608 --- /dev/null +++ b/plugins/talk-plugin-notifications/server/hooks.js @@ -0,0 +1,37 @@ +const { isValidJSValue } = require('graphql'); + +module.exports = { + NotificationSettings: { + digestFrequency: { + // This hook will swap out the digest frequency with `NONE` in the event + // that an org had a digest plugin enabled and later switched it off. This + // will force users that have previously had a digested option enabled to + // get notifications immediately until they update their frequency + // options. + post: async (settings, args, ctx, { schema }, frequency) => { + try { + // Validate that the type is correct. + const errors = isValidJSValue( + frequency, + schema.getType('DIGEST_FREQUENCY') + ); + if (errors && errors.length > 0) { + ctx.log.info( + { frequency }, + 'invalid frequency, swapping with `NONE`, plugin likely disabled' + ); + // Fallback to 'NONE' if the digest value has an error. + frequency = 'NONE'; + } + } catch (err) { + ctx.log.error({ err }, 'could not check if the type was valid'); + + // Fallback to 'NONE' if we couldn't validate the value. + frequency = 'NONE'; + } + + return frequency; + }, + }, + }, +}; diff --git a/plugins/talk-plugin-notifications/server/index.js b/plugins/talk-plugin-notifications/server/index.js index 0c7e993b9..816b9fbe3 100644 --- a/plugins/talk-plugin-notifications/server/index.js +++ b/plugins/talk-plugin-notifications/server/index.js @@ -1,16 +1,19 @@ const path = require('path'); -const connect = require('./connect'); -const typeDefs = require('./typeDefs'); -const resolvers = require('./resolvers'); -const router = require('./router'); -const mutators = require('./mutators'); const translations = path.join(__dirname, 'translations.yml'); +const connect = require('./connect'); +const hooks = require('./hooks'); +const mutators = require('./mutators'); +const resolvers = require('./resolvers'); +const router = require('./router'); +const typeDefs = require('./typeDefs'); + module.exports = { + connect, + hooks, + mutators, + resolvers, + router, translations, typeDefs, - resolvers, - mutators, - connect, - router, };