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
This commit is contained in:
committed by
Yamagishi Kazutoshi
parent
0f3719f16f
commit
8b69a66380
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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?
|
||||
|
17
app/models/user_invite_request.rb
Normal file
17
app/models/user_invite_request.rb
Normal file
@ -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
|
@ -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?
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user