Browse Source

Add invite comments (#10465)

master^2
ThibG 4 years ago
committed by Eugen Rochko
parent
commit
cb62a83a71
7 changed files with 17 additions and 1 deletions
  1. +1
    -1
      app/controllers/invites_controller.rb
  2. +3
    -0
      app/models/invite.rb
  3. +3
    -0
      app/views/invites/_form.html.haml
  4. +3
    -0
      app/views/invites/_invite.html.haml
  5. +1
    -0
      app/views/invites/index.html.haml
  6. +5
    -0
      db/migrate/20190403141604_add_comment_to_invites.rb
  7. +1
    -0
      db/schema.rb

+ 1
- 1
app/controllers/invites_controller.rb 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


+ 3
- 0
app/models/invite.rb 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?


+ 3
- 0
app/views/invites/_form.html.haml 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

+ 3
- 0
app/views/invites/_invite.html.haml View File

@@ -21,5 +21,8 @@
= 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
- 0
app/views/invites/index.html.haml 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

+ 5
- 0
db/migrate/20190403141604_add_comment_to_invites.rb View File

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

+ 1
- 0
db/schema.rb 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


Loading…
Cancel
Save