From e8875c6046615778c7ae6f1fc0c4a195fb5d3a03 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 30 Mar 2017 19:42:33 +0200 Subject: Import feature for following/blocking lists (addresses #62, #177, #201, #454) --- app/controllers/api/v1/timelines_controller.rb | 12 ++++----- app/controllers/settings/imports_controller.rb | 34 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 app/controllers/settings/imports_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/api/v1/timelines_controller.rb b/app/controllers/api/v1/timelines_controller.rb index af6e5b7df..0446b9e4d 100644 --- a/app/controllers/api/v1/timelines_controller.rb +++ b/app/controllers/api/v1/timelines_controller.rb @@ -11,8 +11,8 @@ class Api::V1::TimelinesController < ApiController @statuses = cache_collection(@statuses) set_maps(@statuses) - set_counters_maps(@statuses) - set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) + # set_counters_maps(@statuses) + # set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) unless @statuses.empty? prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty? @@ -27,8 +27,8 @@ class Api::V1::TimelinesController < ApiController @statuses = cache_collection(@statuses) set_maps(@statuses) - set_counters_maps(@statuses) - set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) + # set_counters_maps(@statuses) + # set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) unless @statuses.empty? prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty? @@ -44,8 +44,8 @@ class Api::V1::TimelinesController < ApiController @statuses = cache_collection(@statuses) set_maps(@statuses) - set_counters_maps(@statuses) - set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) + # set_counters_maps(@statuses) + # set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq) next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) unless @statuses.empty? prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty? diff --git a/app/controllers/settings/imports_controller.rb b/app/controllers/settings/imports_controller.rb new file mode 100644 index 000000000..cbb5e65da --- /dev/null +++ b/app/controllers/settings/imports_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Settings::ImportsController < ApplicationController + layout 'admin' + + before_action :authenticate_user! + before_action :set_account + + def show + @import = Import.new + end + + def create + @import = Import.new(import_params) + @import.account = @account + + if @import.save + ImportWorker.perform_async(@import.id) + redirect_to settings_import_path, notice: I18n.t('imports.success') + else + render action: :show + end + end + + private + + def set_account + @account = current_user.account + end + + def import_params + params.require(:import).permit(:data, :type) + end +end -- cgit From 433cb198fa930344c7352250dfaae9857f7ba471 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 2 Apr 2017 04:10:22 +0200 Subject: Fix landing page sign up form ignoring username field --- app/controllers/about_controller.rb | 3 +++ app/views/about/index.html.haml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 491036db2..abf4b7df4 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -5,6 +5,9 @@ class AboutController < ApplicationController def index @description = Setting.site_description + + @user = User.new + @user.build_account end def more diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml index be5e406c5..fdfb2b916 100644 --- a/app/views/about/index.html.haml +++ b/app/views/about/index.html.haml @@ -24,7 +24,7 @@ .screenshot-with-signup .mascot= image_tag 'fluffy-elephant-friend.png' - = simple_form_for(:user, url: user_registration_path) do |f| + = simple_form_for(@user, url: user_registration_path) do |f| = f.simple_fields_for :account do |ff| = ff.input :username, autofocus: true, placeholder: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username') } -- cgit From 4b7dca47130b97e2f213cb28def741c6dee46ff1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 2 Apr 2017 16:45:49 +0200 Subject: Fix wording "show reblogs" -> "show boosts", order reports chronologically in admin UI --- .../components/features/home_timeline/components/column_settings.jsx | 4 ++-- app/controllers/admin/reports_controller.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers') diff --git a/app/assets/javascripts/components/features/home_timeline/components/column_settings.jsx b/app/assets/javascripts/components/features/home_timeline/components/column_settings.jsx index 3317210bf..92e700874 100644 --- a/app/assets/javascripts/components/features/home_timeline/components/column_settings.jsx +++ b/app/assets/javascripts/components/features/home_timeline/components/column_settings.jsx @@ -6,7 +6,7 @@ import SettingToggle from '../../notifications/components/setting_toggle'; import SettingText from './setting_text'; const messages = defineMessages({ - filter_regex: { id: 'home.column_settings.filter_regex', defaultMessage: 'Filter by regular expressions' } + filter_regex: { id: 'home.column_settings.filter_regex', defaultMessage: 'Filter out by regular expressions' } }); const outerStyle = { @@ -44,7 +44,7 @@ const ColumnSettings = React.createClass({
- } /> + } />
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 67d57e4eb..0117a18ee 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -7,7 +7,7 @@ class Admin::ReportsController < ApplicationController layout 'admin' def index - @reports = Report.includes(:account, :target_account).paginate(page: params[:page], per_page: 40) + @reports = Report.includes(:account, :target_account).order('id desc').paginate(page: params[:page], per_page: 40) @reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved end -- cgit From 5b12624847f6a599e1bbb3b24fc87c3b222e6716 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 2 Apr 2017 19:43:09 +0200 Subject: Add proper error page for request timeouts --- Gemfile | 2 +- app/controllers/application_controller.rb | 8 ++++++++ app/views/errors/503.html.haml | 5 +++++ config/initializers/timeout.rb | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/views/errors/503.html.haml (limited to 'app/controllers') diff --git a/Gemfile b/Gemfile index 440f2e87b..764010d5d 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ gem 'rails-settings-cached' gem 'simple-navigation' gem 'statsd-instrument' gem 'ruby-oembed', require: 'oembed' +gem 'rack-timeout' gem 'react-rails' gem 'browserify-rails' @@ -89,5 +90,4 @@ group :production do gem 'rails_12factor' gem 'redis-rails' gem 'lograge' - gem 'rack-timeout' end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef9364897..abfb5bb8c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base rescue_from ActionController::RoutingError, with: :not_found rescue_from ActiveRecord::RecordNotFound, with: :not_found rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity + rescue_from Rack::Timeout::RequestExpiryError, Rack::Timeout::RequestTimeoutError, with: :request_timeout before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? before_action :set_locale @@ -69,6 +70,13 @@ class ApplicationController < ActionController::Base end end + def request_timeout + respond_to do |format| + format.any { head 503 } + format.html { render 'errors/503', layout: 'error', status: 503 } + end + end + def current_account @current_account ||= current_user.try(:account) end diff --git a/app/views/errors/503.html.haml b/app/views/errors/503.html.haml new file mode 100644 index 000000000..f88d50d36 --- /dev/null +++ b/app/views/errors/503.html.haml @@ -0,0 +1,5 @@ +- content_for :page_title do + Request timeout + +- content_for :content do + It took too long to process your request. This might be a temporary server issue diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb index 06a29492e..de87fd906 100644 --- a/config/initializers/timeout.rb +++ b/config/initializers/timeout.rb @@ -1,4 +1,6 @@ +Rack::Timeout::Logger.disable +Rack::Timeout.service_timeout = false + if Rails.env.production? Rack::Timeout.service_timeout = 90 - Rack::Timeout::Logger.disable end -- cgit From 2d07cb57714b7aae96593c8ff293c1c3010a13f9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 2 Apr 2017 21:12:18 +0200 Subject: Catching rack timeout from rails doesn't work --- app/controllers/application_controller.rb | 8 -------- app/views/errors/503.html.haml | 5 ----- 2 files changed, 13 deletions(-) delete mode 100644 app/views/errors/503.html.haml (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index abfb5bb8c..ef9364897 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,6 @@ class ApplicationController < ActionController::Base rescue_from ActionController::RoutingError, with: :not_found rescue_from ActiveRecord::RecordNotFound, with: :not_found rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity - rescue_from Rack::Timeout::RequestExpiryError, Rack::Timeout::RequestTimeoutError, with: :request_timeout before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? before_action :set_locale @@ -70,13 +69,6 @@ class ApplicationController < ActionController::Base end end - def request_timeout - respond_to do |format| - format.any { head 503 } - format.html { render 'errors/503', layout: 'error', status: 503 } - end - end - def current_account @current_account ||= current_user.try(:account) end diff --git a/app/views/errors/503.html.haml b/app/views/errors/503.html.haml deleted file mode 100644 index f88d50d36..000000000 --- a/app/views/errors/503.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -- content_for :page_title do - Request timeout - -- content_for :content do - It took too long to process your request. This might be a temporary server issue -- cgit From b7c1b12367b307d07303ce99f2c27bf255ecd56a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 18:55:06 +0200 Subject: Make default admin UI page reports. Add admin UI for creating a domain block --- app/controllers/admin/domain_blocks_controller.rb | 18 +++ app/services/block_domain_service.rb | 10 +- app/views/admin/domain_blocks/index.html.haml | 1 + app/views/admin/domain_blocks/new.html.haml | 18 +++ app/workers/domain_block_worker.rb | 11 ++ config/locales/devise.no.yml | 62 +------- config/locales/doorkeeper.no.yml | 114 +-------------- config/locales/no.yml | 165 +--------------------- config/locales/simple_form.no.yml | 47 +----- config/navigation.rb | 4 +- config/routes.rb | 2 +- 11 files changed, 59 insertions(+), 393 deletions(-) create mode 100644 app/views/admin/domain_blocks/new.html.haml create mode 100644 app/workers/domain_block_worker.rb (limited to 'app/controllers') diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index e362957e7..1f4432847 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -9,6 +9,24 @@ class Admin::DomainBlocksController < ApplicationController @blocks = DomainBlock.paginate(page: params[:page], per_page: 40) end + def new + @domain_block = DomainBlock.new + end + def create + @domain_block = DomainBlock.new(resource_params) + + if @domain_block.save + DomainBlockWorker.perform_async(@domain_block.id) + redirect_to admin_domain_blocks_path, notice: 'Domain block is now being processed' + else + render action: :new + end + end + + private + + def resource_params + params.require(:domain_block).permit(:domain, :severity) end end diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb index 9518b1fcf..6c131bd34 100644 --- a/app/services/block_domain_service.rb +++ b/app/services/block_domain_service.rb @@ -1,13 +1,11 @@ # frozen_string_literal: true class BlockDomainService < BaseService - def call(domain, severity) - DomainBlock.where(domain: domain).first_or_create!(domain: domain, severity: severity) - - if severity == :silence - Account.where(domain: domain).update_all(silenced: true) + def call(domain_block) + if domain_block.silence? + Account.where(domain: domain_block.domain).update_all(silenced: true) else - Account.where(domain: domain).find_each do |account| + Account.where(domain: domain_block.domain).find_each do |account| account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed? SuspendAccountService.new.call(account) end diff --git a/app/views/admin/domain_blocks/index.html.haml b/app/views/admin/domain_blocks/index.html.haml index dbaeb4716..eb7894b86 100644 --- a/app/views/admin/domain_blocks/index.html.haml +++ b/app/views/admin/domain_blocks/index.html.haml @@ -14,3 +14,4 @@ %td= block.severity = will_paginate @blocks, pagination_options += link_to 'Add new', new_admin_domain_block_path, class: 'button' diff --git a/app/views/admin/domain_blocks/new.html.haml b/app/views/admin/domain_blocks/new.html.haml new file mode 100644 index 000000000..fbd39d6cf --- /dev/null +++ b/app/views/admin/domain_blocks/new.html.haml @@ -0,0 +1,18 @@ +- content_for :page_title do + New domain block + += simple_form_for @domain_block, url: admin_domain_blocks_path do |f| + = render 'shared/error_messages', object: @domain_block + + %p.hint The domain block will not prevent creation of account entries in the database, but will retroactively and automatically apply specific moderation methods on those accounts. + + = f.input :domain, placeholder: 'Domain' + = f.input :severity, collection: DomainBlock.severities.keys, wrapper: :with_label, include_blank: false + + %p.hint + %strong Silence + will make the account's posts invisible to anyone who isn't following them. + %strong Suspend + will remove all of the account's content, media, and profile data. + .actions + = f.button :button, 'Create block', type: :submit diff --git a/app/workers/domain_block_worker.rb b/app/workers/domain_block_worker.rb new file mode 100644 index 000000000..884477829 --- /dev/null +++ b/app/workers/domain_block_worker.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class DomainBlockWorker + include Sidekiq::Worker + + def perform(domain_block_id) + BlockDomainService.new.call(DomainBlock.find(domain_block_id)) + rescue ActiveRecord::RecordNotFound + true + end +end diff --git a/config/locales/devise.no.yml b/config/locales/devise.no.yml index 7c665f0da..2fbf0ffd7 100644 --- a/config/locales/devise.no.yml +++ b/config/locales/devise.no.yml @@ -1,61 +1 @@ ---- -no: - devise: - confirmations: - confirmed: Epostaddressen din er blitt bekreftet. - send_instructions: Du vil motta en epost med instruksjoner for hvordan bekrefte din epostaddresse om noen få minutter. - send_paranoid_instructions: Hvis din epostaddresse finnes i vår database vil du motta en epost med instruksjoner for hvordan bekrefte din epost om noen få minutter. - failure: - already_authenticated: Du er allerede innlogget. - inactive: Din konto er ikke blitt aktivert ennå. - invalid: Ugyldig %{authentication_keys} eller passord. - last_attempt: Du har ett forsøk igjen før kontoen din bli låst. - locked: Din konto er låst. - not_found_in_database: Ugyldig %{authentication_keys} eller passord. - timeout: Sesjonen din løp ut på tid. Logg inn på nytt for å fortsette. - unauthenticated: Du må logge inn eller registrere deg før du kan fortsette. - unconfirmed: Du må bekrefte epostadressen din før du kan fortsette. - mailer: - confirmation_instructions: - subject: 'Mastodon: Instruksjoner for å bekrefte epostadresse' - password_change: - subject: 'Mastodon: Passord endret' - reset_password_instructions: - subject: 'Mastodon: Hvordan nullstille passord?' - unlock_instructions: - subject: 'Mastodon: Instruksjoner for å gjenåpne konto' - omniauth_callbacks: - failure: Kunne ikke autentisere deg fra %{kind} fordi "%{reason}". - success: Vellykket autentisering fra %{kind}. - passwords: - no_token: Du har ingen tilgang til denne siden så lenge du ikke kommer fra en epost om nullstilling av passord. Hvis du kommer fra en passordnullstilling epost, dobbelsjekk at du brukte hele URLen. - send_instructions: Du vil motta en epost med instruksjoner for å nullstille passordet ditt om noen få minutter. - send_paranoid_instructions: Hvis epostadressen din finnes i databasen vår vil du motta en instruksjonsmail om passord nullstilling om noen få minutter. - updated: Passordet ditt har blitt endret. Du er nå logget inn. - updated_not_active: Passordet ditt har blitt endret. - registrations: - destroyed: Adjø! Kontoen din har blitt avsluttet. Vi håper at vi ser deg igjen snart. - signed_up: Velkommen! Registrasjonen var vellykket. - signed_up_but_inactive: Registrasjonen var vellykket. Vi kunne dessverre ikke logge deg inn fordi kontoen din ennå ikke har blitt aktivert. - signed_up_but_locked: Registrasjonen var vellykket. Vi kunne dessverre ikke logge deg inn fordi kontoen din har blitt låst. - signed_up_but_unconfirmed: En epostmelding med en bekreftelseslink har blitt sendt til din adresse. Klikk på linken i eposten for å aktivere kontoen din. - update_needs_confirmation: Du har oppdatert kontoen din, men vi må bekrefte din nye epostadresse. Sjekk eposten din og følg bekreftelseslinken for å bekrefte din nye epostadresse. - updated: Kontoen din ble oppdatert. - sessions: - already_signed_out: Logget ut. - signed_in: Logget inn. - signed_out: Logget ut. - unlocks: - send_instructions: Du vil motta en epost med instruksjoner for å åpne kontoen din om noen få minutter. - send_paranoid_instructions: Hvis kontoen din eksisterer vil du motta en epost med instruksjoner for å åpne kontoen din om noen få minutter. - unlocked: Kontoen din ble åpnet uten problemer. Logg på for å fortsette. - errors: - messages: - already_confirmed: har allerede blitt bekreftet, prøv å logg på istedet. - confirmation_period_expired: må bekreftes innen %{period}. Spør om en ny bekreftelsesmail istedet. - expired: har utløpt, spør om en ny en istedet - not_found: ikke funnet - not_locked: var ikke låst - not_saved: - one: '1 feil hindret denne %{resource} fra å bli lagret:' - other: "%{count} feil hindret denne %{resource} fra å bli lagret:" +--- {} diff --git a/config/locales/doorkeeper.no.yml b/config/locales/doorkeeper.no.yml index 7b51289aa..2fbf0ffd7 100644 --- a/config/locales/doorkeeper.no.yml +++ b/config/locales/doorkeeper.no.yml @@ -1,113 +1 @@ ---- -no: - activerecord: - attributes: - doorkeeper/application: - name: Navn - redirect_uri: Omdirigerings-URI - errors: - models: - doorkeeper/application: - attributes: - redirect_uri: - fragment_present: kan ikke inneholde ett fragment. - invalid_uri: må være en gyldig URI. - relative_uri: må være en absolutt URI. - secured_uri: må være en HTTPS/SSL URI. - doorkeeper: - applications: - buttons: - authorize: Autoriser - cancel: Avbryt - destroy: Ødelegg - edit: Endre - submit: Send inn - confirmations: - destroy: Er du sikker? - edit: - title: Endre applikasjon - form: - error: Whoops! Sjekk skjemaet ditt for mulige feil - help: - native_redirect_uri: Bruk %{native_redirect_uri} for lokale tester - redirect_uri: Bruk en linje per URI - scopes: Adskill omfang med mellomrom. La det være blankt for å bruke standard omfang. - index: - callback_url: Callback URL - name: Navn - new: Ny Applikasjon - title: Dine applikasjoner - new: - title: Ny Applikasjoner - show: - actions: Operasjoner - application_id: Applikasjon Id - callback_urls: Callback urls - scopes: Omfang - secret: Hemmelighet - title: 'Applikasjon: %{name}' - authorizations: - buttons: - authorize: Autoriser - deny: Avvis - error: - title: En feil oppsto - new: - able_to: Den vil ha mulighet til - prompt: Applikasjon %{client_name} spør om tilgang til din konto - title: Autorisasjon påkrevd - show: - title: Autoriserings kode - authorized_applications: - buttons: - revoke: Opphev - confirmations: - revoke: Opphev? - index: - application: Applikasjon - created_at: Autorisert - date_format: "%Y-%m-%d %H:%M:%S" - scopes: Omfang - title: Dine autoriserte applikasjoner - errors: - messages: - access_denied: Ressurseieren eller autoriserings tjeneren avviste forespørslen. - credential_flow_not_configured: Ressurseiers passord flyt feilet på grunn av at Doorkeeper.configure.resource_owner_from_credentials ikke var konfigurert. - invalid_client: Klient autentisering feilet på grunn av ukjent klient, ingen autentisering inkludert eller autentiserings metode som ikke er støttet. - invalid_grant: Autoriseringen er ugyldig, utløpt, opphevet, stemmer ikke overens med omdirigerings-URIen eller var utstedt til en annen klient. - invalid_redirect_uri: redirect urien som var inkludert er ikke gyldig. - invalid_request: Forespørslen mangler ett eller flere parametere, inkluderte ett parameter som ikke støttes eller har feil struktur. - invalid_resource_owner: Ressurseierens detaljer er ikke gyldig, eller så kan ikke eieren finnes. - invalid_scope: Det etterspurte omfanget er ugyldig, ukjent eller har feil struktur. - invalid_token: - expired: Tilgangsbeviset har utløpt - revoked: Tilgangsbeviset har blitt opphevet - unknown: Tilgangsbeviset er ugyldig - resource_owner_authenticator_not_configured: Ressurseier kunne ikke finnes fordi Doorkeeper.configure.resource_owner_authenticator ikke er konfigurert. - server_error: Autoriserings tjeneren støtte på en uventet hendelse som hindret den i å svare på forespørslen. - temporarily_unavailable: Autoriserings tjeneren kan ikke håndtere forespørslen grunnet en midlertidig overbelastning eller tjenervedlikehold. - unauthorized_client: Klienten har ikke autorisasjon for å utføre denne forespørslen med denne metoden. - unsupported_grant_type: Autorisasjons tildelings typen er ikke støttet av denne autoriserings tjeneren. - unsupported_response_type: Autorisasjons serveren støtter ikke denne typen av forespørsler. - flash: - applications: - create: - notice: Applikasjon opprettet. - destroy: - notice: Applikasjon slettet. - update: - notice: Applikasjon oppdatert. - authorized_applications: - destroy: - notice: Applikasjon opphevet. - layouts: - admin: - nav: - applications: Applikasjoner - oauth2_provider: OAuth2 tilbyder - application: - title: OAuth autorisering påkrevet - scopes: - follow: følg, blokker, avblokker, avfølg kontoer - read: lese dine data - write: poste på dine vegne +--- {} diff --git a/config/locales/no.yml b/config/locales/no.yml index d4514d5e4..2fbf0ffd7 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -1,164 +1 @@ ---- -no: - about: - about_mastodon: Mastodon er et gratis, åpen kildekode sosialt nettverk. Et desentralisert alternativ til kommersielle plattformer. Slik kan det unngå risikoene ved å ha et enkelt selskap med monopol på din kommunikasjon. Velg en tjener du stoler på — uansett hvilken du velger så kan du interagere med alle andre. Alle kan kjøre sin egen Mastodon og delta sømløst i det sosiale nettverket. - about_this: Om denne instansen - apps: Applikasjoner - business_email: 'Bedriftsepost:' - contact: Kontakt - description_headline: Hva er %{domain}? - domain_count_after: andre instanser - domain_count_before: Koblet til - features: - api: Åpent api for applikasjoner og tjenester - blocks: Rikholdige blokkerings verktøy - characters: 500 tegn per post - chronology: Tidslinjer er kronologiske - ethics: 'Etisk design: Ingen reklame, ingen sporing' - gifv: GIFV sett og korte videoer - privacy: Finmaskete personvernsinnstillinger - public: Offentlige tidslinjer - features_headline: Hva skiller Mastodon fra andre sosiale nettverk - get_started: Kom i gang - links: Lenker - other_instances: Andre instanser - source_code: Kildekode - status_count_after: statuser - status_count_before: Hvem skrev - terms: Betingelser - user_count_after: brukere - user_count_before: Hjem til - accounts: - follow: Følg - followers: Følgere - following: Følger - nothing_here: Det er ingenting her! - people_followed_by: Folk som %{name} følger - people_who_follow: Folk som følger %{name} - posts: Poster - remote_follow: Følg fra andre instanser - unfollow: Avfølg - application_mailer: - settings: 'Endre foretrukne epost innstillinger: %{link}' - signature: Mastodon notiser fra %{instance} - view: 'Se:' - applications: - invalid_url: Den oppgitte URLen er ugyldig - auth: - change_password: Brukerdetaljer - didnt_get_confirmation: Fikk du ikke bekreftelsesmailen din? - forgot_password: Har du glemt passordet ditt? - login: Innlogging - logout: Logg ut - register: Bli med - resend_confirmation: Send bekreftelsesinstruksjoner på nytt - reset_password: Nullstill passord - set_new_password: Sett nytt passord - authorize_follow: - error: Uheldigvis så skjedde det en feil når vi prøvde å få tak i en konto fra en annen instans. - follow: Følg - prompt_html: 'Du (%{self}) har spurt om å følge:' - title: Følg %{acct} - datetime: - distance_in_words: - about_x_hours: "%{count}t" - about_x_months: "%{count}m" - about_x_years: "%{count}å" - almost_x_years: "%{count}å" - half_a_minute: Nylig - less_than_x_minutes: "%{count}min" - less_than_x_seconds: Nylig - over_x_years: "%{count}å" - x_days: "%{count}d" - x_minutes: "%{count}min" - x_months: "%{count}mo" - x_seconds: "%{count}s" - exports: - blocks: Du blokkerer - csv: CSV - follows: Du følger - storage: Media lagring - generic: - changes_saved_msg: Vellykket lagring av endringer! - powered_by: drevet av %{link} - save_changes: Lagre endringer - validation_errors: - one: Noe er ikke helt riktig ennå. Vær snill å se etter en gang til - other: Noe er ikke helt riktig ennå. Det er ennå %{count} feil å rette på - imports: - preface: Du kan importere data om mennesker du følger eller blokkerer inn til kontoen din på denne instansen, fra filer opprettet av eksporter fra andre instanser. - success: Din data ble mottatt og vil bli prosessert så fort som mulig. - types: - blocking: Blokkeringsliste - following: Følgeliste - upload: Opplastning - landing_strip_html: %{name} er en bruker på %{domain}. Du kan følge dem eller interagere med dem hvis du har en konto hvor som helst i fediverset. Hvis du ikke har en konto så kan du registrere deg her. - notification_mailer: - digest: - body: 'Her er en kort oppsummering av hva du har gått glipp av på %{instance} siden du logget deg inn sist den %{since}:' - mention: "%{name} nevnte deg i:" - new_followers_summary: - one: Du har fått en ny følger. Jippi! - other: Du har fått %{count} nye følgere! Imponerende! - subject: - one: "1 ny hendelse siden ditt siste besøk \U0001F418" - other: "%{count} nye hendelser siden ditt siste besøk \U0001F418" - favourite: - body: 'Din status ble satt som favoritt av %{name}' - subject: "%{name} satte din status som favoritt." - follow: - body: "%{name} følger deg!" - subject: "%{name} følger deg" - follow_request: - body: "%{name} har spurt om å få lov til å følge deg" - subject: 'Ventende følger: %{name}' - mention: - body: 'Du ble nevnt av %{name} i:' - subject: Du ble nevnt av %{name} - reblog: - body: 'Din status fikk en boost av %{name}:' - subject: "%{name} ga din status en boost" - pagination: - next: Neste - prev: Forrige - remote_follow: - acct: Tast inn brukernavn@domene som du vil følge fra - missing_resource: Kunne ikke finne URLen for din konto - proceed: Fortsett med følging - prompt: 'Du kommer til å følge:' - settings: - authorized_apps: Autoriserte applikasjoner - back: Tilbake til Mastodon - edit_profile: Endre profil - export: Data eksport - import: Importer - preferences: Foretrukne valg - settings: Innstillinger - two_factor_auth: To-faktor autentisering - statuses: - open_in_web: Åpne i nettleser - over_character_limit: tegngrense på %{max} overskredet - show_more: Vis mer - visibilities: - private: Vis kun til følgere - public: Offentlig - unlisted: Offentlig, men vis ikke på offentlig tidslinje - stream_entries: - click_to_show: Klikk for å vise - reblogged: boostet - sensitive_content: Sensitivt innhold - time: - formats: - default: "%d, %b %Y, %H:%M" - two_factor_auth: - description_html: Hvis du skru på tofaktor autentisering vil innlogging kreve at du har telefonen din, som vil generere koder som du må taste inn. - disable: Skru av - enable: Skru på - instructions_html: "Scan denne QR-koden i Google Authenticator eller en lignende app på telefonen din. Fra nå av så vil denne applikasjonen generere koder for deg som skal brukes under innlogging" - plaintext_secret_html: 'Plain-text secret: %{secret}' - warning: Hvis du ikke kan konfigurere en autentikatorapp nå, så bør du trykke "Skru av"; ellers vil du ikke kunne logge inn. - users: - invalid_email: E-post addressen er ugyldig - invalid_otp_token: Ugyldig two-faktor kode - will_paginate: - page_gap: "…" +--- {} diff --git a/config/locales/simple_form.no.yml b/config/locales/simple_form.no.yml index 6829e6a24..2fbf0ffd7 100644 --- a/config/locales/simple_form.no.yml +++ b/config/locales/simple_form.no.yml @@ -1,46 +1 @@ ---- -no: - simple_form: - hints: - defaults: - avatar: PNG, GIF eller JPG. Maksimalt 2MB. Vil bli nedskalert til 120x120px - display_name: Maksimalt 30 tegn - header: PNG, GIF eller JPG. Maksimalt 2MB. Vil bli nedskalert til 700x335px - locked: Krever at du manuelt godkjenner følgere og setter standard beskyttelse av poster til kun-følgere - note: Maksimalt 160 tegn - imports: - data: CSV fil eksportert fra en annen Mastodon instans - labels: - defaults: - avatar: Avatar - confirm_new_password: Bekreft nytt passord - confirm_password: Bekreft passord - current_password: Nåværende passord - data: Data - display_name: Visningsnavn - email: E-post adresse - header: Header - locale: Språk - locked: Endre konto til privat - new_password: Nytt passord - note: Biografi - otp_attempt: To-faktor kode - password: Passord - setting_default_privacy: Leserettigheter for poster - type: Importeringstype - username: Brukernavn - interactions: - must_be_follower: Blokker meldinger fra ikke-følgere - must_be_following: Blokker meldinger fra folk du ikke følger - notification_emails: - digest: Send oppsummerings eposter - favourite: Send e-post når noen setter din status som favoritt - follow: Send e-post når noen følger deg - follow_request: Send e-post når noen spør om å få følge deg - mention: Send e-post når noen nevner deg - reblog: Send e-post når noen reblogger din status - 'no': 'Nei' - required: - mark: "*" - text: påkrevd - 'yes': 'Ja' +--- {} diff --git a/config/navigation.rb b/config/navigation.rb index 77556e5aa..c6b7b9767 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -14,11 +14,11 @@ SimpleNavigation::Configuration.run do |navigation| settings.item :authorized_apps, safe_join([fa_icon('list fw'), t('settings.authorized_apps')]), oauth_authorized_applications_url end - primary.item :admin, safe_join([fa_icon('cogs fw'), 'Administration']), admin_accounts_url, if: proc { current_user.admin? } do |admin| + primary.item :admin, safe_join([fa_icon('cogs fw'), 'Administration']), admin_reports_url, if: proc { current_user.admin? } do |admin| admin.item :reports, safe_join([fa_icon('flag fw'), 'Reports']), admin_reports_url, highlights_on: %r{/admin/reports} admin.item :accounts, safe_join([fa_icon('users fw'), 'Accounts']), admin_accounts_url, highlights_on: %r{/admin/accounts} admin.item :pubsubhubbubs, safe_join([fa_icon('paper-plane-o fw'), 'PubSubHubbub']), admin_pubsubhubbub_index_url - admin.item :domain_blocks, safe_join([fa_icon('lock fw'), 'Domain Blocks']), admin_domain_blocks_url + admin.item :domain_blocks, safe_join([fa_icon('lock fw'), 'Domain Blocks']), admin_domain_blocks_url, highlights_on: %r{/admin/domain_blocks} admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url admin.item :settings, safe_join([fa_icon('cogs fw'), 'Site Settings']), admin_settings_url diff --git a/config/routes.rb b/config/routes.rb index bfca5c734..ca77191f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,7 +77,7 @@ Rails.application.routes.draw do namespace :admin do resources :pubsubhubbub, only: [:index] - resources :domain_blocks, only: [:index, :create] + resources :domain_blocks, only: [:index, :new, :create] resources :settings, only: [:index, :update] resources :reports, only: [:index, :show] do -- cgit From 71458dc6df368801b32b55bb63baa94375019a83 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 19:17:56 +0200 Subject: When taking action on a report (silence/suspend), it dismisses all other reports for that user automatically --- app/controllers/admin/reports_controller.rb | 4 ++-- app/views/admin/reports/index.html.haml | 35 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 0117a18ee..bb3f028d9 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -22,13 +22,13 @@ class Admin::ReportsController < ApplicationController def suspend Admin::SuspensionWorker.perform_async(@report.target_account.id) - @report.update(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) redirect_to admin_report_path(@report) end def silence @report.target_account.update(silenced: true) - @report.update(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) redirect_to admin_report_path(@report) end diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index 8a5414cef..839259dc2 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -8,20 +8,25 @@ %li= filter_link_to 'Unresolved', action_taken: nil %li= filter_link_to 'Resolved', action_taken: '1' -%table.table - %thead - %tr - %th ID - %th Target - %th Reported by - %th Comment - %th - %tbody - - @reports.each do |report| += form_tag do + + %table.table + %thead %tr - %td= "##{report.id}" - %td= link_to report.target_account.acct, admin_account_path(report.target_account.id) - %td= link_to report.account.acct, admin_account_path(report.account.id) - %td= truncate(report.comment, length: 30, separator: ' ') - %td= table_link_to 'circle', 'View', admin_report_path(report) + %th + %th ID + %th Target + %th Reported by + %th Comment + %th + %tbody + - @reports.each do |report| + %tr + %td= check_box_tag 'select', report.id + %td= "##{report.id}" + %td= link_to report.target_account.acct, admin_account_path(report.target_account.id) + %td= link_to report.account.acct, admin_account_path(report.account.id) + %td= truncate(report.comment, length: 30, separator: ' ') + %td= table_link_to 'circle', 'View', admin_report_path(report) + = will_paginate @reports, pagination_options -- cgit From 68f829e11c058c55a6695b5812aa0577b5b1eea1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 19:27:30 +0200 Subject: Add basic logging of who resolved report --- app/controllers/admin/reports_controller.rb | 6 +++--- app/models/report.rb | 1 + app/views/admin/reports/show.html.haml | 8 +++++++- ...3172249_add_action_taken_by_account_id_to_reports.rb | 5 +++++ db/schema.rb | 17 +++++++++-------- spec/services/block_domain_service_spec.rb | 2 +- 6 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb (limited to 'app/controllers') diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index bb3f028d9..2b3b1809f 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -16,19 +16,19 @@ class Admin::ReportsController < ApplicationController end def resolve - @report.update(action_taken: true) + @report.update(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end def suspend Admin::SuspensionWorker.perform_async(@report.target_account.id) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end def silence @report.target_account.update(silenced: true) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end diff --git a/app/models/report.rb b/app/models/report.rb index 05dc8cff1..fd8e46aac 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -3,6 +3,7 @@ class Report < ApplicationRecord belongs_to :account belongs_to :target_account, class_name: 'Account' + belongs_to :action_taken_by_account, class_name: 'Account' scope :unresolved, -> { where(action_taken: false) } scope :resolved, -> { where(action_taken: true) } diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 74cac016d..caa8415df 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -27,7 +27,7 @@ = link_to remove_admin_report_path(@report, status_id: status.id), method: :post, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: 'Delete' do = fa_icon 'trash' -- unless @report.action_taken? +- if !@report.action_taken? %hr/ %div{ style: 'overflow: hidden' } @@ -36,3 +36,9 @@ = link_to 'Suspend account', suspend_admin_report_path(@report), method: :post, class: 'button' %div{ style: 'float: left' } = link_to 'Mark as resolved', resolve_admin_report_path(@report), method: :post, class: 'button' +- elsif !@report.action_taken_by_account.nil? + %hr/ + + %p + %strong Action taken by: + = @report.action_taken_by_account.acct diff --git a/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb b/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb new file mode 100644 index 000000000..2d4e12198 --- /dev/null +++ b/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb @@ -0,0 +1,5 @@ +class AddActionTakenByAccountIdToReports < ActiveRecord::Migration[5.0] + def change + add_column :reports, :action_taken_by_account_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5a9ca1426..3aaa3e3ad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170330164118) do +ActiveRecord::Schema.define(version: 20170403172249) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -201,13 +201,14 @@ ActiveRecord::Schema.define(version: 20170330164118) do end create_table "reports", force: :cascade do |t| - t.integer "account_id", null: false - t.integer "target_account_id", null: false - t.bigint "status_ids", default: [], null: false, array: true - t.text "comment", default: "", null: false - t.boolean "action_taken", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "account_id", null: false + t.integer "target_account_id", null: false + t.bigint "status_ids", default: [], null: false, array: true + t.text "comment", default: "", null: false + t.boolean "action_taken", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "action_taken_by_account_id" end create_table "settings", force: :cascade do |t| diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index d88b3b55c..8e71d4542 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -14,7 +14,7 @@ RSpec.describe BlockDomainService do bad_status2 bad_attachment - subject.call('evil.org', :suspend) + subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend)) end it 'creates a domain block' do -- cgit From 4c53af64f0b10bc11473df5e3fd1cd7a11b755f6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 4 Apr 2017 01:33:34 +0200 Subject: Fix ActionController::Parameters in API issue --- app/controllers/api/v1/apps_controller.rb | 8 +++++++- app/controllers/api/v1/follows_controller.rb | 8 ++++++-- app/controllers/api/v1/media_controller.rb | 8 +++++++- app/controllers/api/v1/reports_controller.rb | 12 +++++++++--- app/controllers/api/v1/statuses_controller.rb | 14 +++++++++----- app/models/status.rb | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/api/v1/apps_controller.rb b/app/controllers/api/v1/apps_controller.rb index ca9dd0b7e..2ec7280af 100644 --- a/app/controllers/api/v1/apps_controller.rb +++ b/app/controllers/api/v1/apps_controller.rb @@ -4,6 +4,12 @@ class Api::V1::AppsController < ApiController respond_to :json def create - @app = Doorkeeper::Application.create!(name: params[:client_name], redirect_uri: params[:redirect_uris], scopes: (params[:scopes] || Doorkeeper.configuration.default_scopes), website: params[:website]) + @app = Doorkeeper::Application.create!(name: app_params[:client_name], redirect_uri: app_params[:redirect_uris], scopes: (app_params[:scopes] || Doorkeeper.configuration.default_scopes), website: app_params[:website]) + end + + private + + def app_params + params.permit(:client_name, :redirect_uris, :scopes, :website) end end diff --git a/app/controllers/api/v1/follows_controller.rb b/app/controllers/api/v1/follows_controller.rb index c22dacbaa..7c0f44f03 100644 --- a/app/controllers/api/v1/follows_controller.rb +++ b/app/controllers/api/v1/follows_controller.rb @@ -7,7 +7,7 @@ class Api::V1::FollowsController < ApiController respond_to :json def create - raise ActiveRecord::RecordNotFound if params[:uri].blank? + raise ActiveRecord::RecordNotFound if follow_params[:uri].blank? @account = FollowService.new.call(current_user.account, target_uri).try(:target_account) render action: :show @@ -16,6 +16,10 @@ class Api::V1::FollowsController < ApiController private def target_uri - params[:uri].strip.gsub(/\A@/, '') + follow_params[:uri].strip.gsub(/\A@/, '') + end + + def follow_params + params.permit(:uri) end end diff --git a/app/controllers/api/v1/media_controller.rb b/app/controllers/api/v1/media_controller.rb index f8139ade7..aed3578d7 100644 --- a/app/controllers/api/v1/media_controller.rb +++ b/app/controllers/api/v1/media_controller.rb @@ -10,10 +10,16 @@ class Api::V1::MediaController < ApiController respond_to :json def create - @media = MediaAttachment.create!(account: current_user.account, file: params[:file]) + @media = MediaAttachment.create!(account: current_user.account, file: media_params[:file]) rescue Paperclip::Errors::NotIdentifiedByImageMagickError render json: { error: 'File type of uploaded media could not be verified' }, status: 422 rescue Paperclip::Error render json: { error: 'Error processing thumbnail for uploaded media' }, status: 500 end + + private + + def media_params + params.permit(:file) + end end diff --git a/app/controllers/api/v1/reports_controller.rb b/app/controllers/api/v1/reports_controller.rb index 46bdddbc1..f83c573cb 100644 --- a/app/controllers/api/v1/reports_controller.rb +++ b/app/controllers/api/v1/reports_controller.rb @@ -12,13 +12,19 @@ class Api::V1::ReportsController < ApiController end def create - status_ids = params[:status_ids].is_a?(Enumerable) ? params[:status_ids] : [params[:status_ids]] + status_ids = report_params[:status_ids].is_a?(Enumerable) ? report_params[:status_ids] : [report_params[:status_ids]] @report = Report.create!(account: current_account, - target_account: Account.find(params[:account_id]), + target_account: Account.find(report_params[:account_id]), status_ids: Status.find(status_ids).pluck(:id), - comment: params[:comment]) + comment: report_params[:comment]) render :show end + + private + + def report_params + params.permit(:account_id, :comment, status_ids: []) + end end diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 024258c0e..4ece7e702 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -62,11 +62,11 @@ class Api::V1::StatusesController < ApiController end def create - @status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids], - sensitive: params[:sensitive], - spoiler_text: params[:spoiler_text], - visibility: params[:visibility], - application: doorkeeper_token.application) + @status = PostStatusService.new.call(current_user.account, status_params[:status], status_params[:in_reply_to_id].blank? ? nil : Status.find(status_params[:in_reply_to_id]), media_ids: status_params[:media_ids], + sensitive: status_params[:sensitive], + spoiler_text: status_params[:spoiler_text], + visibility: status_params[:visibility], + application: doorkeeper_token.application) render action: :show end @@ -111,4 +111,8 @@ class Api::V1::StatusesController < ApiController @status = Status.find(params[:id]) raise ActiveRecord::RecordNotFound unless @status.permitted?(current_account) end + + def status_params + params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, media_ids: []) + end end diff --git a/app/models/status.rb b/app/models/status.rb index 81b26fd14..daf128572 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -188,7 +188,7 @@ class Status < ApplicationRecord end before_validation do - text.strip! + text&.strip! spoiler_text&.strip! self.reply = !(in_reply_to_id.nil? && thread.nil?) unless reply -- cgit From b510a56c0c3d8c1a48bb295a85b688af94466723 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 4 Apr 2017 02:00:10 +0200 Subject: Only call regeneration worker after first login after a 14 day break --- app/controllers/application_controller.rb | 9 ++++++++- app/controllers/oauth/authorizations_controller.rb | 7 +++++++ app/models/feed.rb | 12 ++---------- app/workers/regeneration_worker.rb | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef9364897..c06142fd4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,7 +39,14 @@ class ApplicationController < ActionController::Base end def set_user_activity - current_user.touch(:current_sign_in_at) if !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago) + return unless !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago) + + # Mark user as signed-in today + current_user.update_tracked_fields(request) + + # If the sign in is after a two week break, we need to regenerate their feed + RegenerationWorker.perform_async(current_user.account_id) if current_user.last_sign_in_at < 14.days.ago + return end def check_suspension diff --git a/app/controllers/oauth/authorizations_controller.rb b/app/controllers/oauth/authorizations_controller.rb index feaad04f6..7c25266d8 100644 --- a/app/controllers/oauth/authorizations_controller.rb +++ b/app/controllers/oauth/authorizations_controller.rb @@ -3,6 +3,7 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController skip_before_action :authenticate_resource_owner! + before_action :set_locale before_action :store_current_location before_action :authenticate_resource_owner! @@ -11,4 +12,10 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController def store_current_location store_location_for(:user, request.url) end + + def set_locale + I18n.locale = current_user.try(:locale) || I18n.default_locale + rescue I18n::InvalidLocale + I18n.locale = I18n.default_locale + end end diff --git a/app/models/feed.rb b/app/models/feed.rb index 5e1905e15..3cbc160a0 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -10,17 +10,9 @@ class Feed max_id = '+inf' if max_id.blank? since_id = '-inf' if since_id.blank? unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i) + status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h - # If we're after most recent items and none are there, we need to precompute the feed - if unhydrated.empty? && max_id == '+inf' && since_id == '-inf' - RegenerationWorker.perform_async(@account.id, @type) - @statuses = Status.send("as_#{@type}_timeline", @account).cache_ids.paginate_by_max_id(limit, nil, nil) - else - status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h - @statuses = unhydrated.map { |id| status_map[id] }.compact - end - - @statuses + unhydrated.map { |id| status_map[id] }.compact end private diff --git a/app/workers/regeneration_worker.rb b/app/workers/regeneration_worker.rb index 289b63d84..82665b581 100644 --- a/app/workers/regeneration_worker.rb +++ b/app/workers/regeneration_worker.rb @@ -5,7 +5,7 @@ class RegenerationWorker sidekiq_options queue: 'pull', backtrace: true - def perform(account_id, timeline_type) - PrecomputeFeedService.new.call(timeline_type, Account.find(account_id)) + def perform(account_id, _ = :home) + PrecomputeFeedService.new.call(:home, Account.find(account_id)) end end -- cgit