diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-04-09 16:06:30 +0200 |
---|---|---|
committer | Yamagishi Kazutoshi <ykzts@desire.sh> | 2019-04-09 23:06:30 +0900 |
commit | 8b69a66380bbe32127e717ca2d79244392b7d2b6 (patch) | |
tree | 3362aba467a4f40e108f38aa7bf4e76ba48df942 /app | |
parent | 0f3719f16fb5a2704416fa3afae00ba767ad2b2c (diff) |
Add "why do you want to join" field to invite requests (#10524)
* Add "why do you want to join" field to invite requests Fix #10512 * Remove unused translations * Fix broken registrations when no invite request text is submitted
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/about_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/admin/pending_accounts_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/auth/registrations_controller.rb | 14 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/accounts.scss | 26 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/widgets.scss | 9 | ||||
-rw-r--r-- | app/models/user.rb | 3 | ||||
-rw-r--r-- | app/models/user_invite_request.rb | 17 | ||||
-rw-r--r-- | app/views/about/_registration.html.haml | 5 | ||||
-rw-r--r-- | app/views/admin/pending_accounts/_account.html.haml | 22 | ||||
-rw-r--r-- | app/views/auth/registrations/new.html.haml | 9 |
10 files changed, 93 insertions, 19 deletions
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 67bb2c87f..52a51fd62 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -16,7 +16,10 @@ class AboutController < ApplicationController private def new_user - User.new.tap(&:build_account) + User.new.tap do |user| + user.build_account + user.build_invite_request + end end helper_method :new_user diff --git a/app/controllers/admin/pending_accounts_controller.rb b/app/controllers/admin/pending_accounts_controller.rb index 2ea7785fc..249525504 100644 --- a/app/controllers/admin/pending_accounts_controller.rb +++ b/app/controllers/admin/pending_accounts_controller.rb @@ -30,7 +30,7 @@ module Admin private def set_accounts - @accounts = Account.joins(:user).merge(User.pending).page(params[:page]) + @accounts = Account.joins(:user).merge(User.pending).includes(user: :invite_request).page(params[:page]) end def form_account_batch_params diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 16a3ec67a..5c1ff769a 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -10,6 +10,10 @@ class Auth::RegistrationsController < Devise::RegistrationsController before_action :set_instance_presenter, only: [:new, :create, :update] before_action :set_body_classes, only: [:new, :create, :edit, :update] + def new + super(&:build_invite_request) + end + def destroy not_found end @@ -24,17 +28,17 @@ class Auth::RegistrationsController < Devise::RegistrationsController def build_resource(hash = nil) super(hash) - resource.locale = I18n.locale - resource.invite_code = params[:invite_code] if resource.invite_code.blank? - resource.agreement = true + resource.locale = I18n.locale + resource.invite_code = params[:invite_code] if resource.invite_code.blank? + resource.agreement = true + resource.current_sign_in_ip = request.remote_ip - resource.current_sign_in_ip = request.remote_ip if resource.current_sign_in_ip.nil? resource.build_account if resource.account.nil? end def configure_sign_up_params devise_parameter_sanitizer.permit(:sign_up) do |u| - u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation, :invite_code) + u.permit({ account_attributes: [:username], invite_request_attributes: [:text] }, :email, :password, :password_confirmation, :invite_code) end end diff --git a/app/javascript/styles/mastodon/accounts.scss b/app/javascript/styles/mastodon/accounts.scss index f4f458cf4..a790251f4 100644 --- a/app/javascript/styles/mastodon/accounts.scss +++ b/app/javascript/styles/mastodon/accounts.scss @@ -292,3 +292,29 @@ .directory__tag .trends__item__current { width: auto; } + +.pending-account { + &__header { + color: $darker-text-color; + + a { + color: $ui-secondary-color; + text-decoration: none; + + &:hover, + &:active, + &:focus { + text-decoration: underline; + } + } + + strong { + color: $primary-text-color; + font-weight: 700; + } + } + + &__body { + margin-top: 10px; + } +} diff --git a/app/javascript/styles/mastodon/widgets.scss b/app/javascript/styles/mastodon/widgets.scss index 307e509d5..e736d7a7e 100644 --- a/app/javascript/styles/mastodon/widgets.scss +++ b/app/javascript/styles/mastodon/widgets.scss @@ -377,6 +377,10 @@ border: 0; } + strong { + font-weight: 700; + } + thead th { text-align: center; text-transform: uppercase; @@ -414,6 +418,11 @@ } } + &__comment { + width: 50%; + vertical-align: initial !important; + } + @media screen and (max-width: $no-gap-breakpoint) { tbody td.optional { display: none; diff --git a/app/models/user.rb b/app/models/user.rb index d703f9588..c9309bc21 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -74,6 +74,9 @@ class User < ApplicationRecord has_many :applications, class_name: 'Doorkeeper::Application', as: :owner has_many :backups, inverse_of: :user + has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy + accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? } + validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale? validates_with BlacklistedEmailValidator, if: :email_changed? validates_with EmailMxValidator, if: :validate_email_dns? diff --git a/app/models/user_invite_request.rb b/app/models/user_invite_request.rb new file mode 100644 index 000000000..2b76c88b9 --- /dev/null +++ b/app/models/user_invite_request.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: user_invite_requests +# +# id :bigint(8) not null, primary key +# user_id :bigint(8) +# text :text +# created_at :datetime not null +# updated_at :datetime not null +# + +class UserInviteRequest < ApplicationRecord + belongs_to :user, inverse_of: :invite_request + validates :text, presence: true, length: { maximum: 420 } +end diff --git a/app/views/about/_registration.html.haml b/app/views/about/_registration.html.haml index 09cbe2e28..ff32ec8c4 100644 --- a/app/views/about/_registration.html.haml +++ b/app/views/about/_registration.html.haml @@ -10,6 +10,11 @@ = f.input :password, placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password'), :autocomplete => 'off' }, hint: false, disabled: closed_registrations? = f.input :password_confirmation, placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password'), :autocomplete => 'off' }, hint: false, disabled: closed_registrations? + - if approved_registrations? + .fields-group + = f.simple_fields_for :invite_request do |invite_request_fields| + = invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: false + .fields-group = f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.checkbox_agreement_html', rules_path: about_more_path, terms_path: terms_path), disabled: closed_registrations? diff --git a/app/views/admin/pending_accounts/_account.html.haml b/app/views/admin/pending_accounts/_account.html.haml index c520dc065..1ed5dafdd 100644 --- a/app/views/admin/pending_accounts/_account.html.haml +++ b/app/views/admin/pending_accounts/_account.html.haml @@ -1,14 +1,14 @@ .batch-table__row %label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox = f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id - .batch-table__row__content.batch-table__row__content--unpadded - %table.accounts-table - %tbody - %tr - %td - = account.user_email - = "(@#{account.username})" - %br/ - = account.user_current_sign_in_ip - %td.accounts-table__count - = table_link_to 'pencil', t('admin.accounts.edit'), admin_account_path(account.id) + .batch-table__row__content.pending-account + .pending-account__header + = link_to admin_account_path(account.id) do + %strong= account.user_email + = "(@#{account.username})" + %br/ + = account.user_current_sign_in_ip + + - if account.user&.invite_request&.text&.present? + .pending-account__body + %p= account.user&.invite_request&.text diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml index 1caf2b401..bd6e3a13f 100644 --- a/app/views/auth/registrations/new.html.haml +++ b/app/views/auth/registrations/new.html.haml @@ -21,12 +21,19 @@ .fields-group = f.input :password, wrapper: :with_label, label: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password'), :autocomplete => 'off' } + .fields-group = f.input :password_confirmation, wrapper: :with_label, label: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password'), :autocomplete => 'off' } + - if approved_registrations? && !@invite.present? + .fields-group + = f.simple_fields_for :invite_request do |invite_request_fields| + = invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: false + = f.input :invite_code, as: :hidden - %p.hint= t('auth.agreement_html', rules_path: about_more_path, terms_path: terms_path) + .fields-group + = f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.checkbox_agreement_html', rules_path: about_more_path, terms_path: terms_path) .actions = f.button :button, sign_up_message, type: :submit |