Merge remote-tracking branch 'origin/merge-upstream'

signup-info-prompt
David Yip 2018-02-10 22:08:45 -06:00
commit b6159bcb0a
No known key found for this signature in database
GPG Key ID: 7DA0036508FCC0CC
25 changed files with 146 additions and 52 deletions

View File

@ -11,7 +11,7 @@ class ActivityPub::InboxesController < Api::BaseController
process_payload process_payload
head 202 head 202
else else
[signature_verification_failure_reason, 401] render plain: signature_verification_failure_reason, status: 401
end end
end end

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class Api::SalmonController < Api::BaseController class Api::SalmonController < Api::BaseController
include SignatureVerification
before_action :set_account before_action :set_account
respond_to :txt respond_to :txt
@ -9,7 +11,7 @@ class Api::SalmonController < Api::BaseController
process_salmon process_salmon
head 202 head 202
elsif payload.present? elsif payload.present?
[signature_verification_failure_reason, 401] render plain: signature_verification_failure_reason, status: 401
else else
head 400 head 400
end end

View File

@ -36,6 +36,7 @@ class Settings::PreferencesController < Settings::BaseController
:setting_favourite_modal, :setting_favourite_modal,
:setting_delete_modal, :setting_delete_modal,
:setting_auto_play_gif, :setting_auto_play_gif,
:setting_display_sensitive_media,
:setting_reduce_motion, :setting_reduce_motion,
:setting_system_font_ui, :setting_system_font_ui,
:setting_noindex, :setting_noindex,

View File

