Skip to content

Commit

Permalink
Add invite comments (mastodon#10465)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Aug 19, 2019
1 parent 9b6a5ed commit cb62a83
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/invites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def invites
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
Expand Down
3 changes: 3 additions & 0 deletions app/models/invite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions app/views/invites/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions app/views/invites/_invite.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions app/views/invites/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions db/migrate/20190403141604_add_comment_to_invites.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCommentToInvites < ActiveRecord::Migration[5.2]
def change
add_column :invites, :comment, :text
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
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
Expand Down

0 comments on commit cb62a83

Please sign in to comment.