diff --git a/client/coral-admin/src/routes/Community/components/People.js b/client/coral-admin/src/routes/Community/components/People.js
index 9e5fbcd80..467175977 100644
--- a/client/coral-admin/src/routes/Community/components/People.js
+++ b/client/coral-admin/src/routes/Community/components/People.js
@@ -18,7 +18,6 @@ const People = (props) => {
totalPages,
page,
setUserRole,
- setUserBanStatus,
viewUserDetail,
} = props;
@@ -46,11 +45,14 @@ const People = (props) => {
users={users}
setUserRole={setUserRole}
viewUserDetail={viewUserDetail}
- setUserBanStatus={setUserBanStatus}
onHeaderClickHandler={onHeaderClickHandler}
pageCount={totalPages}
onPageChange={onPageChange}
page={page}
+ unBanUser={props.unBanUser}
+ unSuspendUser={props.unSuspendUser}
+ showSuspendUserDialog={props.showSuspendUserDialog}
+ showBanUserDialog={props.showBanUserDialog}
/>
: {t('community.no_results')}
}
@@ -67,9 +69,12 @@ People.propTypes = {
onSearchChange: PropTypes.func,
totalPages: PropTypes.number,
onPageChange: PropTypes.func,
- setUserBanStatus: PropTypes.func.isRequired,
setUserRole: PropTypes.func.isRequired,
viewUserDetail: PropTypes.func.isRequired,
+ unBanUser: PropTypes.func.isRequired,
+ unSuspendUser: PropTypes.func.isRequired,
+ showSuspendUserDialog: PropTypes.func,
+ showBanUserDialog: PropTypes.func,
};
export default People;
diff --git a/client/coral-admin/src/routes/Community/components/Table.js b/client/coral-admin/src/routes/Community/components/Table.js
index 35c10954b..6d40b5d28 100644
--- a/client/coral-admin/src/routes/Community/components/Table.js
+++ b/client/coral-admin/src/routes/Community/components/Table.js
@@ -4,6 +4,9 @@ import t from 'coral-framework/services/i18n';
import PropTypes from 'prop-types';
import {Paginate, Dropdown, Option} from 'coral-ui';
import cn from 'classnames';
+import ActionsMenu from 'coral-admin/src/components/ActionsMenu';
+import ActionsMenuItem from 'coral-admin/src/components/ActionsMenuItem';
+import {isSuspended, isBanned} from 'coral-framework/utils/user';
const headers = [
{
@@ -23,79 +26,120 @@ const headers = [
field: 'role'
}
];
-const getStatus = (status) => {
- return status.banned.status ? 'BANNED' : 'ACTIVE';
-};
-const Table = ({users, setUserRole, onHeaderClickHandler, setUserBanStatus, viewUserDetail, pageCount, page, onPageChange}) => (
-
-
-
-
- {headers.map((header, i) =>(
- | onHeaderClickHandler({field: header.field})}>
- {header.title}
- |
- ))}
-
-
-
- {users.map((row, i)=> (
-
- |
-
- {row.profiles.map(({id}) => id)}
- |
-
- {row.created_at}
- |
-
- setUserBanStatus(row.id, status === 'BANNED')}>
-
-
-
- |
-
- setUserRole(row.id, role)}>
-
-
-
-
-
- |
+const Table = (props) => {
+
+ const {
+ users,
+ setUserRole,
+ onHeaderClickHandler,
+ viewUserDetail,
+ pageCount,
+ page,
+ onPageChange,
+ unSuspendUser,
+ unBanUser,
+ showSuspendUserDialog,
+ showBanUserDialog,
+ } = props;
+
+ return (
+
+
+
+
+ {headers.map((header, i) =>(
+ | onHeaderClickHandler({field: header.field})}>
+ {header.title}
+ |
+ ))}
- ))}
-
-
-
-
-);
+
+
+ {users.map((user, i)=> (
+
+ |
+
+ {user.profiles.map(({id}) => id)}
+ |
+
+ {user.created_at}
+ |
+
+
+
+
+ {isSuspended(user) ? unSuspendUser({id: user.id})}>
+ Remove Suspension
+ : showSuspendUserDialog({
+ userId: user.id,
+ username: user.username,
+ })}>
+ Suspend User
+ }
+
+ {isBanned(user) ? unBanUser({id: user.id})}>
+ Remove Ban
+ : showBanUserDialog({
+ userId: user.id,
+ username: user.username,
+ })}>
+ Ban User
+ }
+
+
+ |
+
+ setUserRole(user.id, role)}>
+
+
+
+
+
+ |
+
+ ))}
+
+
+
+
+ );
+};
Table.propTypes = {
users: PropTypes.array,
onHeaderClickHandler: PropTypes.func.isRequired,
setUserRole: PropTypes.func.isRequired,
- setUserBanStatus: PropTypes.func.isRequired,
viewUserDetail: PropTypes.func.isRequired,
pageCount: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
onPageChange: PropTypes.func.isRequired,
+ showSuspendUserDialog: PropTypes.func,
+ showBanUserDialog: PropTypes.func,
+ unBanUser: PropTypes.func.isRequired,
+ unSuspendUser: PropTypes.func.isRequired,
};
export default Table;
diff --git a/client/coral-admin/src/routes/Community/containers/Community.js b/client/coral-admin/src/routes/Community/containers/Community.js
index 633116569..9b34a5264 100644
--- a/client/coral-admin/src/routes/Community/containers/Community.js
+++ b/client/coral-admin/src/routes/Community/containers/Community.js
@@ -6,6 +6,7 @@ import {getDefinitionName} from 'coral-framework/utils';
import {withRejectUsername} from 'coral-framework/graphql/mutations';
import FlaggedAccounts from '../containers/FlaggedAccounts';
import FlaggedUser from '../containers/FlaggedUser';
+import People from '../containers/People';
import {hideRejectUsernameDialog} from '../../../actions/community';
import Community from '../components/Community';
@@ -32,6 +33,7 @@ const withData = withQuery(gql`
)
...${getDefinitionName(FlaggedAccounts.fragments.root)}
...${getDefinitionName(FlaggedUser.fragments.root)}
+ ...${getDefinitionName(People.fragments.root)}
me {
...${getDefinitionName(FlaggedUser.fragments.me)}
__typename
@@ -39,6 +41,7 @@ const withData = withQuery(gql`
}
${FlaggedAccounts.fragments.root}
${FlaggedUser.fragments.root}
+ ${People.fragments.root}
${FlaggedUser.fragments.me}
`, {
options: {
diff --git a/client/coral-admin/src/routes/Community/containers/FlaggedAccounts.js b/client/coral-admin/src/routes/Community/containers/FlaggedAccounts.js
index 0313dd927..dc1573572 100644
--- a/client/coral-admin/src/routes/Community/containers/FlaggedAccounts.js
+++ b/client/coral-admin/src/routes/Community/containers/FlaggedAccounts.js
@@ -34,7 +34,7 @@ class FlaggedAccountsContainer extends Component {
},
updateQuery: (previous, {fetchMoreResult:{users}}) => {
const updated = update(previous, {
- users: {
+ flaggedUsers: {
nodes: {
$apply: (nodes) => appendNewNodes(nodes, users.nodes),
},
@@ -63,7 +63,7 @@ class FlaggedAccountsContainer extends Component {
loadMore={this.loadMore}
data={this.props.data}
root={this.props.root}
- users={this.props.root.users}
+ users={this.props.root.flaggedUsers}
me={this.props.root.me}
/>
);
@@ -80,7 +80,7 @@ FlaggedAccountsContainer.propTypes = {
const LOAD_MORE_QUERY = gql`
query TalkAdmin_LoadMoreFlaggedAccounts($limit: Int, $cursor: Cursor) {
- users(query:{
+ flaggedUsers: users(query:{
action_type: FLAG,
state: {
status: {
@@ -113,7 +113,7 @@ export default compose(
withFragments({
root: gql`
fragment TalkAdminCommunity_FlaggedAccounts_root on RootQuery {
- users(query:{
+ flaggedUsers: users(query:{
action_type: FLAG,
state: {
status: {
diff --git a/client/coral-admin/src/routes/Community/containers/People.js b/client/coral-admin/src/routes/Community/containers/People.js
index 3b769e60e..4a0a3c6fb 100644
--- a/client/coral-admin/src/routes/Community/containers/People.js
+++ b/client/coral-admin/src/routes/Community/containers/People.js
@@ -1,11 +1,13 @@
import React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
-import {compose} from 'react-apollo';
+import {compose, gql} from 'react-apollo';
import People from '../components/People';
import PropTypes from 'prop-types';
-import {withUnBanUser, withBanUser, withSetUserRole} from 'coral-framework/graphql/mutations';
-
+import {withFragments} from 'plugin-api/beta/client/hocs';
+import {withUnBanUser, withUnSuspendUser, withSetUserRole} from 'coral-framework/graphql/mutations';
+import {showBanUserDialog} from 'actions/banUserDialog';
+import {showSuspendUserDialog} from 'actions/suspendUserDialog';
import {viewUserDetail} from '../../../actions/userDetail';
import {
@@ -62,18 +64,6 @@ class PeopleContainer extends React.Component {
this.fetchUsers({page});
}
- setUserBanStatus = async (id, bannedStatus) => {
- const {banUser, unBanUser} = this.props;
-
- if (bannedStatus) {
- await banUser({id, message: ''});
- } else {
- await unBanUser({id});
- }
-
- await this.fetchUsers();
- }
-
setUserRole = async (id, role) => {
await this.props.setUserRole(id, role);
await this.fetchUsers();
@@ -87,10 +77,13 @@ class PeopleContainer extends React.Component {
onHeaderClickHandler={this.onHeaderClickHandler}
onPageChange={this.onPageChange}
totalPages={this.props.community.totalPagesPeople}
- setUserBanStatus={this.setUserBanStatus}
setUserRole={this.setUserRole}
page={this.props.community.pagePeople}
viewUserDetail={this.props.viewUserDetail}
+ showSuspendUserDialog={this.props.showSuspendUserDialog}
+ showBanUserDialog={this.props.showBanUserDialog}
+ unBanUser={this.props.unBanUser}
+ unSuspendUser={this.props.unBanUser}
/>;
}
}
@@ -100,11 +93,13 @@ PeopleContainer.propTypes = {
fetchUsers: PropTypes.func,
updateSorting: PropTypes.func,
setUserRole: PropTypes.func.isRequired,
- banUser: PropTypes.func.isRequired,
unBanUser: PropTypes.func.isRequired,
+ unSuspendUser: PropTypes.func.isRequired,
setSearchValue: PropTypes.func.isRequired,
viewUserDetail: PropTypes.func.isRequired,
community: PropTypes.object,
+ showSuspendUserDialog: PropTypes.func,
+ showBanUserDialog: PropTypes.func,
};
const mapDispatchToProps = (dispatch) =>
@@ -115,11 +110,28 @@ const mapDispatchToProps = (dispatch) =>
hideRejectUsernameDialog,
viewUserDetail,
setSearchValue,
+ showSuspendUserDialog,
+ showBanUserDialog,
}, dispatch);
export default compose(
connect(null, mapDispatchToProps),
- withBanUser,
- withUnBanUser,
withSetUserRole,
+ withUnBanUser,
+ withUnSuspendUser,
+ withFragments({
+ root: gql`
+ fragment TalkAdminCommunity_People_root on RootQuery {
+ users(query: {}){
+ hasNextPage
+ endCursor
+ nodes {
+ __typename
+ id
+ }
+ }
+ }
+
+ `,
+ }),
)(PeopleContainer);
diff --git a/client/coral-admin/src/utils/index.js b/client/coral-admin/src/utils/index.js
index f78a7b631..bd443ef5e 100644
--- a/client/coral-admin/src/utils/index.js
+++ b/client/coral-admin/src/utils/index.js
@@ -11,4 +11,3 @@ export const isPremod = (mod) => mod === 'PRE';
export const getModPath = (type = 'all', assetId) =>
assetId ? `/admin/moderate/${type}/${assetId}` : `/admin/moderate/${type}`;
-
diff --git a/client/coral-framework/utils/user.js b/client/coral-framework/utils/user.js
index ccdf8ba42..dfad5e89f 100644
--- a/client/coral-framework/utils/user.js
+++ b/client/coral-framework/utils/user.js
@@ -1,3 +1,5 @@
+import get from 'lodash/get';
+
/**
* getReliability
* retrieves reliability value as string
@@ -12,3 +14,22 @@ export const getReliability = (reliabilityValue) => {
return 'unreliable';
}
};
+
+/**
+ * isSuspended
+ * retrieves boolean based on the user suspension status
+ */
+
+export const isSuspended = (user) => {
+ const suspensionUntil = get(user, 'state.status.suspension.until');
+ return user && suspensionUntil && new Date(suspensionUntil) > new Date();
+};
+
+/**
+ * isBanned
+ * retrieves boolean based on the user ban status
+ */
+
+export const isBanned = (user) => {
+ return get(user, 'state.status.banned.status');
+};