diff --git a/app/soapbox/actions/admin.js b/app/soapbox/actions/admin.js index 1667c782e..85910af9d 100644 --- a/app/soapbox/actions/admin.js +++ b/app/soapbox/actions/admin.js @@ -45,6 +45,14 @@ export const ADMIN_LOG_FETCH_REQUEST = 'ADMIN_LOG_FETCH_REQUEST'; export const ADMIN_LOG_FETCH_SUCCESS = 'ADMIN_LOG_FETCH_SUCCESS'; export const ADMIN_LOG_FETCH_FAIL = 'ADMIN_LOG_FETCH_FAIL'; +export const ADMIN_USERS_TAG_REQUEST = 'ADMIN_USERS_TAG_REQUEST'; +export const ADMIN_USERS_TAG_SUCCESS = 'ADMIN_USERS_TAG_SUCCESS'; +export const ADMIN_USERS_TAG_FAIL = 'ADMIN_USERS_TAG_FAIL'; + +export const ADMIN_USERS_UNTAG_REQUEST = 'ADMIN_USERS_UNTAG_REQUEST'; +export const ADMIN_USERS_UNTAG_SUCCESS = 'ADMIN_USERS_UNTAG_SUCCESS'; +export const ADMIN_USERS_UNTAG_FAIL = 'ADMIN_USERS_UNTAG_FAIL'; + export function fetchConfig() { return (dispatch, getState) => { dispatch({ type: ADMIN_CONFIG_FETCH_REQUEST }); @@ -197,3 +205,31 @@ export function fetchModerationLog(params) { }); }; } + +export function tagUsers(accountIds, tags) { + return (dispatch, getState) => { + const nicknames = accountIds.map(id => getState().getIn(['accounts', id, 'acct'])); + dispatch({ type: ADMIN_USERS_TAG_REQUEST, accountIds, tags }); + return api(getState) + .put('/api/v1/pleroma/admin/users/tag', { nicknames, tags }) + .then(() => { + dispatch({ type: ADMIN_USERS_TAG_SUCCESS, accountIds, tags }); + }).catch(error => { + dispatch({ type: ADMIN_USERS_TAG_FAIL, error, accountIds, tags }); + }); + }; +} + +export function untagUsers(accountIds, tags) { + return (dispatch, getState) => { + const nicknames = accountIds.map(id => getState().getIn(['accounts', id, 'acct'])); + dispatch({ type: ADMIN_USERS_UNTAG_REQUEST, accountIds, tags }); + return api(getState) + .delete('/api/v1/pleroma/admin/users/tag', { data: { nicknames, tags } }) + .then(() => { + dispatch({ type: ADMIN_USERS_UNTAG_SUCCESS, accountIds, tags }); + }).catch(error => { + dispatch({ type: ADMIN_USERS_UNTAG_FAIL, error, accountIds, tags }); + }); + }; +} diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index e023564f7..278853097 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -19,6 +19,7 @@ import ProfileInfoPanel from '../../ui/components/profile_info_panel'; import { debounce } from 'lodash'; import StillImage from 'soapbox/components/still_image'; import ActionButton from 'soapbox/features/ui/components/action_button'; +import { isVerified } from 'soapbox/utils/accounts'; const messages = defineMessages({ edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' }, @@ -48,6 +49,8 @@ const messages = defineMessages({ add_or_remove_from_list: { id: 'account.add_or_remove_from_list', defaultMessage: 'Add or Remove from lists' }, deactivateUser: { id: 'admin.users.actions.deactivate_user', defaultMessage: 'Deactivate @{name}' }, deleteUser: { id: 'admin.users.actions.delete_user', defaultMessage: 'Delete @{name}' }, + verifyUser: { id: 'admin.users.actions.verify_user', defaultMessage: 'Verify @{name}' }, + unverifyUser: { id: 'admin.users.actions.unverify_user', defaultMessage: 'Unverify @{name}' }, }); const mapStateToProps = state => { @@ -171,6 +174,13 @@ class Header extends ImmutablePureComponent { if (account.get('id') !== me && isStaff) { menu.push(null); menu.push({ text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), href: `/pleroma/admin/#/users/${account.get('id')}/`, newTab: true }); + + if (isVerified(account)) { + menu.push({ text: intl.formatMessage(messages.unverifyUser, { name: account.get('username') }), action: this.props.onUnverifyUser }); + } else { + menu.push({ text: intl.formatMessage(messages.verifyUser, { name: account.get('username') }), action: this.props.onVerifyUser }); + } + menu.push({ text: intl.formatMessage(messages.deactivateUser, { name: account.get('username') }), action: this.props.onDeactivateUser }); menu.push({ text: intl.formatMessage(messages.deleteUser, { name: account.get('username') }), action: this.props.onDeleteUser }); } diff --git a/app/soapbox/features/account_timeline/components/header.js b/app/soapbox/features/account_timeline/components/header.js index 86798d3ab..a16053fc9 100644 --- a/app/soapbox/features/account_timeline/components/header.js +++ b/app/soapbox/features/account_timeline/components/header.js @@ -92,6 +92,14 @@ export default class Header extends ImmutablePureComponent { this.props.onDeleteUser(this.props.account); } + handleVerifyUser = () => { + this.props.onVerifyUser(this.props.account); + } + + handleUnverifyUser = () => { + this.props.onUnverifyUser(this.props.account); + } + render() { const { account, identity_proofs } = this.props; const moved = (account) ? account.get('moved') : false; @@ -117,6 +125,8 @@ export default class Header extends ImmutablePureComponent { onAddToList={this.handleAddToList} onDeactivateUser={this.handleDeactivateUser} onDeleteUser={this.handleDeleteUser} + onVerifyUser={this.handleVerifyUser} + onUnverifyUser={this.handleUnverifyUser} username={this.props.username} /> diff --git a/app/soapbox/features/account_timeline/containers/header_container.js b/app/soapbox/features/account_timeline/containers/header_container.js index 8d6438894..fdf0b19e3 100644 --- a/app/soapbox/features/account_timeline/containers/header_container.js +++ b/app/soapbox/features/account_timeline/containers/header_container.js @@ -25,12 +25,16 @@ import { getSettings } from 'soapbox/actions/settings'; import { startChat, openChat } from 'soapbox/actions/chats'; import { isMobile } from 'soapbox/is_mobile'; import { deactivateUserModal, deleteUserModal } from 'soapbox/actions/moderation'; +import { tagUsers, untagUsers } from 'soapbox/actions/admin'; +import snackbar from 'soapbox/actions/snackbar'; const messages = defineMessages({ unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' }, blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' }, blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' }, blockAndReport: { id: 'confirmations.block.block_and_report', defaultMessage: 'Block & Report' }, + userVerified: { id: 'admin.users.user_verified_message', defaultMessage: '@{acct} was verified' }, + userUnverified: { id: 'admin.users.user_unverified_message', defaultMessage: '@{acct} was unverified' }, }); const makeMapStateToProps = () => { @@ -154,6 +158,20 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onDeleteUser(account) { dispatch(deleteUserModal(intl, account.get('id'))); }, + + onVerifyUser(account) { + const message = intl.formatMessage(messages.userVerified, { acct: account.get('acct') }); + dispatch(tagUsers([account.get('id')], ['verified'])).then(() => { + dispatch(snackbar.success(message)); + }).catch(() => {}); + }, + + onUnverifyUser(account) { + const message = intl.formatMessage(messages.userUnverified, { acct: account.get('acct') }); + dispatch(untagUsers([account.get('id')], ['verified'])).then(() => { + dispatch(snackbar.info(message)); + }).catch(() => {}); + }, }); export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header)); diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 643c19c0f..110b55c6e 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -21,6 +21,7 @@ import { } from 'immutable'; import { patchMe } from 'soapbox/actions/me'; import { unescape } from 'lodash'; +import { isVerified } from 'soapbox/utils/accounts'; const messages = defineMessages({ heading: { id: 'column.edit_profile', defaultMessage: 'Edit profile' }, @@ -161,7 +162,7 @@ class EditProfile extends ImmutablePureComponent { render() { const { intl, maxFields, account } = this.props; - const verified = account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified'); + const verified = isVerified(account); return ( diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index f8f869ad5..5a908941d 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -6,8 +6,18 @@ import { import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats'; import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer'; -import { Map as ImmutableMap, fromJS } from 'immutable'; +import { + Map as ImmutableMap, + List as ImmutableList, + fromJS, +} from 'immutable'; import { normalizePleromaUserFields } from 'soapbox/utils/pleroma'; +import { + ADMIN_USERS_TAG_REQUEST, + ADMIN_USERS_TAG_FAIL, + ADMIN_USERS_UNTAG_REQUEST, + ADMIN_USERS_UNTAG_FAIL, +} from 'soapbox/actions/admin'; const initialState = ImmutableMap(); @@ -43,6 +53,26 @@ const importAccountsFromChats = (state, chats) => state.withMutations(mutable => chats.forEach(chat => importAccountFromChat(mutable, chat))); +const addTags = (state, accountIds, tags) => { + return state.withMutations(state => { + accountIds.forEach(id => { + state.updateIn([id, 'pleroma', 'tags'], ImmutableList(), v => + v.toOrderedSet().union(tags).toList(), + ); + }); + }); +}; + +const removeTags = (state, accountIds, tags) => { + return state.withMutations(state => { + accountIds.forEach(id => { + state.updateIn([id, 'pleroma', 'tags'], ImmutableList(), v => + v.toOrderedSet().subtract(tags).toList(), + ); + }); + }); +}; + export default function accounts(state = initialState, action) { switch(action.type) { case ACCOUNT_IMPORT: @@ -58,6 +88,12 @@ export default function accounts(state = initialState, action) { case CHAT_FETCH_SUCCESS: case STREAMING_CHAT_UPDATE: return importAccountsFromChats(state, [action.chat]); + case ADMIN_USERS_TAG_REQUEST: + case ADMIN_USERS_UNTAG_FAIL: + return addTags(state, action.accountIds, action.tags); + case ADMIN_USERS_UNTAG_REQUEST: + case ADMIN_USERS_TAG_FAIL: + return removeTags(state, action.accountIds, action.tags); default: return state; } diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js index acc4cde65..7e25f868c 100644 --- a/app/soapbox/utils/accounts.js +++ b/app/soapbox/utils/accounts.js @@ -45,3 +45,7 @@ export const isLocal = account => { let domain = account.get('acct').split('@')[1]; return domain === undefined ? true : false; }; + +export const isVerified = account => ( + account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified') +);