@ -6,7 +6,7 @@ import IconButton from './icon_button';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { isIOS } from '../is_mobile'; import { isIOS } from '../is_mobile';
import classNames from 'classnames'; import classNames from 'classnames';
import { autoPlayGif } from '../initial_state'; import { autoPlayGif, displaySensitiveMedia } from '../initial_state';
const messages = defineMessages({ const messages = defineMessages({
toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' }, toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' },
@ -187,7 +187,7 @@ export default class MediaGallery extends React.PureComponent {
}; };
state = { state = {
visible: !this.props.sensitive, visible: !this.props.sensitive || displaySensitiveMedia,
}; };
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {

View File

@ -122,7 +122,7 @@ export default class ActionBar extends React.PureComponent {
<div className='account__action-bar-links'> <div className='account__action-bar-links'>
<Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}> <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
<span><FormattedMessage id='account.posts' defaultMessage='Posts' /></span> <span><FormattedMessage id='account.posts' defaultMessage='Toots' /></span>
<strong><FormattedNumber value={account.get('statuses_count')} /></strong> <strong><FormattedNumber value={account.get('statuses_count')} /></strong>
</Link> </Link>

View File

@ -4,6 +4,7 @@ import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen'; import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
import { displaySensitiveMedia } from '../../initial_state';
const messages = defineMessages({ const messages = defineMessages({
play: { id: 'video.play', defaultMessage: 'Play' }, play: { id: 'video.play', defaultMessage: 'Play' },
@ -107,7 +108,7 @@ export default class Video extends React.PureComponent {
fullscreen: false, fullscreen: false,
hovered: false, hovered: false,
muted: false, muted: false,
revealed: !this.props.sensitive, revealed: !this.props.sensitive || displaySensitiveMedia,
}; };
setPlayerRef = c => { setPlayerRef = c => {

View File

@ -5,6 +5,7 @@ const getMeta = (prop) => initialState && initialState.meta && initialState.meta
export const reduceMotion = getMeta('reduce_motion'); export const reduceMotion = getMeta('reduce_motion');
export const autoPlayGif = getMeta('auto_play_gif'); export const autoPlayGif = getMeta('auto_play_gif');
export const displaySensitiveMedia = getMeta('display_sensitive_media');
export const unfollowModal = getMeta('unfollow_modal'); export const unfollowModal = getMeta('unfollow_modal');
export const boostModal = getMeta('boost_modal'); export const boostModal = getMeta('boost_modal');
export const deleteModal = getMeta('delete_modal'); export const deleteModal = getMeta('delete_modal');

View File

@ -433,7 +433,7 @@
"id": "account.view_full_profile" "id": "account.view_full_profile"
}, },
{ {
"defaultMessage": "Posts", "defaultMessage": "Toots",
"id": "account.posts" "id": "account.posts"
}, },
{ {

View File

@ -13,7 +13,7 @@
"account.moved_to": "{name} has moved to:", "account.moved_to": "{name} has moved to:",
"account.mute": "Mute @{name}", "account.mute": "Mute @{name}",
"account.mute_notifications": "Mute notifications from @{name}", "account.mute_notifications": "Mute notifications from @{name}",
"account.posts": "Posts", "account.posts": "Toots",
"account.report": "Report @{name}", "account.report": "Report @{name}",
"account.requested": "Awaiting approval. Click to cancel follow request", "account.requested": "Awaiting approval. Click to cancel follow request",
"account.share": "Share @{name}'s profile", "account.share": "Share @{name}'s profile",

View File

@ -24,6 +24,7 @@ class UserSettingsDecorator
user.settings['favourite_modal'] = favourite_modal_preference if change?('setting_favourite_modal') user.settings['favourite_modal'] = favourite_modal_preference if change?('setting_favourite_modal')
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif') user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif')
user.settings['display_sensitive_media'] = display_sensitive_media_preference if change?('setting_display_sensitive_media')
user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion') user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion')
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui') user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
user.settings['noindex'] = noindex_preference if change?('setting_noindex') user.settings['noindex'] = noindex_preference if change?('setting_noindex')
@ -71,6 +72,10 @@ class UserSettingsDecorator
boolean_cast_setting 'setting_auto_play_gif' boolean_cast_setting 'setting_auto_play_gif'
end end
def display_sensitive_media_preference
boolean_cast_setting 'setting_display_sensitive_media'
end
def reduce_motion_preference def reduce_motion_preference
boolean_cast_setting 'setting_reduce_motion' boolean_cast_setting 'setting_reduce_motion'
end end

View File

@ -4,7 +4,7 @@
# Table name: invites # Table name: invites
# #
# id :integer not null, primary key # id :integer not null, primary key
# user_id :integer # user_id :integer not null
# code :string default(""), not null # code :string default(""), not null
# expires_at :datetime # expires_at :datetime
# max_uses :integer # max_uses :integer

View File

@ -69,7 +69,7 @@ class Notification < ApplicationRecord
class << self class << self
def reload_stale_associations!(cached_items) def reload_stale_associations!(cached_items)
account_ids = cached_items.map(&:from_account_id).uniq account_ids = (cached_items.map(&:from_account_id) + cached_items.map { |item| item.target_status&.account_id }.compact).uniq
return if account_ids.empty? return if account_ids.empty?
@ -77,6 +77,7 @@ class Notification < ApplicationRecord
cached_items.each do |item| cached_items.each do |item|
item.from_account = accounts[item.from_account_id] item.from_account = accounts[item.from_account_id]
item.target_status.account = accounts[item.target_status.account_id] if item.target_status
end end
end end

View File

@ -84,7 +84,7 @@ class User < ApplicationRecord
has_many :session_activations, dependent: :destroy has_many :session_activations, dependent: :destroy
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal, delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_sensitive_media,
to: :settings, prefix: :setting, allow_nil: false to: :settings, prefix: :setting, allow_nil: false
attr_accessor :invite_code attr_accessor :invite_code

View File

@ -7,7 +7,7 @@
# data :json # data :json
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# user_id :integer # user_id :integer not null
# #
class Web::Setting < ApplicationRecord class Web::Setting < ApplicationRecord

View File

@ -31,6 +31,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:favourite_modal] = object.current_account.user.setting_favourite_modal store[:favourite_modal] = object.current_account.user.setting_favourite_modal
store[:delete_modal] = object.current_account.user.setting_delete_modal store[:delete_modal] = object.current_account.user.setting_delete_modal
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:display_sensitive_media] = object.current_account.user.setting_display_sensitive_media
store[:reduce_motion] = object.current_account.user.setting_reduce_motion store[:reduce_motion] = object.current_account.user.setting_reduce_motion
end end

View File

@ -36,6 +36,7 @@
.fields-group .fields-group
= f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label = f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label
= f.input :setting_display_sensitive_media, as: :boolean, wrapper: :with_label
= f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label = f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label
= f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label = f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label

View File

@ -22,9 +22,9 @@
- if !status.media_attachments.empty? - if !status.media_attachments.empty?
- if status.media_attachments.first.video? - if status.media_attachments.first.video?
- video = status.media_attachments.first - video = status.media_attachments.first
%div{ data: { component: 'Video', props: Oj.dump(src: video.file.url(:original), preview: video.file.url(:small), sensitive: status.sensitive?, width: 670, height: 380, detailed: true) }}< %div{ data: { component: 'Video', props: Oj.dump(src: video.file.url(:original), preview: video.file.url(:small), sensitive: status.sensitive? && !current_account&.user&.setting_display_sensitive_media, width: 670, height: 380, detailed: true) }}
- else - else
%div{ data: { component: 'MediaGallery', props: Oj.dump(height: 380, sensitive: status.sensitive?, standalone: true, 'autoPlayGif': current_account&.user&.setting_auto_play_gif, 'reduceMotion': current_account&.user&.setting_reduce_motion, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }) }}< %div{ data: { component: 'MediaGallery', props: Oj.dump(height: 380, sensitive: status.sensitive? && !current_account&.user&.setting_display_sensitive_media, standalone: true, 'autoPlayGif': current_account&.user&.setting_auto_play_gif, 'reduceMotion': current_account&.user&.setting_reduce_motion, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }) }}
- elsif status.preview_cards.first - elsif status.preview_cards.first
%div{ data: { component: 'Card', props: Oj.dump('maxDescription': 160, card: ActiveModelSerializers::SerializableResource.new(status.preview_cards.first, serializer: REST::PreviewCardSerializer).as_json) }} %div{ data: { component: 'Card', props: Oj.dump('maxDescription': 160, card: ActiveModelSerializers::SerializableResource.new(status.preview_cards.first, serializer: REST::PreviewCardSerializer).as_json) }}

View File

@ -24,6 +24,6 @@
- unless status.media_attachments.empty? - unless status.media_attachments.empty?
- if status.media_attachments.first.video? - if status.media_attachments.first.video?
- video = status.media_attachments.first - video = status.media_attachments.first
%div{ data: { component: 'Video', props: Oj.dump(src: video.file.url(:original), preview: video.file.url(:small), sensitive: status.sensitive?, width: 610, height: 343) }}>< %div{ data: { component: 'Video', props: Oj.dump(src: video.file.url(:original), preview: video.file.url(:small), sensitive: status.sensitive? && !current_account&.user&.setting_display_sensitive_media, width: 610, height: 343) }}
- else - else
%div{ data: { component: 'MediaGallery', props: Oj.dump(height: 343, sensitive: status.sensitive?, 'autoPlayGif': current_account&.user&.setting_auto_play_gif, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }) }}>< %div{ data: { component: 'MediaGallery', props: Oj.dump(height: 343, sensitive: status.sensitive? && !current_account&.user&.setting_display_sensitive_media, 'autoPlayGif': current_account&.user&.setting_auto_play_gif, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }) }}

