From 6151308c47efb0e05bcb2c54aa1693f5ff04da5c Mon Sep 17 00:00:00 2001 From: Shuhei Kitagawa Date: Tue, 12 Jun 2018 21:24:46 +0900 Subject: [PATCH 01/39] Add missing tests for admin/accounts_controller (#7791) --- .../admin/accounts_controller_spec.rb | 224 +++++++++++++++++- 1 file changed, 219 insertions(+), 5 deletions(-) diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index ff9dbbfb8..197e019fe 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -3,13 +3,11 @@ require 'rails_helper' RSpec.describe Admin::AccountsController, type: :controller do render_views - let(:user) { Fabricate(:user, admin: true) } - - before do - sign_in user, scope: :user - end + before { sign_in current_user, scope: :user } describe 'GET #index' do + let(:current_user) { Fabricate(:user, admin: true) } + around do |example| default_per_page = Account.default_per_page Account.paginates_per 1 @@ -68,6 +66,7 @@ RSpec.describe Admin::AccountsController, type: :controller do end describe 'GET #show' do + let(:current_user) { Fabricate(:user, admin: true) } let(:account) { Fabricate(:account, username: 'bob') } it 'returns http success' do @@ -75,4 +74,219 @@ RSpec.describe Admin::AccountsController, type: :controller do expect(response).to have_http_status(200) end end + + + describe 'POST #subscribe' do + subject { post :subscribe, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: admin) } + let(:account) { Fabricate(:account) } + + context 'when user is admin' do + let(:admin) { true } + + it { is_expected.to redirect_to admin_account_path(account.id) } + end + + context 'when user is not admin' do + let(:admin) { false } + + it { is_expected.to have_http_status :forbidden } + end + end + + describe 'POST #unsubscribe' do + subject { post :unsubscribe, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: admin) } + let(:account) { Fabricate(:account) } + + context 'when user is admin' do + let(:admin) { true } + + it { is_expected.to redirect_to admin_account_path(account.id) } + end + + context 'when user is not admin' do + let(:admin) { false } + + it { is_expected.to have_http_status :forbidden } + end + end + + describe 'POST #memorialize' do + subject { post :memorialize, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: current_user_admin) } + let(:account) { Fabricate(:account, user: user) } + let(:user) { Fabricate(:user, admin: target_user_admin) } + + context 'when user is admin' do + let(:current_user_admin) { true } + + context 'when target user is admin' do + let(:target_user_admin) { true } + + it 'fails to memorialize account' do + is_expected.to have_http_status :forbidden + expect(account.reload).not_to be_memorial + end + end + + context 'when target user is not admin' do + let(:target_user_admin) { false } + + it 'succeeds in memorializing account' do + is_expected.to redirect_to admin_account_path(account.id) + expect(account.reload).to be_memorial + end + end + end + + context 'when user is not admin' do + let(:current_user_admin) { false } + + context 'when target user is admin' do + let(:target_user_admin) { true } + + it 'fails to memorialize account' do + is_expected.to have_http_status :forbidden + expect(account.reload).not_to be_memorial + end + end + + context 'when target user is not admin' do + let(:target_user_admin) { false } + + it 'fails to memorialize account' do + is_expected.to have_http_status :forbidden + expect(account.reload).not_to be_memorial + end + end + end + end + + describe 'POST #enable' do + subject { post :enable, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: admin) } + let(:account) { Fabricate(:account, user: user) } + let(:user) { Fabricate(:user, disabled: true) } + + context 'when user is admin' do + let(:admin) { true } + + it 'succeeds in enabling account' do + is_expected.to redirect_to admin_account_path(account.id) + expect(user.reload).not_to be_disabled + end + end + + context 'when user is not admin' do + let(:admin) { false } + + it 'fails to enable account' do + is_expected.to have_http_status :forbidden + expect(user.reload).to be_disabled + end + end + end + + describe 'POST #disable' do + subject { post :disable, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: current_user_admin) } + let(:account) { Fabricate(:account, user: user) } + let(:user) { Fabricate(:user, disabled: false, admin: target_user_admin) } + + context 'when user is admin' do + let(:current_user_admin) { true } + + context 'when target user is admin' do + let(:target_user_admin) { true } + + it 'fails to disable account' do + is_expected.to have_http_status :forbidden + expect(user.reload).not_to be_disabled + end + end + + context 'when target user is not admin' do + let(:target_user_admin) { false } + + it 'succeeds in disabling account' do + is_expected.to redirect_to admin_account_path(account.id) + expect(user.reload).to be_disabled + end + end + end + + context 'when user is not admin' do + let(:current_user_admin) { false } + + context 'when target user is admin' do + let(:target_user_admin) { true } + + it 'fails to disable account' do + is_expected.to have_http_status :forbidden + expect(user.reload).not_to be_disabled + end + end + + context 'when target user is not admin' do + let(:target_user_admin) { false } + + it 'fails to disable account' do + is_expected.to have_http_status :forbidden + expect(user.reload).not_to be_disabled + end + end + end + end + + describe 'POST #redownload' do + subject { post :redownload, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: admin) } + let(:account) { Fabricate(:account) } + + context 'when user is admin' do + let(:admin) { true } + + it 'succeeds in redownloadin' do + is_expected.to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:admin) { false } + + it 'fails to redownload' do + is_expected.to have_http_status :forbidden + end + end + end + + describe 'POST #remove_avatar' do + subject { post :remove_avatar, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, admin: admin) } + let(:account) { Fabricate(:account) } + + context 'when user is admin' do + let(:admin) { true } + + it 'succeeds in removing avatar' do + is_expected.to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:admin) { false } + + it 'fails to remove avatar' do + is_expected.to have_http_status :forbidden + end + end + end end From 5b47774ab87082873238a0fd9b3a21c2f6016688 Mon Sep 17 00:00:00 2001 From: Shuhei Kitagawa Date: Wed, 13 Jun 2018 10:28:39 +0900 Subject: [PATCH 02/39] Add tests for followers_accounts_controller (#7794) --- .../follower_accounts_controller_spec.rb | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/spec/controllers/follower_accounts_controller_spec.rb b/spec/controllers/follower_accounts_controller_spec.rb index 3a42a6e18..83032ab64 100644 --- a/spec/controllers/follower_accounts_controller_spec.rb +++ b/spec/controllers/follower_accounts_controller_spec.rb @@ -8,18 +8,45 @@ describe FollowerAccountsController do let(:follower1) { Fabricate(:account) } describe 'GET #index' do - it 'assigns follows' do - follow0 = follower0.follow!(alice) - follow1 = follower1.follow!(alice) + let!(:follow0) { follower0.follow!(alice) } + let!(:follow1) { follower1.follow!(alice) } - get :index, params: { account_username: alice.username } + context 'when format is html' do + subject(:response) { get :index, params: { account_username: alice.username, format: :html } } - assigned = assigns(:follows).to_a - expect(assigned.size).to eq 2 - expect(assigned[0]).to eq follow1 - expect(assigned[1]).to eq follow0 + it 'assigns follows' do + expect(response).to have_http_status(200) - expect(response).to have_http_status(200) + assigned = assigns(:follows).to_a + expect(assigned.size).to eq 2 + expect(assigned[0]).to eq follow1 + expect(assigned[1]).to eq follow0 + end + end + + context 'when format is json' do + subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } } + subject(:body) { JSON.parse(response.body) } + + context 'with page' do + let(:page) { 1 } + + it 'returns followers' do + expect(response).to have_http_status(200) + expect(body['totalItems']).to eq 2 + expect(body['partOf']).to be_present + end + end + + context 'without page' do + let(:page) { nil } + + it 'returns followers' do + expect(response).to have_http_status(200) + expect(body['totalItems']).to eq 2 + expect(body['partOf']).to be_blank + end + end end end end From 0338da1699fae66e2e49404464003da70adc7580 Mon Sep 17 00:00:00 2001 From: "chr v1.x" Date: Wed, 13 Jun 2018 05:44:50 -0700 Subject: [PATCH 03/39] Add profile options on compose form (#7789) * Add profile options on compose form * Remove unused imports to appease codeclimate * Play nicely with cancel button and use ellipsis-v instead of hamburger * Fix whitespace and quotes to appease codeclimate --- .../features/compose/components/action_bar.js | 53 +++++++++++++++++++ .../compose/components/navigation_bar.js | 8 ++- .../styles/mastodon/components.scss | 48 +++++++++++++---- 3 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 app/javascript/mastodon/features/compose/components/action_bar.js diff --git a/app/javascript/mastodon/features/compose/components/action_bar.js b/app/javascript/mastodon/features/compose/components/action_bar.js new file mode 100644 index 000000000..d6dcf51e0 --- /dev/null +++ b/app/javascript/mastodon/features/compose/components/action_bar.js @@ -0,0 +1,53 @@ +import React from 'react'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import PropTypes from 'prop-types'; +import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; +import { defineMessages, injectIntl } from 'react-intl'; + +const messages = defineMessages({ + edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' }, + pins: { id: 'navigation_bar.pins', defaultMessage: 'Pinned toots' }, + preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, + follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' }, + favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' }, + lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, + blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, + domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, + mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, +}); + +@injectIntl +export default class ActionBar extends React.PureComponent { + + static propTypes = { + account: ImmutablePropTypes.map.isRequired, + intl: PropTypes.object.isRequired, + }; + + render () { + const { intl } = this.props; + + let menu = []; + + menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' }); + menu.push({ text: intl.formatMessage(messages.preferences), href: '/settings/preferences' }); + menu.push({ text: intl.formatMessage(messages.pins), to: '/pinned' }); + menu.push(null); + menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' }); + menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' }); + menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' }); + menu.push(null); + menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' }); + menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' }); + menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' }); + + return ( +
+
+ +
+
+ ); + } + +} diff --git a/app/javascript/mastodon/features/compose/components/navigation_bar.js b/app/javascript/mastodon/features/compose/components/navigation_bar.js index 3014c4033..9ac2a138d 100644 --- a/app/javascript/mastodon/features/compose/components/navigation_bar.js +++ b/app/javascript/mastodon/features/compose/components/navigation_bar.js @@ -1,9 +1,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; +import ActionBar from './action_bar'; import Avatar from '../../../components/avatar'; -import IconButton from '../../../components/icon_button'; import Permalink from '../../../components/permalink'; +import IconButton from '../../../components/icon_button'; import { FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; @@ -30,7 +31,10 @@ export default class NavigationBar extends ImmutablePureComponent { - + ); } diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index cb790ac05..42eebb05c 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -1510,9 +1510,21 @@ a.account__display-name { text-decoration: none; } - .icon-button { - pointer-events: none; - opacity: 0; + .navigation-bar__actions { + position: relative; + + .icon-button.close { + position: absolute; + pointer-events: none; + transform: scale(0.0, 1.0) translate(-100%, 0); + opacity: 0; + } + + .compose__action-bar .icon-button { + pointer-events: auto; + transform: scale(1.0, 1.0) translate(0, 0); + opacity: 1; + } } } @@ -4932,9 +4944,18 @@ noscript { transition: margin-top $duration $delay; } - & > .icon-button { - will-change: opacity; - transition: opacity $duration $delay; + .navigation-bar__actions { + & > .icon-button.close { + will-change: opacity transform; + transition: opacity $duration * 0.5 $delay, + transform $duration $delay; + } + + & > .compose__action-bar .icon-button { + will-change: opacity transform; + transition: opacity $duration * 0.5 $delay + $duration * 0.5, + transform $duration $delay; + } } } @@ -4961,9 +4982,18 @@ noscript { margin-top: -50px; } - .icon-button { - pointer-events: auto; - opacity: 1; + .navigation-bar__actions { + .icon-button.close { + pointer-events: auto; + opacity: 1; + transform: scale(1.0, 1.0) translate(0, 0); + } + + .compose__action-bar .icon-button { + pointer-events: none; + opacity: 0; + transform: scale(0.0, 1.0) translate(100%, 0); + } } } } From ad8814232f9fec8ab06d66d5d1f85e3ba5bce253 Mon Sep 17 00:00:00 2001 From: Shuhei Kitagawa Date: Thu, 14 Jun 2018 10:49:17 +0900 Subject: [PATCH 04/39] Add tests for following accounts controller (#7800) --- .../following_accounts_controller_spec.rb | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/spec/controllers/following_accounts_controller_spec.rb b/spec/controllers/following_accounts_controller_spec.rb index 33376365d..d5e4ee587 100644 --- a/spec/controllers/following_accounts_controller_spec.rb +++ b/spec/controllers/following_accounts_controller_spec.rb @@ -8,18 +8,45 @@ describe FollowingAccountsController do let(:followee1) { Fabricate(:account) } describe 'GET #index' do - it 'assigns followees' do - follow0 = alice.follow!(followee0) - follow1 = alice.follow!(followee1) + let!(:follow0) { alice.follow!(followee0) } + let!(:follow1) { alice.follow!(followee1) } - get :index, params: { account_username: alice.username } + context 'when format is html' do + subject(:response) { get :index, params: { account_username: alice.username, format: :html } } - assigned = assigns(:follows).to_a - expect(assigned.size).to eq 2 - expect(assigned[0]).to eq follow1 - expect(assigned[1]).to eq follow0 + it 'assigns follows' do + expect(response).to have_http_status(200) - expect(response).to have_http_status(200) + assigned = assigns(:follows).to_a + expect(assigned.size).to eq 2 + expect(assigned[0]).to eq follow1 + expect(assigned[1]).to eq follow0 + end + end + + context 'when format is json' do + subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } } + subject(:body) { JSON.parse(response.body) } + + context 'with page' do + let(:page) { 1 } + + it 'returns followers' do + expect(response).to have_http_status(200) + expect(body['totalItems']).to eq 2 + expect(body['partOf']).to be_present + end + end + + context 'without page' do + let(:page) { nil } + + it 'returns followers' do + expect(response).to have_http_status(200) + expect(body['totalItems']).to eq 2 + expect(body['partOf']).to be_blank + end + end end end end From 79a468016a4f267fc954ef521a65d97e3e1370cf Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Thu, 14 Jun 2018 15:03:07 +0900 Subject: [PATCH 05/39] Fix "Invalid DOM property `class`" (#7798) --- .../mastodon/features/compose/components/navigation_bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/compose/components/navigation_bar.js b/app/javascript/mastodon/features/compose/components/navigation_bar.js index 9ac2a138d..9910eb4f9 100644 --- a/app/javascript/mastodon/features/compose/components/navigation_bar.js +++ b/app/javascript/mastodon/features/compose/components/navigation_bar.js @@ -31,7 +31,7 @@ export default class NavigationBar extends ImmutablePureComponent { -