From 8c04e37b033ff35174753fb82faa1cd7bed110da Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 27 Jun 2020 20:20:11 +0200 Subject: Remove the terms blacklist and whitelist from UX (#14149) Localization strings: - "Whitelist mode" -> "Limited federation mode" - "Blacklist e-mail domain" -> "Block e-mail domain" - "Whitelist domain" -> "Allow domain for federation" ...And so on Environment variables (backwards-compatible): - `WHITELIST_MODE` -> `LIMITED_FEDERATION_MODE` - `EMAIL_DOMAIN_BLACKLIST` -> `EMAIL_DOMAIN_DENYLIST` - `EMAIL_DOMAIN_WHITELIST` -> `EMAIL_DOMAIN_ALLOWLIST` tootctl: - `tootctl domains purge --whitelist-mode` -> `tootctl domains purge --limited-federation-mode` Removed badly maintained and no longer relevant .env.production.sample file --- config/initializers/2_whitelist_mode.rb | 2 +- config/initializers/blacklists.rb | 4 ++-- config/locales/en.yml | 34 ++++++++++++++++----------------- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'config') diff --git a/config/initializers/2_whitelist_mode.rb b/config/initializers/2_whitelist_mode.rb index a17ad07a2..1cc6a8e72 100644 --- a/config/initializers/2_whitelist_mode.rb +++ b/config/initializers/2_whitelist_mode.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Rails.application.configure do - config.x.whitelist_mode = ENV['WHITELIST_MODE'] == 'true' + config.x.whitelist_mode = (ENV['LIMITED_FEDERATION_MODE'] || ENV['WHITELIST_MODE']) == 'true' end diff --git a/config/initializers/blacklists.rb b/config/initializers/blacklists.rb index 020d84f56..0e3339c98 100644 --- a/config/initializers/blacklists.rb +++ b/config/initializers/blacklists.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Rails.application.configure do - config.x.email_domains_blacklist = ENV.fetch('EMAIL_DOMAIN_BLACKLIST') { 'mvrht.com' } - config.x.email_domains_whitelist = ENV.fetch('EMAIL_DOMAIN_WHITELIST') { '' } + config.x.email_domains_blacklist = (ENV['EMAIL_DOMAIN_DENYLIST'] || ENV['EMAIL_DOMAIN_BLACKLIST']) || '' + config.x.email_domains_whitelist = (ENV['EMAIL_DOMAIN_ALLOWLIST'] || ENV['EMAIL_DOMAIN_WHITELIST']) || '' end diff --git a/config/locales/en.yml b/config/locales/en.yml index 52692129e..7fc58643f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -95,7 +95,7 @@ en: delete: Delete destroyed_msg: Moderation note successfully destroyed! accounts: - add_email_domain_block: Blacklist e-mail domain + add_email_domain_block: Block e-mail domain approve: Approve approve_all: Approve all are_you_sure: Are you sure? @@ -196,7 +196,7 @@ en: username: Username warn: Warn web: Web - whitelisted: Whitelisted + whitelisted: Allowed for federation action_logs: action_types: assigned_to_self_report: Assign Report @@ -241,15 +241,15 @@ en: create_account_warning: "%{name} sent a warning to %{target}" create_announcement: "%{name} created new announcement %{target}" create_custom_emoji: "%{name} uploaded new emoji %{target}" - create_domain_allow: "%{name} whitelisted domain %{target}" + create_domain_allow: "%{name} allowed federation with domain %{target}" create_domain_block: "%{name} blocked domain %{target}" - create_email_domain_block: "%{name} blacklisted e-mail domain %{target}" + create_email_domain_block: "%{name} blocked e-mail domain %{target}" demote_user: "%{name} demoted user %{target}" destroy_announcement: "%{name} deleted announcement %{target}" destroy_custom_emoji: "%{name} destroyed emoji %{target}" - destroy_domain_allow: "%{name} removed domain %{target} from whitelist" + destroy_domain_allow: "%{name} disallowed federation with domain %{target}" destroy_domain_block: "%{name} unblocked domain %{target}" - destroy_email_domain_block: "%{name} whitelisted e-mail domain %{target}" + destroy_email_domain_block: "%{name} unblocked e-mail domain %{target}" destroy_status: "%{name} removed status by %{target}" disable_2fa_user: "%{name} disabled two factor requirement for user %{target}" disable_custom_emoji: "%{name} disabled emoji %{target}" @@ -350,12 +350,12 @@ en: week_interactions: interactions this week week_users_active: active this week week_users_new: users this week - whitelist_mode: Whitelist mode + whitelist_mode: Limited federation mode domain_allows: - add_new: Whitelist domain - created_msg: Domain has been successfully whitelisted - destroyed_msg: Domain has been removed from the whitelist - undo: Remove from whitelist + add_new: Allow federation with domain + created_msg: Domain has been successfully allowed for federation + destroyed_msg: Domain has been disallowed from federation + undo: Disallow federation with domain domain_blocks: add_new: Add new domain block created_msg: Domain block is now being processed @@ -398,16 +398,16 @@ en: view: View domain block email_domain_blocks: add_new: Add new - created_msg: Successfully added e-mail domain to blacklist + created_msg: Successfully blocked e-mail domain delete: Delete - destroyed_msg: Successfully deleted e-mail domain from blacklist + destroyed_msg: Successfully unblocked e-mail domain domain: Domain - empty: No e-mail domains currently blacklisted. + empty: No e-mail domains currently blocked. from_html: from %{domain} new: create: Add domain - title: New e-mail blacklist entry - title: E-mail blacklist + title: Block new e-mail domain + title: Blocked e-mail domains instances: by_domain: Domain delivery_available: Delivery is available @@ -451,7 +451,7 @@ en: pending: Waiting for relay's approval save_and_enable: Save and enable setup: Setup a relay connection - signatures_not_enabled: Relays will not work correctly while secure mode or whitelist mode is enabled + signatures_not_enabled: Relays will not work correctly while secure mode or limited federation mode is enabled status: Status title: Relays report_notes: -- cgit From 65506bac3f3fe233b5b7b3241020bd74eb5c9259 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 30 Jun 2020 19:19:50 +0200 Subject: Add user notes on accounts (#14148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add UserNote model * Add UI for user notes * Put comment in relationships entity * Add API to create user notes * Copy user notes to new account when receiving a Move activity * Address some of the review remarks * Replace modal by inline edition * Please CodeClimate * Button design changes * Change design again * Cancel note edition when pressing Escape * Fixes * Tweak design again * Move “Add note” item, and allow users to add notes to themselves * Rename UserNote into AccountNote, rename “comment” Relationship attribute to “note” --- .../api/v1/accounts/notes_controller.rb | 30 ++++++ app/javascript/mastodon/actions/account_notes.js | 69 ++++++++++++++ .../features/account/components/account_note.js | 103 +++++++++++++++++++++ .../mastodon/features/account/components/header.js | 11 +++ .../account/containers/account_note_container.js | 34 +++++++ .../features/account_timeline/components/header.js | 6 ++ .../containers/header_container.js | 5 + app/javascript/mastodon/reducers/account_notes.js | 44 +++++++++ app/javascript/mastodon/reducers/index.js | 2 + app/javascript/mastodon/reducers/relationships.js | 4 + app/javascript/styles/mastodon/components.scss | 62 ++++++++++++- app/models/account_note.rb | 20 ++++ app/models/concerns/account_interactions.rb | 8 ++ app/presenters/account_relationships_presenter.rb | 6 +- app/serializers/rest/relationship_serializer.rb | 6 +- app/workers/move_worker.rb | 17 ++++ config/locales/en.yml | 2 + config/routes.rb | 1 + db/migrate/20200628133322_create_account_notes.rb | 13 +++ db/schema.rb | 14 ++- spec/fabricators/account_note_fabricator.rb | 5 + spec/workers/move_worker_spec.rb | 27 ++++++ 22 files changed, 485 insertions(+), 4 deletions(-) create mode 100644 app/controllers/api/v1/accounts/notes_controller.rb create mode 100644 app/javascript/mastodon/actions/account_notes.js create mode 100644 app/javascript/mastodon/features/account/components/account_note.js create mode 100644 app/javascript/mastodon/features/account/containers/account_note_container.js create mode 100644 app/javascript/mastodon/reducers/account_notes.js create mode 100644 app/models/account_note.rb create mode 100644 db/migrate/20200628133322_create_account_notes.rb create mode 100644 spec/fabricators/account_note_fabricator.rb (limited to 'config') diff --git a/app/controllers/api/v1/accounts/notes_controller.rb b/app/controllers/api/v1/accounts/notes_controller.rb new file mode 100644 index 000000000..032e807d1 --- /dev/null +++ b/app/controllers/api/v1/accounts/notes_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Api::V1::Accounts::NotesController < Api::BaseController + include Authorization + + before_action -> { doorkeeper_authorize! :write, :'write:accounts' } + before_action :require_user! + before_action :set_account + + def create + if params[:comment].blank? + AccountNote.find_by(account: current_account, target_account: @account)&.destroy + else + @note = AccountNote.find_or_initialize_by(account: current_account, target_account: @account) + @note.comment = params[:comment] + @note.save! if @note.changed? + end + render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships_presenter + end + + private + + def set_account + @account = Account.find(params[:account_id]) + end + + def relationships_presenter + AccountRelationshipsPresenter.new([@account.id], current_user.account_id) + end +end diff --git a/app/javascript/mastodon/actions/account_notes.js b/app/javascript/mastodon/actions/account_notes.js new file mode 100644 index 000000000..059ed9e80 --- /dev/null +++ b/app/javascript/mastodon/actions/account_notes.js @@ -0,0 +1,69 @@ +import api from '../api'; + +export const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST'; +export const ACCOUNT_NOTE_SUBMIT_SUCCESS = 'ACCOUNT_NOTE_SUBMIT_SUCCESS'; +export const ACCOUNT_NOTE_SUBMIT_FAIL = 'ACCOUNT_NOTE_SUBMIT_FAIL'; + +export const ACCOUNT_NOTE_INIT_EDIT = 'ACCOUNT_NOTE_INIT_EDIT'; +export const ACCOUNT_NOTE_CANCEL = 'ACCOUNT_NOTE_CANCEL'; + +export const ACCOUNT_NOTE_CHANGE_COMMENT = 'ACCOUNT_NOTE_CHANGE_COMMENT'; + +export function submitAccountNote() { + return (dispatch, getState) => { + dispatch(submitAccountNoteRequest()); + + const id = getState().getIn(['account_notes', 'edit', 'account_id']); + + api(getState).post(`/api/v1/accounts/${id}/note`, { + comment: getState().getIn(['account_notes', 'edit', 'comment']), + }).then(response => { + dispatch(submitAccountNoteSuccess(response.data)); + }).catch(error => dispatch(submitAccountNoteFail(error))); + }; +}; + +export function submitAccountNoteRequest() { + return { + type: ACCOUNT_NOTE_SUBMIT_REQUEST, + }; +}; + +export function submitAccountNoteSuccess(relationship) { + return { + type: ACCOUNT_NOTE_SUBMIT_SUCCESS, + relationship, + }; +}; + +export function submitAccountNoteFail(error) { + return { + type: ACCOUNT_NOTE_SUBMIT_FAIL, + error, + }; +}; + +export function initEditAccountNote(account) { + return (dispatch, getState) => { + const comment = getState().getIn(['relationships', account.get('id'), 'note']); + + dispatch({ + type: ACCOUNT_NOTE_INIT_EDIT, + account, + comment, + }); + }; +}; + +export function cancelAccountNote() { + return { + type: ACCOUNT_NOTE_CANCEL, + }; +}; + +export function changeAccountNoteComment(comment) { + return { + type: ACCOUNT_NOTE_CHANGE_COMMENT, + comment, + }; +}; diff --git a/app/javascript/mastodon/features/account/components/account_note.js b/app/javascript/mastodon/features/account/components/account_note.js new file mode 100644 index 000000000..832a96a6a --- /dev/null +++ b/app/javascript/mastodon/features/account/components/account_note.js @@ -0,0 +1,103 @@ +import React from 'react'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import PropTypes from 'prop-types'; +import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import Icon from 'mastodon/components/icon'; +import Textarea from 'react-textarea-autosize'; + +const messages = defineMessages({ + placeholder: { id: 'account_note.placeholder', defaultMessage: 'No comment provided' }, +}); + +export default @injectIntl +class Header extends ImmutablePureComponent { + + static propTypes = { + account: ImmutablePropTypes.map.isRequired, + isEditing: PropTypes.bool, + isSubmitting: PropTypes.bool, + accountNote: PropTypes.string, + onEditAccountNote: PropTypes.func.isRequired, + onCancelAccountNote: PropTypes.func.isRequired, + onSaveAccountNote: PropTypes.func.isRequired, + onChangeAccountNote: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + handleChangeAccountNote = (e) => { + this.props.onChangeAccountNote(e.target.value); + }; + + componentWillUnmount () { + if (this.props.isEditing) { + this.props.onCancelAccountNote(); + } + } + + handleKeyDown = e => { + if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) { + this.props.onSaveAccountNote(); + } else if (e.keyCode === 27) { + this.props.onCancelAccountNote(); + } + } + + render () { + const { account, accountNote, isEditing, isSubmitting, intl } = this.props; + + if (!account || (!accountNote && !isEditing)) { + return null; + } + + let action_buttons = null; + if (isEditing) { + action_buttons = ( +
+ +
+ +
+ ); + } + + let note_container = null; + if (isEditing) { + note_container = ( +