View File

@ -45,6 +45,7 @@ en:
setting_default_privacy: Post privacy setting_default_privacy: Post privacy
setting_default_sensitive: Always mark media as sensitive setting_default_sensitive: Always mark media as sensitive
setting_delete_modal: Show confirmation dialog before deleting a toot setting_delete_modal: Show confirmation dialog before deleting a toot
setting_display_sensitive_media: Always show media marked as sensitive
setting_favourite_modal: Show confirmation dialog before favouriting setting_favourite_modal: Show confirmation dialog before favouriting
setting_noindex: Opt-out of search engine indexing setting_noindex: Opt-out of search engine indexing
setting_reduce_motion: Reduce motion in animations setting_reduce_motion: Reduce motion in animations

View File

@ -25,6 +25,7 @@ defaults: &defaults
favourite_modal: false favourite_modal: false
delete_modal: true delete_modal: true
auto_play_gif: false auto_play_gif: false
display_sensitive_media: false
reduce_motion: false reduce_motion: false
system_font_ui: false system_font_ui: false
noindex: false noindex: false

View File

@ -0,0 +1,6 @@
class ChangeUserIdNonnullable < ActiveRecord::Migration[5.1]
def change
change_column_null :invites, :user_id, false
change_column_null :web_settings, :user_id, false
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180204034416) do ActiveRecord::Schema.define(version: 20180206000000) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -204,7 +204,7 @@ ActiveRecord::Schema.define(version: 20180204034416) do
end end
create_table "invites", force: :cascade do |t| create_table "invites", force: :cascade do |t|
t.bigint "user_id" t.bigint "user_id", null: false
t.string "code", default: "", null: false t.string "code", default: "", null: false
t.datetime "expires_at" t.datetime "expires_at"
t.integer "max_uses" t.integer "max_uses"
@ -526,7 +526,7 @@ ActiveRecord::Schema.define(version: 20180204034416) do
t.json "data" t.json "data"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.bigint "user_id" t.bigint "user_id", null: false
t.index ["user_id"], name: "index_web_settings_on_user_id", unique: true t.index ["user_id"], name: "index_web_settings_on_user_id", unique: true
end end

