about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-04-09 16:06:30 +0200
committerYamagishi Kazutoshi <ykzts@desire.sh>2019-04-09 23:06:30 +0900
commit8b69a66380bbe32127e717ca2d79244392b7d2b6 (patch)
tree3362aba467a4f40e108f38aa7bf4e76ba48df942 /app/models
parent0f3719f16fb5a2704416fa3afae00ba767ad2b2c (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/models')
-rw-r--r--app/models/user.rb3
-rw-r--r--app/models/user_invite_request.rb17
2 files changed, 20 insertions, 0 deletions
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