@@ -17,4 +17,3 @@ export default ({children, restricted, message = lang.t('contentNotAvailable'),
}
};
-const messageBox = (message) =>
{message}
;
diff --git a/client/coral-framework/components/RestrictedMessageBox.css b/client/coral-framework/components/RestrictedMessageBox.css
new file mode 100644
index 000000000..94b193a17
--- /dev/null
+++ b/client/coral-framework/components/RestrictedMessageBox.css
@@ -0,0 +1,6 @@
+.message {
+ background: #D8D8D8;
+ padding: 25px;
+ margin-bottom: 8px;
+}
+
diff --git a/client/coral-framework/components/RestrictedMessageBox.js b/client/coral-framework/components/RestrictedMessageBox.js
new file mode 100644
index 000000000..c579a4731
--- /dev/null
+++ b/client/coral-framework/components/RestrictedMessageBox.js
@@ -0,0 +1,4 @@
+import React from 'react';
+import styles from './RestrictedMessageBox.css';
+
+export default ({children}) =>
{children}
;
diff --git a/client/coral-framework/translations.json b/client/coral-framework/translations.json
index 2e4c405b4..2ea58e159 100644
--- a/client/coral-framework/translations.json
+++ b/client/coral-framework/translations.json
@@ -7,6 +7,8 @@
"successNameUpdate": "Your username has been updated",
"contentNotAvailable": "This content is not available",
"bannedAccountMsg": "Your account is currently suspended. This means that you cannot Like, Report, or write comments. Please contact us if you have any questions.",
+
+ "temporarilySuspended": "In accordance with {0}'s community guidlines, your account has been temporarily suspended. Please rejoin the conversation {1}.",
"editName": {
"msg": "Your account is currently suspended because your username has been deemed inappropriate. To restore your account, please enter a new username. Please contact us if you have any questions.",
"label": "New Username",
diff --git a/client/coral-framework/utils/index.js b/client/coral-framework/utils/index.js
index 512759e98..8fb9cbf81 100644
--- a/client/coral-framework/utils/index.js
+++ b/client/coral-framework/utils/index.js
@@ -64,10 +64,39 @@ export function separateDataAndRoot(
};
}
+/**
+ * Taken from: http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object.
+ * Adds time to a date. Modelled after MySQL DATE_ADD function.
+ * Example: dateAdd(new Date(), 'minute', 30) //returns 30 minutes from now.
+ *
+ * @param date Date to start with
+ * @param interval One of: year, quarter, month, week, day, hour, minute, second
+ * @param units Number of units of the given interval to add.
+ */
+export function dateAdd(date, interval, units) {
+ let ret = new Date(date); // don't change original date
+ const checkRollover = () => {
+ if (ret.getDate() !== date.getDate()) {
+ ret.setDate(0);
+ }
+ };
+ switch(interval.toLowerCase()) {
+ case 'year' : ret.setFullYear(ret.getFullYear() + units); checkRollover(); break;
+ case 'quarter': ret.setMonth(ret.getMonth() + 3 * units); checkRollover(); break;
+ case 'month' : ret.setMonth(ret.getMonth() + units); checkRollover(); break;
+ case 'week' : ret.setDate(ret.getDate() + 7 * units); break;
+ case 'day' : ret.setDate(ret.getDate() + units); break;
+ case 'hour' : ret.setTime(ret.getTime() + units * 3600000); break;
+ case 'minute' : ret.setTime(ret.getTime() + units * 60000); break;
+ case 'second' : ret.setTime(ret.getTime() + units * 1000); break;
+ default : ret = undefined; break;
+ }
+ return ret;
+}
+
export function mergeDocuments(documents) {
const main = typeof documents[0] === 'string' ? documents[0] : documents[0].loc.source.body;
const substitutions = documents.slice(1);
const literals = [main, ...substitutions.map(() => '\n')];
return gql.apply(null, [literals, ...substitutions]);
}
-
diff --git a/client/coral-sign-in/containers/ChangeUsernameContainer.js b/client/coral-sign-in/containers/ChangeUsernameContainer.js
index 12a9a75b8..cebd9605b 100644
--- a/client/coral-sign-in/containers/ChangeUsernameContainer.js
+++ b/client/coral-sign-in/containers/ChangeUsernameContainer.js
@@ -104,7 +104,7 @@ class ChangeUsernameContainer extends Component {
return (
.icon {
+ margin-right: 5px;
+ font-size: 14px;
+ }
}
.full {
diff --git a/client/coral-ui/components/Button.js b/client/coral-ui/components/Button.js
index 52d806adb..6d3dc94d2 100644
--- a/client/coral-ui/components/Button.js
+++ b/client/coral-ui/components/Button.js
@@ -13,7 +13,7 @@ const Button = ({cStyle = 'local', children, className, raised = false, full = f
`}
{...props}
>
- {icon && }
+ {icon && }
{children}
);
diff --git a/graph/mutators/user.js b/graph/mutators/user.js
index 2cc1962be..34cfd4355 100644
--- a/graph/mutators/user.js
+++ b/graph/mutators/user.js
@@ -5,8 +5,12 @@ const setUserStatus = ({user}, {id, status}) => {
return UsersService.setStatus(id, status);
};
-const suspendUser = ({user}, {id, message}) => {
- return UsersService.suspendUser(id, message);
+const suspendUser = ({user}, {id, message, until}) => {
+ return UsersService.suspendUser(id, message, until);
+};
+
+const rejectUsername = ({user}, {id, message}) => {
+ return UsersService.rejectUsername(id, message);
};
const ignoreUser = ({user}, userToIgnore) => {
@@ -22,6 +26,7 @@ module.exports = (context) => {
User: {
setUserStatus: () => Promise.reject(errors.ErrNotAuthorized),
suspendUser: () => Promise.reject(errors.ErrNotAuthorized),
+ rejectUsername: () => Promise.reject(errors.ErrNotAuthorized),
ignoreUser: (action) => ignoreUser(context, action),
stopIgnoringUser: (action) => stopIgnoringUser(context, action),
}
@@ -35,5 +40,9 @@ module.exports = (context) => {
mutators.User.suspendUser = (action) => suspendUser(context, action);
}
+ if (context.user && context.user.can('mutation:rejectUsername')) {
+ mutators.User.rejectUsername = (action) => rejectUsername(context, action);
+ }
+
return mutators;
};
diff --git a/graph/resolvers/comment.js b/graph/resolvers/comment.js
index 6f3313356..7273bf58a 100644
--- a/graph/resolvers/comment.js
+++ b/graph/resolvers/comment.js
@@ -25,9 +25,9 @@ const Comment = {
// TODO: remove
if (user && excludeIgnored) {
- return Comments.countByParentIDPersonalized({id, excludeIgnored});
+ return Comments.countByParentIDPersonalized({id, excludeIgnored});
}
- return Comments.countByParentID.load(id);
+ return Comments.countByParentID.load(id);
},
actions({id}, _, {user, loaders: {Actions}}) {
diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js
index 2abc88f0d..e17cdcc8a 100644
--- a/graph/resolvers/root_mutation.js
+++ b/graph/resolvers/root_mutation.js
@@ -20,8 +20,11 @@ const RootMutation = {
setUserStatus(_, {id, status}, {mutators: {User}}) {
return wrapResponse(null)(User.setUserStatus({id, status}));
},
- suspendUser(_, {id, message}, {mutators: {User}}) {
- return wrapResponse(null)(User.suspendUser({id, message}));
+ suspendUser(_, {input: {id, message, until}}, {mutators: {User}}) {
+ return wrapResponse(null)(User.suspendUser({id, message, until}));
+ },
+ rejectUsername(_, {input: {id, message}}, {mutators: {User}}) {
+ return wrapResponse(null)(User.rejectUsername({id, message}));
},
ignoreUser(_, {id}, {mutators: {User}}) {
return wrapResponse(null)(User.ignoreUser({id}));
diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql
index b11889865..1abb894b8 100644
--- a/graph/typeDefs.graphql
+++ b/graph/typeDefs.graphql
@@ -443,6 +443,7 @@ type Settings {
charCountEnable: Boolean
charCount: Int
+ organizationName: String
}
################################################################################
@@ -711,6 +712,29 @@ input CreateDontAgreeInput {
message: String
}
+# Input for suspendUser mutation.
+input SuspendUserInput {
+
+ # id of target user.
+ id: ID!
+
+ # message to be sent to the user.
+ message: String!
+
+ # target user will be suspended until this date.
+ until: Date!
+}
+
+# Input for rejectUsername mutation.
+input RejectUsernameInput {
+
+ # id of target user.
+ id: ID!
+
+ # message to be sent to the user.
+ message: String!
+}
+
# DeleteActionResponse is the response returned with possibly some errors
# relating to the delete action attempt.
type DeleteActionResponse implements Response {
@@ -735,6 +759,14 @@ type SuspendUserResponse implements Response {
errors: [UserError]
}
+# RejectUsernameResponse is the response returned with possibly some errors
+# relating to the reject username action attempt.
+type RejectUsernameResponse implements Response {
+
+ # An array of errors relating to the mutation that occurred.
+ errors: [UserError]
+}
+
# SetCommentStatusResponse is the response returned with possibly some errors
# relating to the delete action attempt.
type SetCommentStatusResponse implements Response {
@@ -807,8 +839,11 @@ type RootMutation {
# Sets User status. Requires the `ADMIN` role.
setUserStatus(id: ID!, status: USER_STATUS!): SetUserStatusResponse
- # Sets User status to BANNED and canEditName to true. It sends a message to the banned User. Requires the `ADMIN` role.
- suspendUser(id: ID!, message: String): SuspendUserResponse
+ # Suspends a user. Requires the `ADMIN` role.
+ suspendUser(input: SuspendUserInput!): SuspendUserResponse
+
+ # Suspends a user. Requires the `ADMIN` role.
+ rejectUsername(input: RejectUsernameInput!): RejectUsernameResponse
# Sets Comment status. Requires the `ADMIN` role.
setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse
diff --git a/models/user.js b/models/user.js
index 56f750d34..b02d2c3bc 100644
--- a/models/user.js
+++ b/models/user.js
@@ -111,6 +111,14 @@ const UserSchema = new mongoose.Schema({
default: false
},
+ // User's suspension details.
+ suspension: {
+ until: {
+ type: Date,
+ default: null,
+ },
+ },
+
// User's settings
settings: {
bio: {
@@ -197,6 +205,7 @@ const USER_GRAPH_OPERATIONS = [
'mutation:editName',
'mutation:setUserStatus',
'mutation:suspendUser',
+ 'mutation:rejectUsername',
'mutation:setCommentStatus',
'mutation:addCommentTag',
'mutation:removeCommentTag',
@@ -212,11 +221,12 @@ UserSchema.method('can', function(...actions) {
throw new Error(`invalid actions: ${actions}`);
}
- if (this.status === 'BANNED') {
+ if (this.status === 'BANNED' || (this.suspension.until && this.suspension.until > new Date())) {
return false;
}
- if (actions.some((action) => action === 'mutation:setUserStatus' || action === 'mutation:suspendUser' || action === 'mutation:setCommentStatus') && !this.hasRoles('ADMIN')) {
+ const adminOnlyActions = ['mutation:setUserStatus', 'mutation:suspendUser', 'mutation:rejectUsername', 'mutation:setCommentStatus'];
+ if (actions.some((action) => adminOnlyActions.indexOf(action) > 0 && !this.hasRoles('ADMIN'))) {
return false;
}
diff --git a/package.json b/package.json
index 76d822033..84d0fdf52 100644
--- a/package.json
+++ b/package.json
@@ -100,6 +100,7 @@
"prop-types": "^15.5.8",
"react-apollo": "^1.1.0",
"react-recaptcha": "^2.2.6",
+ "react-toastify": "^1.5.0",
"recompose": "^0.23.1",
"redis": "^2.7.1",
"resolve": "^1.3.2",
diff --git a/services/email/suspension.ejs b/services/email/suspension.ejs
deleted file mode 100644
index b36560ec5..000000000
--- a/services/email/suspension.ejs
+++ /dev/null
@@ -1 +0,0 @@
-<%= body %>
diff --git a/services/email/suspension.html.ejs b/services/email/suspension.html.ejs
index b36560ec5..4fd8f191c 100644
--- a/services/email/suspension.html.ejs
+++ b/services/email/suspension.html.ejs
@@ -1 +1 @@
-<%= body %>
+<%= body.replace(/\n/g, '
') %>
diff --git a/services/users.js b/services/users.js
index 0c83832ab..728569cd5 100644
--- a/services/users.js
+++ b/services/users.js
@@ -450,28 +450,64 @@ module.exports = class UsersService {
}
/**
- * Suspend a user. It changes the status to BANNED and canEditName to True.
- * @param {String} id id of a user
- * @param {Function} done callback after the operation is complete
+ * Suspend a user until specified time.
+ * @param {String} id id of a user
+ * @param {String} message message to be send to the user
+ * @param {Date} until date until the suspension is valid.
*/
- static suspendUser(id, message) {
+ static suspendUser(id, message, until) {
+ return UserModel.findOneAndUpdate(
+ {id}, {
+ $set: {
+ suspension: {
+ until,
+ },
+ }
+ })
+ .then((user) => {
+ if (message) {
+ let localProfile = user.profiles.find((profile) => profile.provider === 'local');
+ if (localProfile) {
+ const options =
+ {
+ template: 'suspension', // needed to know which template to render!
+ locals: { // specifies the template locals.
+ body: message
+ },
+ subject: 'Your account has been suspended',
+ to: localProfile.id // This only works if the user has registered via e-mail.
+ // We may want a standard way to access a user's e-mail address in the future
+ };
+
+ return MailerService.sendSimple(options);
+ }
+ }
+ });
+ }
+
+ /**
+ * Reject username. It changes the status to BANNED and canEditName to True.
+ * @param {String} id id of a user
+ * @param {String} message message to be send to the user
+ * @param {Date} until date until the suspension is valid.
+ */
+ static rejectUsername(id, message) {
return UserModel.findOneAndUpdate({
id
}, {
$set: {
status: 'BANNED',
- canEditName: true
+ canEditName: true,
}
})
.then((user) => {
if (message) {
let localProfile = user.profiles.find((profile) => profile.provider === 'local');
-
if (localProfile) {
const options =
{
template: 'suspension', // needed to know which template to render!
- locals: { // specifies the template locals.
+ locals: { // specifies the template locals.
body: message
},
subject: 'Email Suspension',
@@ -480,8 +516,6 @@ module.exports = class UsersService {
};
return MailerService.sendSimple(options);
- } else {
- return Promise.reject(errors.ErrMissingEmail);
}
}
});
@@ -813,7 +847,7 @@ module.exports = class UsersService {
username: username,
lowercaseUsername: username.toLowerCase(),
canEditName: false,
- status: 'PENDING'
+ status: 'PENDING',
}
})
.then((result) => {
diff --git a/yarn.lock b/yarn.lock
index 3cbe44a2b..728687248 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1480,6 +1480,10 @@ chai@^3.5.0:
deep-eql "^0.1.3"
type-detect "^1.0.0"
+chain-function@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"
+
chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -2441,6 +2445,10 @@ doctypes@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/doctypes/-/doctypes-1.1.0.tgz#ea80b106a87538774e8a3a4a5afe293de489e0a9"
+dom-helpers@^3.2.0:
+ version "3.2.1"
+ resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.2.1.tgz#3203e07fed217bd1f424b019735582fc37b2825a"
+
dom-serializer@0, dom-serializer@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82"
@@ -6862,6 +6870,22 @@ react-tagsinput@^3.14.0:
version "3.16.1"
resolved "https://registry.yarnpkg.com/react-tagsinput/-/react-tagsinput-3.16.1.tgz#dfb3bcbe5fc4430f60c145716c17cdc2613ce117"
+react-toastify@^1.5.0:
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-1.5.0.tgz#e9857e0b5d640064e5ba6caf7a96bb1578273de7"
+ dependencies:
+ prop-types "^15.5.8"
+ react-transition-group "^1.1.2"
+
+react-transition-group@^1.1.2:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.1.3.tgz#5e02cf6e44a863314ff3c68a0c826c2d9d70b221"
+ dependencies:
+ chain-function "^1.0.0"
+ dom-helpers "^3.2.0"
+ prop-types "^15.5.6"
+ warning "^3.0.0"
+
react@^15.3.1, react@^15.4.2:
version "15.5.4"
resolved "https://registry.yarnpkg.com/react/-/react-15.5.4.tgz#fa83eb01506ab237cdc1c8c3b1cea8de012bf047"