View File

@ -40,7 +40,7 @@ RSpec.describe Api::SalmonController, type: :controller do
end end
end end
context 'with invalid post data' do context 'with empty post data' do
before do before do
request.env['RAW_POST_DATA'] = '' request.env['RAW_POST_DATA'] = ''
post :update, params: { id: account.id } post :update, params: { id: account.id }
@ -50,5 +50,19 @@ RSpec.describe Api::SalmonController, type: :controller do
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
end end
context 'with invalid post data' do
before do
service = double(call: false)
allow(VerifySalmonService).to receive(:new).and_return(service)
request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
post :update, params: { id: account.id }
end
it 'returns http client error' do
expect(response).to have_http_status(401)
end
end
end end
end end

View File

@ -1,4 +1,63 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe FetchAtomService do RSpec.describe FetchAtomService do
describe '#link_header' do
context 'Link is Array' do
target = FetchAtomService.new
target.instance_variable_set('@response', 'Link' => [
'<http://example.com/>; rel="up"; meta="bar"',
'<http://example.com/foo>; rel="self"',
])
it 'set first link as link_header' do
expect(target.send(:link_header).links[0].href).to eq 'http://example.com/'
end
end
context 'Link is not Array' do
target = FetchAtomService.new
target.instance_variable_set('@response', 'Link' => '<http://example.com/foo>; rel="self", <http://example.com/>; rel = "up"')
it { expect(target.send(:link_header).links[0].href).to eq 'http://example.com/foo' }
end
end
describe '#perform_request' do
let(:url) { 'http://example.com' }
context 'Check method result' do
before do
WebMock.stub_request(:get, url).to_return(status: 200, body: '', headers: {})
@target = FetchAtomService.new
@target.instance_variable_set('@url', url)
end
it 'HTTP::Response instance is returned and set to @response' do
expect(@target.send(:perform_request).status.to_s).to eq '200 OK'
expect(@target.instance_variable_get('@response')).to be_instance_of HTTP::Response
end
end
context 'check passed parameters to Request' do
before do
@target = FetchAtomService.new
@target.instance_variable_set('@url', url)
@target.instance_variable_set('@unsupported_activity', unsupported_activity)
allow(Request).to receive(:new).with(:get, url)
expect(Request).to receive_message_chain(:new, :add_headers).with('Accept' => accept)
allow(Request).to receive_message_chain(:new, :add_headers, :perform).with(no_args)
end
context '@unsupported_activity is true' do
let(:unsupported_activity) { true }
let(:accept) { 'text/html' }
it { @target.send(:perform_request) }
end
context '@unsupported_activity is false' do
let(:unsupported_activity) { false }
let(:accept) { 'application/activity+json, application/ld+json, application/atom+xml, text/html' }
it { @target.send(:perform_request) }
end
end
end
end end