Add basic invitations
This commit is contained in:
33
app/controllers/invitations_controller.rb
Normal file
33
app/controllers/invitations_controller.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class InvitationsController < ApplicationController
|
||||
before_action :require_user_signed_in
|
||||
|
||||
# GET /invitations
|
||||
def index
|
||||
@invitations = current_user.invitations
|
||||
end
|
||||
|
||||
# POST /invitations
|
||||
def create
|
||||
@invitation = Invitation.new(user: current_user)
|
||||
|
||||
respond_to do |format|
|
||||
if @invitation.save
|
||||
format.html { redirect_to @invitation, notice: 'Invitation was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @invitation }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @invitation.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /invitations/1
|
||||
def destroy
|
||||
@invitation = current_user.invitations.find(params[:id])
|
||||
@invitation.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to invitations_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/invitations_helper.rb
Normal file
2
app/helpers/invitations_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module InvitationsHelper
|
||||
end
|
||||
14
app/models/invitation.rb
Normal file
14
app/models/invitation.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class Invitation < ApplicationRecord
|
||||
# Relations
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :user
|
||||
|
||||
before_create :generate_token
|
||||
|
||||
private
|
||||
|
||||
def generate_token
|
||||
self.token = SecureRandom.hex(8)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,7 @@
|
||||
class User < ApplicationRecord
|
||||
# Relations
|
||||
has_many :invitations, dependent: :destroy
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
devise :ldap_authenticatable,
|
||||
|
||||
23
app/views/invitations/index.html.erb
Normal file
23
app/views/invitations/index.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<section>
|
||||
<h2>Invitations</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Token</th>
|
||||
<th>Created at</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @invitations.each do |invitation| %>
|
||||
<tr>
|
||||
<td><%= invitation.token %></td>
|
||||
<td><%= invitation.created_at %></td>
|
||||
<td><%= link_to 'Delete', invitation, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
Reference in New Issue
Block a user