allow admin to upload interview recording

This commit is contained in:
Bilal
2020-07-16 14:58:22 +02:00
parent e3acdb4d0e
commit 066f8f496e
7 changed files with 224 additions and 14 deletions

View File

@@ -0,0 +1,65 @@
class Admin::CastingCallInterviewsController < Admin::ApplicationController
before_action :set_casting_call_interview, only: [:edit, :update, :show, :complete]
before_action :build_casting_call_interview, only: [:new, :create]
before_action :set_accounts, only: %i[new create edit]
def index
@casting_call_interviews = casting_call_interviews.order_by_recent.paginate(page: params[:page])
end
def create
@casting_call_interview.attributes = casting_call_interview_params
if @casting_call_interview.save
redirect_to [:admin, :casting_call_interviews], notice: t(".notice")
else
render :new
end
end
def update
if @casting_call_interview.update(casting_call_interview_params)
redirect_to [:admin, :casting_call_interviews], notice: t(".notice")
else
render :edit
end
end
def complete
if @casting_call_interview.update(interviewed_at: Time.zone.now)
redirect_to [:admin, :casting_call_interviews], notice: t(".notice")
else
redirect_to [:admin, :casting_call_interviews], notice: t(".alert")
end
end
private
def set_accounts
@accounts = accounts
end
def casting_call_interview_params
params.require(:casting_call_interview).permit(:casting_call_id,
:performer_name,
:interview_date,
:zoom_meeting_url,
:interview_recording)
end
def casting_call_interviews
policy_scope CastingCallInterview
end
def set_casting_call_interview
@casting_call_interview = authorize policy_scope(CastingCallInterview).find(params[:id])
end
def accounts
policy_scope Account
end
def build_casting_call_interview
@casting_call_interview = authorize policy_scope(CastingCallInterview).build
end
end

View File

@@ -1,6 +1,7 @@
class CastingSubmission < ApplicationRecord
belongs_to :casting_call
has_many_attached :files
has_one_attached :interview_recording
has_secure_token

View File

@@ -6,6 +6,21 @@
<%= form.text_field :interview_date, class: "datepicker-control" %>
<%= form.text_field :zoom_meeting_url %>
<% unless casting_call_interview.new_record? %>
<%= form.file_field :interview_recording, accept: "video/*", data: { direct_upload_url: rails_direct_uploads_url, aws_bucket: ENV['AWS_BUCKET'], aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], signer_url: multipart_signatures_url } %>
<% if casting_call_interview.interview_recording.attached? %>
<p>
<%= link_to casting_call_interview.interview_recording do %>
<%= fa_icon "file-text-o" %> <%= casting_call_interview.interview_recording.filename %>
<% end %>
<span class="text-muted"><%= fa_icon "long-arrow-left" %> <em>Current interview recording</em></span>
</p>
<% end %>
<% end %>
<div class="row align-items-center text-center mt-4">
<%= link_to t("shared.cancel"), [:admin, :casting_submissions], class: "col-3 text-reset" %>
<div class="col-9">