Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::Communication::Files::ApplicationController < Admin::Communication::ApplicationController

protected

def breadcrumb
super
add_breadcrumb t('communication.description.parts.file.title'), admin_communication_files_path
breadcrumb_for @file
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class Admin::Communication::Files::CategoriesController < Admin::Communication::Files::ApplicationController
load_and_authorize_resource class: Communication::File::Category,
through: :current_university,
through_association: :communication_file_categories

include Admin::ActAsCategories
include Admin::Localizable

def index
@root_categories = categories.root.ordered(current_language)
@categories_class = categories_class
@feature_nav = 'navigation/admin/communication/files'
breadcrumb
end

def show
@files = @category.files
.ordered(current_language)
.page(params[:page])
breadcrumb
end

def new
@categories = categories
breadcrumb
end

def edit
@categories = categories
breadcrumb
add_breadcrumb t('edit')
end

def create
if @category.save
redirect_to admin_communication_file_category_path(@category),
notice: t('admin.successfully_created_html', model: @category.to_s_in(current_language))
else
@categories = categories
breadcrumb
render :new, status: :unprocessable_content
end
end

def update
if @category.update(category_params)
redirect_to admin_communication_file_category_path(@category),
notice: t('admin.successfully_updated_html', model: @category.to_s_in(current_language))
else
load_invalid_localization
@categories = categories
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_content
end
end

def destroy
@category.destroy
redirect_to admin_communication_file_categories_path,
notice: t('admin.successfully_destroyed_html', model: @category.to_s_in(current_language))
end

protected

def categories_class
Communication::File::Category
end

def categories
current_university.file_categories.ordered(current_language)
end

def breadcrumb
super
add_breadcrumb Communication::File::Category.model_name.human(count: 2),
admin_communication_file_categories_path
breadcrumb_for @category
end

def category_params
permitted_params_for(:communication_file_category)
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 85 lines of similar code in 2 locations (mass = 275) [qlty:similar-code]

85 changes: 85 additions & 0 deletions app/controllers/admin/communication/files_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class Admin::Communication::FilesController < Admin::Communication::Files::ApplicationController
load_and_authorize_resource class: Communication::File,
through: :current_university

include Admin::Localizable

def index
@files = @files.filter_by(params[:filters], current_language)
.ordered(current_language)
.page(params[:page])
@categories = categories.root
breadcrumb
@feature_nav = 'navigation/admin/communication/files'
end

def show
breadcrumb
end

def new
@categories = categories
breadcrumb
end

def pick
picker = Osuny::File::Picker.new
picker.university = current_university
picker.language = current_language
picker.params = params.to_unsafe_hash
render json: picker.to_json
end

def edit
@categories = categories
breadcrumb
add_breadcrumb t('admin.subnav.settings')
end

def create
if @file.save
redirect_to [:admin, @file], notice: t('admin.successfully_created_html', model: @file.to_s_in(current_language))
else
load_invalid_localization
@categories = categories
breadcrumb
render :new, status: :unprocessable_content
end
end

def update
if @file.update(file_params)
redirect_to [:admin, @file], notice: t('admin.successfully_updated_html', model: @file.to_s_in(current_language))
else
load_invalid_localization
@categories = categories
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_content
end
end

def destroy
@file.destroy
redirect_to admin_communication_files_url, notice: t('admin.successfully_destroyed_html', model: @file.to_s_in(current_language))
end

protected

def file_params
params.require(:communication_file)
.permit(
category_ids: [],
localizations_attributes: [
:id, :name, :alt, :credit, :internal_description,
:original_uploaded_file, :language_id
]
)
.merge(university_id: current_university.id)
end

def categories
current_university.communication_file_categories.ordered
end

end
1 change: 1 addition & 0 deletions app/models/communication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.parts
[Communication::Website, :admin_communication_websites_path],
[Communication::Extranet, :admin_communication_extranets_path],
[Communication::Media, :admin_communication_medias_path],
[Communication::File, :admin_communication_files_path],
]
end
end
1 change: 1 addition & 0 deletions app/models/communication/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# html_class :string
# metadata :jsonb
# migration_identifier :string
# native :boolean default(FALSE)
# position :integer not null
# published :boolean default(TRUE)
# template_kind :integer default(NULL), not null, indexed => [university_id]
Expand Down
40 changes: 40 additions & 0 deletions app/models/communication/file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# == Schema Information
#
# Table name: communication_files
#
# id :uuid not null, primary key
# original_byte_size :bigint
# original_checksum :string
# original_content_type :string
# original_filename :string
# created_at :datetime not null
# updated_at :datetime not null
# original_blob_id :uuid not null, indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_files_on_original_blob_id (original_blob_id)
# index_communication_files_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_28f27bc358 (university_id => universities.id)
#
class Communication::File < ApplicationRecord
include Filterable
include Categorizable # Must be loaded after Filterable to be filtered by categories
include Localizable
include LocalizableOrderByNameScope
include WithOpenApi
include WithUniversity

scope :for_search_term, -> (term, language = nil) {
joins(:localizations)
.where(communication_file_localizations: { language_id: language.id })
.where("
unaccent(communication_file_localizations.name) ILIKE unaccent(:term) OR
unaccent(communication_file_localizations.internal_description) ILIKE unaccent(:term)
", term: "%#{sanitize_sql_like(term)}%")
}
end
32 changes: 32 additions & 0 deletions app/models/communication/file/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# == Schema Information
#
# Table name: communication_file_categories
#
# id :uuid not null, primary key
# bodyclass :string
# is_taxonomy :boolean default(FALSE)
# position :integer default(0)
# position_in_tree :integer
# created_at :datetime not null
# updated_at :datetime not null
# parent_id :uuid indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_file_categories_on_parent_id (parent_id)
# index_communication_file_categories_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_00fa9503c3 (university_id => universities.id)
# fk_rails_061315a91c (parent_id => communication_file_categories.id)
#
class Communication::File::Category < ApplicationRecord
include AsCategory
include Localizable
include WithUniversity

has_and_belongs_to_many :files
alias :category_objects :files
end
33 changes: 33 additions & 0 deletions app/models/communication/file/category/localization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# == Schema Information
#
# Table name: communication_file_category_localizations
#
# id :uuid not null, primary key
# featured_image_alt :text
# featured_image_credit :text
# meta_description :text
# name :string
# slug :string
# summary :text
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid uniquely indexed => [language_id], indexed
# language_id :uuid uniquely indexed => [about_id], indexed
# university_id :uuid indexed
#
# Indexes
#
# idx_on_about_id_language_id_f3d63b2051 (about_id,language_id) UNIQUE
# idx_on_university_id_7bebff08b4 (university_id)
# index_communication_file_category_localizations_on_about_id (about_id)
# index_communication_file_category_localizations_on_language_id (language_id)
#
# Foreign Keys
#
# fk_rails_085826a452 (university_id => universities.id)
# fk_rails_cbf5631003 (language_id => languages.id)
# fk_rails_dbc01ccb51 (about_id => communication_file_categories.id)
#
class Communication::File::Category::Localization < ApplicationRecord
include AsCategoryLocalization
end
Loading
Loading