# frozen_string_literal: true class AppearanceReleaseImportsController < ApplicationController include AppearanceReleaseContext include ProjectContext before_action :set_project, only: [:create] include ProjectLayout def create authorize AppearanceRelease attachments = appearance_release_params if attachments.nil? alert_message = t 'appearance_releases.create.no_attachments' redirect_to [@project, :appearance_releases], alert: alert_message else filtered_attachments = filter_attachments attachments MatchAppearanceReleasesJob.perform_later(@project, filtered_attachments) notice_message = t 'appearance_releases.create.matching_started' redirect_to [@project, :appearance_releases], notice: notice_message end end private def appearance_releases if @project policy_scope(@project.appearance_releases) else super end end def appearance_release_params params.require(:attachments) end def filter_attachments(attachments) filtered_attachments = [] attachments.each do |attachment| blob = ActiveStorage::Blob.find_signed attachment next if blob.nil? extension = blob.filename.extension filtered_attachments << attachment if blob.image? || extension == 'pdf' end end def acceptable_extensions AppearanceRelease.acceptable_import_file_extensions end end