Browse Source

Add invite comments (#10465)

cybrespace-3.0
ThibG 4 years ago committed by Eugen Rochko
parent
commit
cb62a83a71
  1. 2
      app/controllers/invites_controller.rb
  2. 3
      app/models/invite.rb
  3. 3
      app/views/invites/_form.html.haml
  4. 3
      app/views/invites/_invite.html.haml
  5. 1
      app/views/invites/index.html.haml
  6. 5
      db/migrate/20190403141604_add_comment_to_invites.rb
  7. 1
      db/schema.rb

2
app/controllers/invites_controller.rb

@ -43,7 +43,7 @@ class InvitesController < ApplicationController @@ -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

3
app/models/invite.rb

@ -12,6 +12,7 @@ @@ -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 @@ -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?

3
app/views/invites/_form.html.haml

@ -10,5 +10,8 @@ @@ -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

3
app/views/invites/_invite.html.haml

@ -20,6 +20,9 @@ @@ -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

1
app/views/invites/index.html.haml

@ -15,6 +15,7 @@ @@ -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

5
db/migrate/20190403141604_add_comment_to_invites.rb

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

1
db/schema.rb

@ -344,6 +344,7 @@ ActiveRecord::Schema.define(version: 2019_08_15_225426) do @@ -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

Loading…
Cancel
Save