Add invite comments (#10465)

pull/1199/head
ThibG 2019-08-19 11:40:42 +02:00 committed by Eugen Rochko
parent 9b6a5ed109
commit cb62a83a71
7 changed files with 17 additions and 1 deletions

View File

@ -43,7 +43,7 @@ class InvitesController < ApplicationController
end
def resource_params
params.require(:invite).permit(:max_uses, :expires_in, :autofollow)
params.require(:invite).permit(:max_uses, :expires_in, :autofollow, :comment)
end
def set_body_classes

View File

@ -12,6 +12,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# autofollow :boolean default(FALSE), not null
# comment :text
#
class Invite < ApplicationRecord
@ -22,6 +23,8 @@ class Invite < ApplicationRecord
scope :available, -> { where(expires_at: nil).or(where('expires_at >= ?', Time.now.utc)) }
validates :comment, length: { maximum: 420 }
before_validation :set_code
def valid_for_use?

View File

@ -10,5 +10,8 @@
.fields-group
= f.input :autofollow, wrapper: :with_label
.fields-group
= f.input :comment, wrapper: :with_label, input_html: { maxlength: 420 }
.actions
= f.button :button, t('invites.generate'), type: :submit

View File

@ -20,6 +20,9 @@
%td{ colspan: 2 }
= t('invites.expired')
%td
= invite.comment
%td
- if invite.valid_for_use? && policy(invite).destroy?
= table_link_to 'times', t('invites.delete'), invite_path(invite), method: :delete

View File

@ -15,6 +15,7 @@
%th
%th= t('invites.table.uses')
%th= t('invites.table.expires_at')
%th= t('invites.table.comment')
%th
%tbody
= render @invites

View File

@ -0,0 +1,5 @@
class AddCommentToInvites < ActiveRecord::Migration[5.2]
def change
add_column :invites, :comment, :text
end
end

View File

@ -344,6 +344,7 @@ ActiveRecord::Schema.define(version: 2019_08_15_225426) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "autofollow", default: false, null: false
t.text "comment"
t.index ["code"], name: "index_invites_on_code", unique: true
t.index ["user_id"], name: "index_invites_on_user_id"
end