From: Thibaut Girka Date: Tue, 23 Jul 2019 08:17:06 +0000 (+0200) Subject: Merge branch 'master' into glitch-soc/merge-upstream X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=444796b69b0cd2c7b4b95d3b3119e0b7a503f682;p=mastodon.git Merge branch 'master' into glitch-soc/merge-upstream Conflicts: - app/controllers/application_controller.rb - app/controllers/auth/confirmations_controller.rb - app/controllers/auth/sessions_controller.rb - app/controllers/settings/deletes_controller.rb - app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb --- 444796b69b0cd2c7b4b95d3b3119e0b7a503f682 diff --cc app/controllers/application_controller.rb index 95e0d624f,41ce1a0ca..4a6b96982 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@@ -180,62 -111,15 +181,24 @@@ class ApplicationController < ActionCon @current_session = SessionActivation.find_by(session_id: cookies.signed['_session_id']) if cookies.signed['_session_id'].present? end - def current_theme - return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme - current_user.setting_theme + def current_flavour + return Setting.flavour unless Themes.instance.flavours.include? current_user&.setting_flavour + current_user.setting_flavour + end + + def current_skin + return Setting.skin unless Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin + current_user.setting_skin end - def cache_collection(raw, klass) - return raw unless klass.respond_to?(:with_includes) - - raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation) - cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id) - uncached_ids = raw.map(&:id) - cached_keys_with_value.keys - - klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!) - - unless uncached_ids.empty? - uncached = klass.where(id: uncached_ids).with_includes.each_with_object({}) { |item, h| h[item.id] = item } - - uncached.each_value do |item| - Rails.cache.write(item, item) - end - end - - raw.map { |item| cached_keys_with_value[item.id] || uncached[item.id] }.compact - end - def respond_with_error(code) respond_to do |format| format.any { head code } - format.html { render "errors/#{code}", layout: 'error', status: code } + + format.html do - set_locale + use_pack 'error' + render "errors/#{code}", layout: 'error', status: code + end end end - - def render_cached_json(cache_key, **options) - options[:expires_in] ||= 3.minutes - cache_public = options.key?(:public) ? options.delete(:public) : true - content_type = options.delete(:content_type) || 'application/json' - - data = Rails.cache.fetch(cache_key, { raw: true }.merge(options)) do - yield.to_json - end - - expires_in options[:expires_in], public: cache_public - render json: data, content_type: content_type - end - - def set_cache_headers - response.headers['Vary'] = public_fetch_mode? ? 'Accept' : 'Accept, Signature' - end end diff --cc app/controllers/auth/confirmations_controller.rb index eade82e36,0d7c6e7c2..1d6e4ec19 --- a/app/controllers/auth/confirmations_controller.rb +++ b/app/controllers/auth/confirmations_controller.rb @@@ -4,31 -4,11 +4,16 @@@ class Auth::ConfirmationsController < D layout 'auth' before_action :set_body_classes - before_action :set_user, only: [:finish_signup] + before_action :set_pack - def finish_signup - return unless request.patch? && params[:user] - - if @user.update(user_params) - @user.skip_reconfirmation! - bypass_sign_in(@user) - redirect_to root_path, notice: I18n.t('devise.confirmations.send_instructions') - else - @show_errors = true - end - end + skip_before_action :require_functional! private + def set_pack + use_pack 'auth' + end + - def set_user - @user = current_user - end - def set_body_classes @body_classes = 'lighter' end diff --cc app/controllers/auth/sessions_controller.rb index 332f4d7a7,7e6dbf19e..7ecbaf193 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@@ -6,9 -6,10 +6,11 @@@ class Auth::SessionsController < Devise layout 'auth' skip_before_action :require_no_authentication, only: [:create] - skip_before_action :check_user_permissions, only: [:destroy] + skip_before_action :require_functional! + prepend_before_action :authenticate_with_two_factor, if: :two_factor_enabled?, only: [:create] + prepend_before_action :set_pack + before_action :set_instance_presenter, only: [:new] before_action :set_body_classes diff --cc app/controllers/oauth/authorized_applications_controller.rb index 4e45445df,fb8389034..c5ccece13 --- a/app/controllers/oauth/authorized_applications_controller.rb +++ b/app/controllers/oauth/authorized_applications_controller.rb @@@ -5,9 -5,10 +5,11 @@@ class Oauth::AuthorizedApplicationsCont before_action :store_current_location before_action :authenticate_resource_owner! + before_action :set_pack before_action :set_body_classes + skip_before_action :require_functional! + include Localized def destroy diff --cc app/controllers/settings/deletes_controller.rb index 4c1121471,97fe4d328..20dcc2dbd --- a/app/controllers/settings/deletes_controller.rb +++ b/app/controllers/settings/deletes_controller.rb @@@ -1,8 -1,13 +1,11 @@@ # frozen_string_literal: true class Settings::DeletesController < Settings::BaseController - layout 'admin' - before_action :check_enabled_deletion - before_action :authenticate_user! + prepend_before_action :check_enabled_deletion + before_action :require_not_suspended! + + skip_before_action :require_functional! def show @confirmation = Form::DeleteConfirmation.new diff --cc app/controllers/settings/two_factor_authentication/confirmations_controller.rb index 363b32e17,3145e092d..1708d71d7 --- a/app/controllers/settings/two_factor_authentication/confirmations_controller.rb +++ b/app/controllers/settings/two_factor_authentication/confirmations_controller.rb @@@ -3,8 -3,13 +3,10 @@@ module Settings module TwoFactorAuthentication class ConfirmationsController < BaseController - layout 'admin' - - before_action :authenticate_user! before_action :ensure_otp_secret + skip_before_action :require_functional! + def new prepare_two_factor_form end diff --cc app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb index 0555d61db,09a759860..56763e10c --- a/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb +++ b/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb @@@ -3,6 -3,12 +3,8 @@@ module Settings module TwoFactorAuthentication class RecoveryCodesController < BaseController - layout 'admin' - - before_action :authenticate_user! - + skip_before_action :require_functional! + def create @recovery_codes = current_user.generate_otp_backup_codes! current_user.save! diff --cc app/controllers/settings/two_factor_authentications_controller.rb index 8c7737e9d,6904076e4..e632d39cf --- a/app/controllers/settings/two_factor_authentications_controller.rb +++ b/app/controllers/settings/two_factor_authentications_controller.rb @@@ -2,8 -2,13 +2,10 @@@ module Settings class TwoFactorAuthenticationsController < BaseController - layout 'admin' - - before_action :authenticate_user! before_action :verify_otp_required, only: [:create] + skip_before_action :require_functional! + def show @confirmation = Form::TwoFactorConfirmation.new end diff --cc app/javascript/packs/public.js index 69441d315,b58622a8d..6aea119e3 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@@ -91,7 -114,130 +97,10 @@@ function main() if (parallaxComponents.length > 0 ) { new Rellax('.parallax', { speed: -1 }); } + + delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original')); + delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static')); }); - - delegate(document, '.webapp-btn', 'click', ({ target, button }) => { - if (button !== 0) { - return true; - } - window.location.href = target.href; - return false; - }); - - delegate(document, '.status__content__spoiler-link', 'click', function() { - const contentEl = this.parentNode.parentNode.querySelector('.e-content'); - - if (contentEl.style.display === 'block') { - contentEl.style.display = 'none'; - this.parentNode.style.marginBottom = 0; - } else { - contentEl.style.display = 'block'; - this.parentNode.style.marginBottom = null; - } - - return false; - }); - - delegate(document, '.modal-button', 'click', e => { - e.preventDefault(); - - let href; - - if (e.target.nodeName !== 'A') { - href = e.target.parentNode.href; - } else { - href = e.target.href; - } - - window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes'); - }); - - delegate(document, '#account_display_name', 'input', ({ target }) => { - const name = document.querySelector('.card .display-name strong'); - if (name) { - if (target.value) { - name.innerHTML = emojify(escapeTextContentForBrowser(target.value)); - } else { - name.textContent = document.querySelector('#default_account_display_name').textContent; - } - } - }); - - delegate(document, '#account_avatar', 'change', ({ target }) => { - const avatar = document.querySelector('.card .avatar img'); - const [file] = target.files || []; - const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc; - - avatar.src = url; - }); - - const getProfileAvatarAnimationHandler = (swapTo) => { - //animate avatar gifs on the profile page when moused over - return ({ target }) => { - const swapSrc = target.getAttribute(swapTo); - //only change the img source if autoplay is off and the image src is actually different - if(target.getAttribute('data-autoplay') !== 'true' && target.src !== swapSrc) { - target.src = swapSrc; - } - }; - }; - - delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original')); - - delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static')); - - delegate(document, '#account_header', 'change', ({ target }) => { - const header = document.querySelector('.card .card__img img'); - const [file] = target.files || []; - const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc; - - header.src = url; - }); - - delegate(document, '#account_locked', 'change', ({ target }) => { - const lock = document.querySelector('.card .display-name i'); - - if (target.checked) { - lock.style.display = 'inline'; - } else { - lock.style.display = 'none'; - } - }); - - delegate(document, '.input-copy input', 'click', ({ target }) => { - target.focus(); - target.select(); - target.setSelectionRange(0, target.value.length); - }); - - delegate(document, '.input-copy button', 'click', ({ target }) => { - const input = target.parentNode.querySelector('.input-copy__wrapper input'); - - const oldReadOnly = input.readonly; - - input.readonly = false; - input.focus(); - input.select(); - input.setSelectionRange(0, input.value.length); - - try { - if (document.execCommand('copy')) { - input.blur(); - target.parentNode.classList.add('copied'); - - setTimeout(() => { - target.parentNode.classList.remove('copied'); - }, 700); - } - } catch (err) { - console.error(err); - } - - input.readonly = oldReadOnly; - }); } loadPolyfills().then(main).catch(error => { diff --cc package.json index a56cc75ea,58d594817..aa9d809f1 --- a/package.json +++ b/package.json @@@ -72,9 -71,8 +72,9 @@@ "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.5.4", - "@clusterws/cws": "^0.14.0", + "@clusterws/cws": "^0.15.0", "array-includes": "^3.0.3", + "atrament": "^0.2.3", "autoprefixer": "^9.6.0", "axios": "^0.19.0", "babel-loader": "^8.0.6",