Move "global switchoff" code from plugin to core

This commit is contained in:
Fabian Neumann
2018-04-26 13:12:27 +02:00
parent fab15daacd
commit 48fc3ab5db
24 changed files with 105 additions and 150 deletions
-1
View File
@@ -35,7 +35,6 @@ plugins/*
!plugins/talk-plugin-facebook-auth
!plugins/talk-plugin-featured-comments
!plugins/talk-plugin-flag-details
!plugins/talk-plugin-global-switchoff
!plugins/talk-plugin-google-auth
!plugins/talk-plugin-ignore-user
!plugins/talk-plugin-like
@@ -82,6 +82,20 @@ class StreamSettings extends React.Component {
this.props.updatePending({ updater });
};
updateGlobalSwitchoffEnable = () => {
const updater = {
globalSwitchoffEnable: {
$set: !this.props.settings.globalSwitchoffEnable,
},
};
this.props.updatePending({ updater });
};
updateGlobalSwitchoffMessage = value => {
const updater = { globalSwitchoffMessage: { $set: value } };
this.props.updatePending({ updater });
};
updateAutoClose = () => {
const updater = {
autoCloseStream: { $set: !this.props.settings.autoCloseStream },
@@ -192,6 +206,25 @@ class StreamSettings extends React.Component {
 
{t('configure.edit_comment_timeframe_text_post')}
</ConfigureCard>
<ConfigureCard
checked={settings.globalSwitchoffEnable}
onCheckbox={this.updateGlobalSwitchoffEnable}
title={t('configure.global_switchoff_title')}
>
<p>{t('configure.global_switchoff_desc')}</p>
<div
className={cn(
styles.configSettingGlobalSwitchoff,
settings.globalSwitchoffEnable ? null : styles.hidden
)}
>
<MarkdownEditor
className={styles.descriptionBox}
onChange={this.updateGlobalSwitchoffMessage}
value={settings.globalSwitchoffMessage}
/>
</div>
</ConfigureCard>
<ConfigureCard
checked={settings.autoCloseStream}
onCheckbox={this.updateAutoClose}
@@ -39,6 +39,8 @@ export default compose(
autoCloseStream
closedTimeout
closedMessage
globalSwitchoffEnable
globalSwitchoffMessage
${getSlotFragmentSpreads(slots, 'settings')}
}
`,
@@ -4,6 +4,7 @@ import StreamError from './StreamError';
import Comment from '../containers/Comment';
import BannedAccount from '../../../components/BannedAccount';
import ChangeUsername from '../containers/ChangeUsername';
import Markdown from 'coral-framework/components/Markdown';
import Slot from 'coral-framework/components/Slot';
import InfoBox from './InfoBox';
import { can } from 'coral-framework/services/perms';
@@ -215,7 +216,7 @@ class Stream extends React.Component {
currentUser,
} = this.props;
const { keepCommentBox } = this.state;
const open = !asset.isClosed;
const open = !(asset.isClosed || asset.settings.globalSwitchoffEnable);
const banned = get(currentUser, 'status.banned.status');
const suspensionUntil = get(currentUser, 'status.suspension.until');
@@ -293,7 +294,13 @@ class Stream extends React.Component {
)}
</div>
) : (
<p>{asset.settings.closedMessage}</p>
<div>
{asset.isClosed ? (
<p>{asset.settings.closedMessage}</p>
) : (
<Markdown content={asset.settings.globalSwitchoffMessage} />
)}
</div>
)}
<Slot fill="stream" passthrough={slotPassthrough} />
@@ -434,6 +434,8 @@ const fragments = {
questionBoxIcon
closedTimeout
closedMessage
globalSwitchoffEnable
globalSwitchoffMessage
charCountEnable
charCount
requireEmailConfirmation
+19
View File
@@ -161,6 +161,24 @@ class ErrAssetCommentingClosed extends TalkError {
}
}
// ErrCommentingDisabled is returned when a comment or action is attempted while
// commenting has been disabled site-wide.
class ErrCommentingDisabled extends TalkError {
constructor(message = null) {
super(
'asset commenting is closed',
{
status: 400,
translation_key: 'COMMENTING_DISABLED',
},
{
// Include the closedMessage in the metadata piece of the error.
message,
}
);
}
}
/**
* ErrAuthentication is returned when there is an error authenticating and the
* message is provided.
@@ -387,6 +405,7 @@ module.exports = {
ErrAuthentication,
ErrCannotIgnoreStaff,
ErrCommentTooShort,
ErrCommentingDisabled,
ErrContainsProfanity,
ErrEditWindowHasEnded,
ErrEmailAlreadyVerified,
+14
View File
@@ -837,6 +837,13 @@ type Settings {
# closed.
closedMessage: String
# globalSwitchoffEnable will disable commenting site-wide.
globalSwitchoffEnable: Boolean
# globalSwitchoffMessage will be shown above the comment stream while
# commenting is disabled site-wide.
globalSwitchoffMessage: String
# editCommentWindowLength is the length of time (in milliseconds) after a
# comment is posted that it can still be edited by the author.
editCommentWindowLength: Int
@@ -1300,6 +1307,13 @@ input UpdateSettingsInput {
# closed.
closedMessage: String
# globalSwitchoffEnable will disable commenting site-wide.
globalSwitchoffEnable: Boolean
# globalSwitchoffMessage will be shown above the comment stream while
# commenting is disabled site-wide.
globalSwitchoffMessage: String
# charCountEnable is true when the character count restriction is enabled.
charCountEnable: Boolean
+3
View File
@@ -136,6 +136,8 @@ de:
enable_premod_links_description: "Moderatoren müssen jeden Kommentar, der einen Link enthält, freigeben, bevor er veröffentlicht wird."
enable_questionbox: "Stellen Sie den Lesern eine Frage"
enable_questionbox_description: "Diese Frage erscheint am Anfang des Kommentarbereichs. Regen Sie eine Diskussion an."
global_switchoff_title: "Kommentieren global deaktivieren"
global_switchoff_desc: "Verfassen Sie eine Nachricht, die angezeigt wird, solange das Kommentieren deaktiviert ist."
hours: Stunden
include_comment_stream: "Einleitung zum Kommentarbereich"
include_comment_stream_desc: "Verfassen Sie eine Einleitung, die über jedem Kommentarbereich erscheint. Nützlich z.B. für Community-Richtlinien."
@@ -223,6 +225,7 @@ de:
LOGIN_MAXIMUM_EXCEEDED: "Sie haben zu häufig erfolglos versucht, sich anzumelden. Bitte warten Sie."
PASSWORD_REQUIRED: "Passwort ist erforderlich"
COMMENTING_CLOSED: "Kommentarbereich ist bereits geschlossen"
COMMENTING_DISABLED: "Die Kommentarfunktion ist derzeit abgeschaltet"
NOT_FOUND: "Ressource nicht gefunden"
ALREADY_EXISTS: "Ressource existiert bereits"
INVALID_ASSET_URL: "Asset-URL ist ungültig"
+3
View File
@@ -140,6 +140,8 @@ en:
enable_premod_links_description: "Moderators must approve any comment containing a link before it is published."
enable_questionbox: "Ask Readers a Question"
enable_questionbox_description: "This question will appear at the top of this comment stream. Ask readers about a certain issue in the article or pose discussion questions etc."
global_switchoff_title: "Deactivate commenting site-wide"
global_switchoff_desc: "Write a message that will be displayed while commenting is deactivated."
hours: Hours
include_comment_stream: "Include Comment Stream Description for Readers"
include_comment_stream_desc: "Write a message to be added to the top of your comment stream. Pose a topic include community guidelines etc."
@@ -247,6 +249,7 @@ en:
LOGIN_MAXIMUM_EXCEEDED: "You have made too many unsuccessful password attempts. Please wait."
PASSWORD_REQUIRED: "Must input a password"
COMMENTING_CLOSED: "Commenting is already closed"
COMMENTING_DISABLED: "Commenting is currently disabled on this site"
NOT_FOUND: "Resource not found"
ALREADY_EXISTS: "Resource already exists"
INVALID_ASSET_URL: "Assert URL is invalid"
+8
View File
@@ -66,6 +66,14 @@ const Setting = new Schema(
type: String,
default: 'Expired',
},
globalSwitchoffEnable: {
type: Boolean,
default: false,
},
globalSwitchoffMessage: {
type: String,
default: '',
},
wordlist: {
banned: {
type: Array,
@@ -1,23 +0,0 @@
{
"env": {
"browser": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
}
},
"parser": "babel-eslint",
"plugins": [
"react"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
@@ -1,48 +0,0 @@
import React from 'react';
import ConfigureCard from 'coral-framework/components/ConfigureCard';
import MarkdownEditor from 'coral-framework/components/MarkdownEditor';
import t from 'coral-framework/services/i18n';
import cn from 'classnames';
import styles from './styles.css';
const plugin = 'talk-plugin-global-switchoff';
class GlobalSwitchoff extends React.Component {
updateGlobalSwitchoffEnable = () => {
const updater = {
globalSwitchoffEnable: {
$set: !this.props.settings.globalSwitchoffEnable,
},
};
this.props.updatePending({ updater });
};
updateGlobalSwitchoffMessage = () => {};
render() {
const { settings } = this.props;
return (
<ConfigureCard
checked={settings.globalSwitchoffEnable}
onCheckbox={this.updateGlobalSwitchoffEnable}
title={t(plugin + '.setting_title')}
>
<p>{t(plugin + '.setting_desc')}</p>
<div
className={cn(
styles.configSettingGlobalSwitchoff,
settings.globalSwitchoffEnable ? null : styles.hidden
)}
>
<MarkdownEditor
className={styles.descriptionBox}
onChange={this.updateGlobalSwitchoffMessage}
value={settings.globalSwitchoffMessage}
/>
</div>
</ConfigureCard>
);
}
}
export default GlobalSwitchoff;
@@ -1,12 +0,0 @@
import { gql } from 'react-apollo';
import GlobalSwitchoff from '../components/GlobalSwitchoff';
import { withFragments } from 'plugin-api/beta/client/hocs';
export default withFragments({
settings: gql`
fragment TalkPlugin_GlobalSwitchoff_settings on Settings {
globalSwitchoffEnable
globalSwitchoffMessage
}
`,
})(GlobalSwitchoff);
@@ -1,9 +0,0 @@
import GlobalSwitchoff from './containers/GlobalSwitchoff';
import translations from './translations.yml';
export default {
translations,
slots: {
adminStreamSettings: [GlobalSwitchoff],
},
};
@@ -1,8 +0,0 @@
en:
talk-plugin-global-switchoff:
setting_title: 'Deactivate commenting globally'
setting_desc: 'Write a message that will be displayed while commenting is deactivated.'
de:
talk-plugin-global-switchoff:
setting_title: 'Kommentieren global deaktivieren'
setting_desc: 'Verfassen Sie eine Nachricht, die angezeigt wird, solange das Kommentieren deaktiviert ist.'
@@ -1,13 +0,0 @@
const { readFileSync } = require('fs');
const path = require('path');
const hooks = require('./server/hooks');
const resolvers = require('./server/resolvers');
module.exports = {
typeDefs: readFileSync(
path.join(__dirname, 'server/typeDefs.graphql'),
'utf8'
),
hooks,
resolvers,
};
@@ -1,13 +0,0 @@
module.exports = {
RootMutation: {
updateSettings: {
async pre(_, { input }) {
input.metadata = {
...input.metadata,
globalSwitchoffEnable: input.globalSwitchoffEnable,
};
delete input.globalSwitchoffEnable;
},
},
},
};
@@ -1 +0,0 @@
module.exports = {};
@@ -1,10 +0,0 @@
const { get } = require('lodash');
module.exports = {
Settings: {
globalSwitchoffEnable: settings =>
get(settings, 'metadata.globalSwitchoffEnable', false),
globalSwitchoffMessage: settings =>
get(settings, 'metadata.globalSwitchoffMessage', ''),
},
};
@@ -1,10 +0,0 @@
type Settings {
globalSwitchoffEnable: Boolean
globalSwitchoffMessage: String
}
input UpdateSettingsInput {
globalSwitchoffEnable: Boolean
globalSwitchoffMessage: String
}
+2
View File
@@ -6,6 +6,7 @@ const {
wordlist,
commentLength,
assetClosed,
commentingDisabled,
karma,
staff,
links,
@@ -36,6 +37,7 @@ const applyStatus = status => () => ({ status });
const phases = [
commentLength,
assetClosed,
commentingDisabled,
wordlist,
staff,
links,
@@ -0,0 +1,9 @@
const { ErrCommentingDisabled } = require('../../../errors');
// This phase checks to see if commenting is site-wide disabled.
module.exports = (ctx, comment, { asset }) => {
// Check to see if the asset has closed commenting...
if (asset.settings.globalSwitchoffEnable) {
throw new ErrCommentingDisabled(asset.settings.globalSwitchoffMessage);
}
};
+1
View File
@@ -1,6 +1,7 @@
module.exports.wordlist = require('./wordlist');
module.exports.commentLength = require('./commentLength');
module.exports.assetClosed = require('./assetClosed');
module.exports.commentingDisabled = require('./commentingDisabled');
module.exports.karma = require('./karma');
module.exports.staff = require('./staff');
module.exports.links = require('./links');