このコミットが含まれているのは:
@@ -0,0 +1,49 @@
|
||||
class MaterialSyncSuppressionsController < ApplicationController
|
||||
def index
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
suppressions =
|
||||
MaterialSyncSuppression
|
||||
.includes(:created_by_user)
|
||||
.order(created_at: :desc, id: :desc)
|
||||
|
||||
render json: { suppressions: suppressions.map { |s| repr(s) } }
|
||||
end
|
||||
|
||||
def create
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
suppression =
|
||||
MaterialSyncSuppressionRegistrar.create!(suppression_params,
|
||||
created_by_user: current_user)
|
||||
|
||||
render json: repr(suppression), status: :created
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
render_validation_error e.record
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def suppression_params
|
||||
params.permit(:source_kind,
|
||||
:source_uri,
|
||||
:drive_path,
|
||||
:drive_file_id,
|
||||
:reason)
|
||||
end
|
||||
|
||||
def repr suppression
|
||||
{ id: suppression.id,
|
||||
source_kind: suppression.source_kind,
|
||||
source_uri: suppression.source_uri,
|
||||
drive_path: suppression.drive_path,
|
||||
drive_file_id: suppression.drive_file_id,
|
||||
normalized_source_key: suppression.normalized_source_key,
|
||||
reason: suppression.reason,
|
||||
created_by_user: suppression.created_by_user&.as_json(UserRepr::BASE),
|
||||
created_at: suppression.created_at,
|
||||
updated_at: suppression.updated_at }
|
||||
end
|
||||
end
|
||||
@@ -17,8 +17,6 @@ class MaterialsController < ApplicationController
|
||||
thumbnail_attachment: :blob,
|
||||
file_attachment: :blob,
|
||||
tag: :tag_name)
|
||||
q = q.where(file_suppressed_at: nil) if filters[:suppression] == 'active'
|
||||
q = q.where.not(file_suppressed_at: nil) if filters[:suppression] == 'suppressed'
|
||||
q = q.where(tag_id: nil) if filters[:tag_state] == 'untagged'
|
||||
q = q.where.not(tag_id: nil) if filters[:tag_state] == 'tagged'
|
||||
q = q.where('materials.created_at >= ?', filters[:created_from]) if filters[:created_from]
|
||||
@@ -136,7 +134,6 @@ class MaterialsController < ApplicationController
|
||||
material.assign_attributes(tag:, url:, updated_by_user: current_user)
|
||||
if uploaded_blob
|
||||
material.file.attach(uploaded_blob)
|
||||
clear_file_suppression!(material)
|
||||
elsif params.key?(:url) && url.present? && file.blank?
|
||||
material.file.detach
|
||||
end
|
||||
@@ -182,37 +179,6 @@ class MaterialsController < ApplicationController
|
||||
filename: "btrc-materials-#{ profile }.zip"
|
||||
end
|
||||
|
||||
def suppress_file
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.admin?
|
||||
|
||||
material = Material.with_attached_file.find_by(id: params[:id])
|
||||
return head :not_found unless material
|
||||
|
||||
reason = params[:reason].to_s.strip.presence
|
||||
return render_unprocessable_entity('理由は必須です.', field: :reason) unless reason
|
||||
purge = bool?(:purge)
|
||||
file_snapshot = purge_material_file_snapshot(material) if purge
|
||||
attachment = purge && material.file.attached? ? material.file.attachment : nil
|
||||
|
||||
Material.transaction do
|
||||
MaterialVersionRecorder.ensure_snapshot!(material, created_by_user: current_user)
|
||||
material.update!(file_suppressed_at: Time.current,
|
||||
file_suppressed_by_user: current_user,
|
||||
file_suppression_reason: reason,
|
||||
updated_by_user: current_user)
|
||||
MaterialVersionRecorder.record!(material:, event_type: :suppress,
|
||||
created_by_user: current_user,
|
||||
file_snapshot:)
|
||||
end
|
||||
# Enqueue failure raises here after the suppress metadata has been committed.
|
||||
# In that case the file remains suppressed in UI/ZIP and purge can be retried.
|
||||
attachment&.purge_later
|
||||
material.reload if purge
|
||||
|
||||
render json: MaterialRepr.base(material, host: request.base_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def material_index_filters
|
||||
@@ -225,9 +191,6 @@ class MaterialsController < ApplicationController
|
||||
media_kind = 'all'
|
||||
end
|
||||
|
||||
suppression = params[:suppression].to_s.presence
|
||||
suppression = 'active' unless ['active', 'suppressed', 'all'].include?(suppression)
|
||||
|
||||
sort = params[:sort].to_s.presence
|
||||
unless ['created_at', 'updated_at', 'tag_name', 'media_kind', 'file_byte_size',
|
||||
'version_no', 'id'].include?(sort)
|
||||
@@ -240,7 +203,6 @@ class MaterialsController < ApplicationController
|
||||
{ q: params[:q].to_s.strip.presence,
|
||||
tag_state:,
|
||||
media_kind:,
|
||||
suppression:,
|
||||
created_from: parse_time_param(:created_from),
|
||||
created_to: parse_time_param(:created_to),
|
||||
updated_from: parse_time_param(:updated_from),
|
||||
@@ -410,26 +372,6 @@ class MaterialsController < ApplicationController
|
||||
file.tempfile.rewind if file&.tempfile
|
||||
end
|
||||
|
||||
def clear_file_suppression! material
|
||||
material.file_suppressed_at = nil
|
||||
material.file_suppressed_by_user = nil
|
||||
material.file_suppression_reason = nil
|
||||
end
|
||||
|
||||
def purge_material_file_snapshot material
|
||||
return nil unless material.file.attached?
|
||||
|
||||
blob = material.file.blob
|
||||
|
||||
{ file_blob_id: blob.id,
|
||||
file_filename: blob.filename.to_s,
|
||||
file_content_type: blob.content_type,
|
||||
file_byte_size: blob.byte_size,
|
||||
file_checksum: blob.checksum,
|
||||
file_sha256: blob.metadata['sha256'] ||
|
||||
MaterialFileSha256.from_blob(blob, allow_download: true) }
|
||||
end
|
||||
|
||||
def render_material_import_block block
|
||||
render_validation_error fields: { file: ["抑止された素材です: #{ block.reason }"] }
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする