diff --git a/app/controllers/admin/communication/website/authors_controller.rb b/app/controllers/admin/communication/website/authors_controller.rb index 5f71ddf18ec2df02e8bd3511e3686d1f32109739..e4b694f4b31f7b90a8f1b09859b483f4cc6c2fb1 100644 --- a/app/controllers/admin/communication/website/authors_controller.rb +++ b/app/controllers/admin/communication/website/authors_controller.rb @@ -1,13 +1,15 @@ class Admin::Communication::Website::AuthorsController < Admin::Communication::Website::ApplicationController def index - @authors = current_university.people.authors.accessible_by(current_ability).ordered.page(params[:page]) + @authors = @website.authors.accessible_by(current_ability) + .ordered + .page(params[:page]) breadcrumb end def show - @author = current_university.people.authors.accessible_by(current_ability).find(params[:id]) - @posts = @author.communication_website_posts.ordered.page(params[:page]) + @author = @website.authors.accessible_by(current_ability).find(params[:id]) + @posts = @author.communication_website_posts.where(communication_website_id: @website.id).ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb index f42168be20eeec033063b733e7cf350caa147f7c..4cc7c2cda7acb2abdd1b40c9429cb92945d33847 100644 --- a/app/controllers/admin/research/journal/articles_controller.rb +++ b/app/controllers/admin/research/journal/articles_controller.rb @@ -1,6 +1,8 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::ApplicationController load_and_authorize_resource class: Research::Journal::Article, through: :journal + include Admin::Reorderable + def index breadcrumb end @@ -58,7 +60,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A def article_params params.require(:research_journal_article) - .permit(:title, :slug, :text, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, researcher_ids: []) + .permit(:title, :slug, :text, :published, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, researcher_ids: []) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb index c470f7e8094cc74912ac79407e66af0bd5e90fb4..b0c1d63da54692956c8ef503b2f12262f19f20b7 100644 --- a/app/controllers/admin/research/journal/volumes_controller.rb +++ b/app/controllers/admin/research/journal/volumes_controller.rb @@ -7,6 +7,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap end def show + @articles = @volume.articles.ordered breadcrumb end @@ -55,7 +56,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap def volume_params params.require(:research_journal_volume) .permit( - :title, :slug, :number, :keywords, :published_at, :description, + :title, :slug, :number, :keywords, :published, :published_at, :description, :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt ) .merge(university_id: current_university.id) diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index 343082a6e9560021d93582600d18efe198bba1a7..4cecdb213ef75b6d41f73ea6dbcba6885350be8d 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -10,6 +10,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll end def show + @articles = @journal.articles.order(published_at: :desc, created_at: :desc).limit(10) breadcrumb end diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index c8f7efb73a29e9931e5d95605d7f3fa8b209d8c0..ae994e920900f5c34f7bf2bacded2f7ab28928ea 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -6,7 +6,7 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr end def show - @researcher = current_university.people.authors.accessible_by(current_ability).find(params[:id]) + @researcher = current_university.people.researchers.accessible_by(current_ability).find(params[:id]) @articles = @researcher.research_journal_articles.ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 31e4032dec4dde87ba6685ff90009dab71bd7e52..71a44e4ee9d0f93adbf4690de1a2b68d5ce9dde0 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -55,9 +55,10 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro end def person_params - params.require(:university_person) - .permit(:first_name, :last_name, :email, :phone, :biography, :slug, :user_id, - :is_author, :is_researcher, :is_teacher, :is_administration) - .merge(university_id: current_university.id) + params.require(:university_person).permit( + :slug, :first_name, :last_name, :email, :phone, + :biography, :picture, :picture_delete, :picture_infos, + :is_researcher, :is_teacher, :is_administration, :user_id + ).merge(university_id: current_university.id) end end diff --git a/app/controllers/server/universities_controller.rb b/app/controllers/server/universities_controller.rb index 95f23cae6cd3a5a2bbe98595fb72a9785e7a5ac8..5dd42f655ab2851bc0271d2645a5cd4359ceb324 100644 --- a/app/controllers/server/universities_controller.rb +++ b/app/controllers/server/universities_controller.rb @@ -19,6 +19,7 @@ class Server::UniversitiesController < Server::ApplicationController end def create + @university.source_university_id = current_university.id if @university.save redirect_to [:server, @university], notice: t('admin.successfully_created_html', model: @university.to_s) else diff --git a/app/jobs/sync_server_admin_users_job.rb b/app/jobs/sync_server_admin_users_job.rb new file mode 100644 index 0000000000000000000000000000000000000000..74934788ce3d5325e3ba99a5b47f7b3408f7e9b4 --- /dev/null +++ b/app/jobs/sync_server_admin_users_job.rb @@ -0,0 +1,10 @@ +class SyncServerAdminUsersJob < ApplicationJob + queue_as :default + + def perform(source_university_id, target_university_id) + source_university = University.find_by(id: source_university_id) + target_university = University.find_by(id: target_university_id) + return unless source_university.present? && target_university.present? + User.synchronize_server_admin_users(source_university, target_university) + end +end diff --git a/app/models/communication/website/imported/author.rb b/app/models/communication/website/imported/author.rb index 79689e42705a185f7c84d6888cdad16ce7b32395..9feb591cba6e3748fc6140d9ad97ac75d34f0b70 100644 --- a/app/models/communication/website/imported/author.rb +++ b/app/models/communication/website/imported/author.rb @@ -57,7 +57,6 @@ class Communication::Website::Imported::Author < ApplicationRecord self.author = University::Person.new university: university self.author.last_name = "Doe" # No title yet self.author.first_name = "John" # No title yet - self.is_author = true self.author.save end puts "Update author #{author.id}" diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index 3481a3ba8bbb031e5509e66ff7ee1f8e06f3827e..0a6c10cb8bae898dc3a6e0a47a1907dcf78007b6 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -101,7 +101,7 @@ class Communication::Website::Imported::Post < ApplicationRecord post.published = true imported_author = website.authors.where(identifier: author).first - post.author = imported_author.author if imported_author.author + post.author = imported_author.author if imported_author&.author.present? imported_categories = website.categories.where(identifier: categories) imported_categories.each do |imported_category| post.categories << imported_category.category unless post.categories.pluck(:id).include?(imported_category.category_id) diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 222d9a439819617e39887d149f9a556cfc87a722..353e781e24be9ebcc021fa2e50d9c15ef1038dce 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -77,7 +77,7 @@ class Communication::Website::Post < ApplicationRecord end def git_destroy_dependencies(website) - explicit_active_storage_blobs + [self] + explicit_active_storage_blobs end def to_s diff --git a/app/models/communication/website/with_abouts.rb b/app/models/communication/website/with_abouts.rb index 2019fd5369476f6002fbf6cc8eff643d60856419..c104183822667f6e0343362c5289bb1e50e5bac4 100644 --- a/app/models/communication/website/with_abouts.rb +++ b/app/models/communication/website/with_abouts.rb @@ -19,6 +19,8 @@ module Communication::Website::WithAbouts foreign_key: :communication_website_id, dependent: :destroy + has_many :authors, -> { distinct }, through: :posts + has_many :categories, class_name: 'Communication::Website::Category', foreign_key: :communication_website_id, @@ -49,7 +51,7 @@ module Communication::Website::WithAbouts def people @people ||= begin - people = posts.collect(&:author) + posts.collect(&:author).compact.map(&:author) + people = authors + authors.compact.map(&:author) if about_school? people += programs.collect(&:university_people_through_teachers).flatten people += programs.collect(&:university_people_through_teachers).flatten.map(&:teacher) diff --git a/app/models/communication/website/with_import.rb b/app/models/communication/website/with_import.rb index 2d9f76b089c5da719f20a13d6c0f28ec941e913a..0643cd2b5d015a59ed3e814d91d1963d3503d566 100644 --- a/app/models/communication/website/with_import.rb +++ b/app/models/communication/website/with_import.rb @@ -13,7 +13,7 @@ module Communication::Website::WithImport ).first_or_create unless imported? imported_website.run! - imported_website + reload end def imported? diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index b58d7922910497627a761caf031cf4c95f0c0915..a48d81818e7d0a1c4d4f32042d520922111cf25d 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -37,7 +37,7 @@ module WithGit def sync_with_git websites_for_self.each do |website| - dependencies = git_dependencies(website).flatten.uniq.compact + dependencies = git_dependencies(website).to_a.flatten.uniq.compact dependencies.each do |object| Communication::Website::GitFile.sync website, object end @@ -48,7 +48,7 @@ module WithGit def destroy_from_git websites_for_self.each do |website| - dependencies = git_destroy_dependencies(website).flatten.uniq.compact + dependencies = git_destroy_dependencies(website).to_a.flatten.uniq.compact dependencies.each do |object| Communication::Website::GitFile.sync website, object, destroy: true end diff --git a/app/models/education/program/role.rb b/app/models/education/program/role.rb index d79798d0670750128e13cd299656cdf71e3c0619..1f9113f5e53033a91fa972fe56e24a68580306cc 100644 --- a/app/models/education/program/role.rb +++ b/app/models/education/program/role.rb @@ -28,6 +28,8 @@ class Education::Program::Role < ApplicationRecord has_many :people, class_name: 'Education::Program::Role::Person', dependent: :destroy has_many :university_people, through: :people, source: :person + after_commit :sync_program + def to_s "#{title}" end @@ -37,4 +39,8 @@ class Education::Program::Role < ApplicationRecord def last_ordered_element program.roles.ordered.last end + + def sync_program + program.sync_with_git + end end diff --git a/app/models/education/program/role/person.rb b/app/models/education/program/role/person.rb index f61f1d20ff98b9b25167825d552f6a91768f83a0..648a7ffb600aea8a560540ede4ce6f06280d4f44 100644 --- a/app/models/education/program/role/person.rb +++ b/app/models/education/program/role/person.rb @@ -24,6 +24,9 @@ class Education::Program::Role::Person < ApplicationRecord belongs_to :person, class_name: 'University::Person' belongs_to :role, class_name: 'Education::Program::Role' + delegate :program, to: :role + + after_commit :sync_program def to_s person.to_s @@ -34,4 +37,8 @@ class Education::Program::Role::Person < ApplicationRecord def last_ordered_element role.people.ordered.last end + + def sync_program + program.sync_with_git + end end diff --git a/app/models/education/program/teacher.rb b/app/models/education/program/teacher.rb index 2a85d592810b94c587411e09d6f8374f22b27d56..bed1c1afdc241e79a9162d63a8ad020b85a7a695 100644 --- a/app/models/education/program/teacher.rb +++ b/app/models/education/program/teacher.rb @@ -27,7 +27,15 @@ class Education::Program::Teacher < ApplicationRecord scope :ordered, -> { joins(:person).order('university_people.last_name, university_people.first_name') } + after_commit :sync_program + def to_s person.to_s end + + protected + + def sync_program + program.sync_with_git + end end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 1bcdadf4ae0349d868949a1bd7208bda3153472d..6f79e2f3beb978ade47e0fe8d554ec8fcb5824c6 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -50,4 +50,10 @@ class Education::School < ApplicationRecord def git_path(website) "data/school.yml" end + + def git_dependencies(website) + [self] + + university_people_through_administrators + + university_people_through_administrators.map(&:administrator) + end end diff --git a/app/models/education/school/administrator.rb b/app/models/education/school/administrator.rb index 42c86f05d85da39dabe4259c4f405644814febc5..33a37caa29e7ab9f5db9fcd87102320092589362 100644 --- a/app/models/education/school/administrator.rb +++ b/app/models/education/school/administrator.rb @@ -25,9 +25,17 @@ class Education::School::Administrator < ApplicationRecord validates :person_id, uniqueness: { scope: :school_id } + after_commit :sync_school + scope :ordered, -> { joins(:person).order('university_people.last_name, university_people.first_name') } def to_s person.to_s end + + protected + + def sync_school + school.sync_with_git + end end diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index e4c27aa309013f9424b4695c1a82ef3f70f9678d..ca553be57329cd12042f94c559510be3108e8e8c 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -6,6 +6,8 @@ # abstract :text # keywords :text # old_text :text +# position :integer +# published :boolean default(FALSE) # published_at :date # references :text # slug :string @@ -33,6 +35,7 @@ # class Research::Journal::Article < ApplicationRecord include WithGit + include WithPosition has_rich_text :text has_one_attached :pdf @@ -47,12 +50,14 @@ class Research::Journal::Article < ApplicationRecord association_foreign_key: :researcher_id has_many :websites, -> { distinct }, through: :journal - validates :title, :published_at, presence: true + validates :title, presence: true - scope :ordered, -> { order(:published_at, :created_at) } + before_validation :set_published_at, if: :published_changed? + + scope :published, -> { where(published: true) } def git_path(website) - "content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at + "content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if (volume.nil? || volume.published_at) && published_at end def git_dependencies(website) @@ -62,4 +67,17 @@ class Research::Journal::Article < ApplicationRecord def to_s "#{ title }" end + + protected + + def last_ordered_element + Research::Journal::Article.where( + university_id: university_id, + research_journal_volume_id: research_journal_volume_id + ).ordered.last + end + + def set_published_at + self.published_at = published? ? Time.zone.now : nil + end end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 6724c4399cb70268ffb6426dabe9593ba5e51e79..328ded75e988538c46d829ce930f25825a8b6060 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -7,6 +7,7 @@ # featured_image_alt :string # keywords :text # number :integer +# published :boolean default(FALSE) # published_at :date # slug :string # title :string @@ -37,6 +38,9 @@ class Research::Journal::Volume < ApplicationRecord has_many :websites, -> { distinct }, through: :journal has_many :researchers, through: :articles + before_validation :set_published_at, if: :published_changed? + + scope :published, -> { where(published: true) } scope :ordered, -> { order(number: :desc, published_at: :desc) } def website @@ -62,4 +66,10 @@ class Research::Journal::Volume < ApplicationRecord def to_s "##{ number } #{ title }" end + + protected + + def set_published_at + self.published_at = published? ? Time.zone.now : nil + end end diff --git a/app/models/university/person.rb b/app/models/university/person.rb index f9c448947ef9ad0e28dd7a302e4c8deffb37b16d..1012cf47ee3c92aa95ccbceefa9db26ab417fb89 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -6,7 +6,6 @@ # email :string # first_name :string # is_administration :boolean -# is_author :boolean # is_researcher :boolean # is_teacher :boolean # last_name :string @@ -30,6 +29,7 @@ class University::Person < ApplicationRecord include WithGit include WithSlug + include WithPicture has_rich_text :biography @@ -62,6 +62,11 @@ class University::Person < ApplicationRecord foreign_key: :author_id, dependent: :nullify + has_many :communication_website_imported_authors, + class_name: "Communiation::Website::Imported::Author", + foreign_key: :author_id, + dependent: :destroy + has_many :author_websites, -> { distinct }, through: :communication_website_posts, @@ -77,6 +82,7 @@ class University::Person < ApplicationRecord through: :education_programs, source: :websites + validates_presence_of :first_name, :last_name validates_uniqueness_of :email, scope: :university_id, @@ -91,7 +97,6 @@ class University::Person < ApplicationRecord scope :ordered, -> { order(:last_name, :first_name) } scope :administration, -> { where(is_administration: true) } - scope :authors, -> { where(is_author: true) } scope :teachers, -> { where(is_teacher: true) } scope :researchers, -> { where(is_researcher: true) } @@ -109,7 +114,10 @@ class University::Person < ApplicationRecord def git_dependencies(website) dependencies = [] - dependencies << self if for_website?(website) + if for_website?(website) + dependencies << self + dependencies << best_picture.blob + end dependencies << administrator if administrator.for_website?(website) dependencies << author if author.for_website?(website) dependencies << researcher if researcher.for_website?(website) diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index 6b54869f5a42562f71dbeee9ebbce79452da1711..2c16151fbd331d0ec0c4f518c124f68dc436d03a 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -6,7 +6,6 @@ # email :string # first_name :string # is_administration :boolean -# is_author :boolean # is_researcher :boolean # is_teacher :boolean # last_name :string diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb index 3353e96cb907c060848f722441145f9847645ba0..be788bef945fd5bb828ae62e5d4c8d2f69ab12a7 100644 --- a/app/models/university/person/author.rb +++ b/app/models/university/person/author.rb @@ -6,7 +6,6 @@ # email :string # first_name :string # is_administration :boolean -# is_author :boolean # is_researcher :boolean # is_teacher :boolean # last_name :string @@ -37,8 +36,8 @@ class University::Person::Author < University::Person end def for_website?(website) - is_author && communication_website_posts.published - .where(communication_website_id: website&.id) - .any? + communication_website_posts.published + .where(communication_website_id: website&.id) + .any? end end diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb index 727ee2c3a3f2675f8836a76319960616fcddd3b4..f1b7341ad36fad9dcc90a6d001d2b45ee1eca4ab 100644 --- a/app/models/university/person/researcher.rb +++ b/app/models/university/person/researcher.rb @@ -6,7 +6,6 @@ # email :string # first_name :string # is_administration :boolean -# is_author :boolean # is_researcher :boolean # is_teacher :boolean # last_name :string diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index fe13ebe93208a726472d5c811995f5144634b778..6e5f3a761f1432afede463cc1c9b2b05bd110d7e 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -6,7 +6,6 @@ # email :string # first_name :string # is_administration :boolean -# is_author :boolean # is_researcher :boolean # is_teacher :boolean # last_name :string diff --git a/app/models/university/person/with_picture.rb b/app/models/university/person/with_picture.rb new file mode 100644 index 0000000000000000000000000000000000000000..31be4dd3debe9670fc969cf3cbfded6e9a0138c3 --- /dev/null +++ b/app/models/university/person/with_picture.rb @@ -0,0 +1,19 @@ +module University::Person::WithPicture + extend ActiveSupport::Concern + + included do + has_one_attached_deletable :picture + end + + def best_picture + @best_picture ||= begin + best_picture = picture + best_picture = user.picture if !picture.attached? && user.present? + best_picture + end + end + + def best_picture_inherits_from_user? + user.present? && best_picture == user.picture + end +end diff --git a/app/models/university/with_users.rb b/app/models/university/with_users.rb index ccc0ea64e00c21c0d6681eb767195c99e089e027..dacbaf54c15f791085d72c50e6fcb6412f1cc622 100644 --- a/app/models/university/with_users.rb +++ b/app/models/university/with_users.rb @@ -2,6 +2,8 @@ module University::WithUsers extend ActiveSupport::Concern included do + attr_accessor :source_university_id + has_many :users, dependent: :destroy after_commit :synchronize_server_admin_users, on: :create @@ -9,9 +11,8 @@ module University::WithUsers private def synchronize_server_admin_users - User.synchronize_server_admin_users(id) + return unless source_university_id.present? + SyncServerAdminUsersJob.perform_later(source_university_id, id) end - handle_asynchronously :synchronize_server_admin_users, queue: 'default' - end end diff --git a/app/models/user/with_sync_between_universities.rb b/app/models/user/with_sync_between_universities.rb index 341601120e9246a27c9833dfe88b040c73182c80..f1a1eed41615723d36bf25d69dbb22dc14b9c233 100644 --- a/app/models/user/with_sync_between_universities.rb +++ b/app/models/user/with_sync_between_universities.rb @@ -2,41 +2,49 @@ module User::WithSyncBetweenUniversities extend ActiveSupport::Concern included do - after_save :sync_from_current_university, if: Proc.new { |user| user.server_admin? } + attr_accessor :skip_server_admin_sync - def self.synchronize_server_admin_users(university_id) - university = University.where.not(id: university_id).first - university.users.server_admin.each(&:sync_from_current_university) if university + after_save :sync_between_universities, if: Proc.new { |user| user.server_admin? && !user.skip_server_admin_sync } + + def self.synchronize_server_admin_users(source_university, target_university) + source_university.users.server_admin.each do |user| + user.sync_in_university(target_university) + end end end - def sync_from_current_university - University.where.not(id: university_id).each do |university| - unless User.where(email: email, university_id: university.id).any? - duplicate_user_for_university(university) - else - User.where(email: email, university_id: university.id).first&.update_columns( - encrypted_password: self.encrypted_password, - first_name: self.first_name, - last_name: self.last_name, - mobile_phone: self.mobile_phone, - role: :server_admin - ) - end + def sync_between_universities + University.where.not(id: university_id).each do |target_university| + sync_in_university(target_university) + end + end + + def sync_in_university(target_university) + unless User.where(email: email, university_id: target_university.id).any? + duplicate_user_for_university(target_university) + else + User.find_by(email: email, university_id: target_university.id)&.update_columns( + encrypted_password: self.encrypted_password, + first_name: self.first_name, + last_name: self.last_name, + mobile_phone: self.mobile_phone, + role: :server_admin + ) end end private - def duplicate_user_for_university(university) + def duplicate_user_for_university(target_university) # Create user for this university user = self.dup - user.assign_attributes(university_id: university.id, picture_infos: nil, + user.assign_attributes(university_id: target_university.id, picture_infos: nil, password: "MyNewPasswordIs2Strong!", password_confirmation: "MyNewPasswordIs2Strong!", reset_password_token: nil, unlock_token: nil, encrypted_otp_secret_key: nil, confirmation_token: Devise.friendly_token, confirmed_at: Time.now, - role: :server_admin) + role: :server_admin, skip_server_admin_sync: true) # as a new user must have a password and we can't access previous user password + byebug user.save user.update_column(:encrypted_password, self.encrypted_password) if user.valid? end diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index c96bd6db126780c99ed5ccd4da9cb474fbec37ae..99427bb40bfaa74d47f3da9e403dd2991452cd5a 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -38,7 +38,7 @@ <%= f.input :published %> <%= f.input :published_at, html5: true %> <%= f.input :pinned %> - <%= f.association :author, collection: current_university.people.authors.ordered %> + <%= f.association :author, collection: current_university.people.ordered %> </div> </div> <div class="card flex-fill w-100"> diff --git a/app/views/admin/communication/websites/show/_authors.html.erb b/app/views/admin/communication/websites/show/_authors.html.erb deleted file mode 100644 index 0953a1a4149fcb6a19a65326e92c6f6668d405cc..0000000000000000000000000000000000000000 --- a/app/views/admin/communication/websites/show/_authors.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<div class="card mb-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to t('create'), - new_admin_communication_website_author_path(website_id: @website), - class: button_classes %> - </div> - <h2 class="card-title"> - <%= link_to admin_communication_website_authors_path(website_id: @website) do %> - <%= t('communication.authors', count: 2) %> - <small> - - - <%= t('communication.website.see_all', number: @website.authors.count) %> - </small> - <% end %> - </h2> - </div> - <%= render 'admin/communication/website/authors/list', authors: @website.authors.ordered.limit(10) %> -</div> diff --git a/app/views/admin/communication/websites/show/_categories.html.erb b/app/views/admin/communication/websites/show/_categories.html.erb deleted file mode 100644 index e4bcfbbf47507f74bc1f7ac75b284477e83d3a9f..0000000000000000000000000000000000000000 --- a/app/views/admin/communication/websites/show/_categories.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<div class="card mb-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to t('create'), - new_admin_communication_website_category_path(website_id: @website), - class: button_classes if can?(:create, Communication::Website::Category) %> - </div> - <h2 class="card-title"> - <%= link_to admin_communication_website_categories_path(website_id: @website) do %> - <%= Communication::Website::Category.model_name.human(count: 2) %> - <small> - - - <%= t('communication.website.see_all', number: @website.categories.count) %> - </small> - <% end %> - </h2> - </div> - <%= render 'admin/communication/website/categories/list', categories: @website.categories.root.ordered %> -</div> diff --git a/app/views/admin/communication/websites/show/_menus.html.erb b/app/views/admin/communication/websites/show/_menus.html.erb deleted file mode 100644 index c5bec2217bc91238ea756b36d1a6d43fafb3c577..0000000000000000000000000000000000000000 --- a/app/views/admin/communication/websites/show/_menus.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<div class="card mb-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to t('create'), - new_admin_communication_website_menu_path(website_id: @website), - class: button_classes if can?(:create, Communication::Website::Menu) %> - </div> - <h2 class="card-title"> - <%= link_to admin_communication_website_menus_path(website_id: @website) do %> - <%= Communication::Website::Menu.model_name.human(count: 2) %> - <small> - - - <%= t('communication.website.see_all', number: @website.menus.count) %> - </small> - <% end %> - </h2> - </div> - <%= render 'admin/communication/website/menus/list', menus: @website.menus.ordered %> -</div> diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb index 92c8711c75acdb429063d87f079fc6af79cfdf71..74fd771a4dd11959c7faf09d8fd0e33a318d465a 100644 --- a/app/views/admin/education/programs/static.html.erb +++ b/app/views/admin/education/programs/static.html.erb @@ -17,7 +17,7 @@ teachers: teachers_description: <% @program.teachers.includes(:person).ordered.each do |teacher| %> "<%= teacher.person.slug %>": > - <%= teacher.description %> + <%= teacher.description.blank? ? teacher.person.biography.to_plain_text : teacher.description %> <% end %> roles: <% @program.roles.ordered.each do |role| %> diff --git a/app/views/admin/education/schools/static.html.erb b/app/views/admin/education/schools/static.html.erb index 19933a14492793a2156e7cb73d0cb8a5462a33fb..60fcb4a93f1a5b8d950b41746ac1962bf53b711d 100644 --- a/app/views/admin/education/schools/static.html.erb +++ b/app/views/admin/education/schools/static.html.erb @@ -11,4 +11,13 @@ country: > <%= ISO3166::Country[@school.country].translations[@school.country.downcase] %> phone: > <%= @school.phone %> +administrators: +<% @school.administrators.includes(:person).ordered.each do |administrator| %> + - "<%= administrator.person.slug %>" +<% end %> +administrators_description: +<% @school.administrators.includes(:person).ordered.each do |administrator| %> + "<%= administrator.person.slug %>": > + <%= administrator.description.blank? ? administrator.person.biography.to_plain_text : administrator.description %> +<% end %> --- diff --git a/app/views/admin/research/journal/articles/_form.html.erb b/app/views/admin/research/journal/articles/_form.html.erb index 60f8b1943c93fdf4698bb958b58ca1f624b8f9ff..c52f9d1e72acc537245adcf6dd9c311b4154e915 100644 --- a/app/views/admin/research/journal/articles/_form.html.erb +++ b/app/views/admin/research/journal/articles/_form.html.erb @@ -27,6 +27,7 @@ </div> <div class="card-body"> <%= f.association :volume, collection: @journal.volumes, label: Research::Journal::Volume.model_name.human %> + <%= f.input :published %> <%= f.input :published_at, html5: true %> <%= f.input :keywords, as: :text, input_html: { rows: 2 } %> <%= f.association :researchers, collection: current_university.people.researchers.ordered, as: :check_boxes %> diff --git a/app/views/admin/research/journal/articles/_list.html.erb b/app/views/admin/research/journal/articles/_list.html.erb index 806c59711ea40dfcf20f5d26dd7973b652984420..a14b7154c9c192d9ce6f0df96c51118431c51041 100644 --- a/app/views/admin/research/journal/articles/_list.html.erb +++ b/app/views/admin/research/journal/articles/_list.html.erb @@ -9,7 +9,11 @@ <tbody> <% articles.each do |article| %> <tr> - <td><%= link_to article, admin_research_journal_article_path(journal_id: article.journal, id: article) %></td> + <td> + <%= link_to article, + admin_research_journal_article_path(journal_id: article.journal, id: article), + class: "#{'opacity-50' unless article.published?}" %> + </td> <td><%= article.published_at %></td> <td class="text-end"> <div class="btn-group" role="group"> diff --git a/app/views/admin/research/journal/articles/show.html.erb b/app/views/admin/research/journal/articles/show.html.erb index 3d1b9e68b4d0ad31a4aea4fa627382e1f2096d3f..dc84c32a4d94365d6e193aad22b0191f7d48a4ff 100644 --- a/app/views/admin/research/journal/articles/show.html.erb +++ b/app/views/admin/research/journal/articles/show.html.erb @@ -28,10 +28,14 @@ <div class="card-body"> <% if @article.volume %> <h3 class="h5"><%= Research::Journal::Article.human_attribute_name('volume') %></h3> - <p><%= link_to @article.volume, [:admin, @article.volume] %></p> + <p><%= link_to @article.volume, [:admin, @article.volume], class: "#{'opacity-50' unless @article.volume.published?}" %></p> <% end %> + <h3 class="h5"><%= Research::Journal::Article.human_attribute_name('published') %></h3> + <p><%= t @article.published %></p> + <% if @article.published? && @article.published_at.present? %> <h3 class="h5"><%= Research::Journal::Article.human_attribute_name('published_at') %></h3> - <p><%=l @article.published_at.to_time, format: :date_with_explicit_month %></p> + <p><%= l @article.published_at.to_time, format: :date_with_explicit_month %></p> + <% end %> <% unless @article.keywords.blank? %> <h3 class="h5"><%= Research::Journal::Article.human_attribute_name('keywords') %></h3> <p><%= @article.keywords %></p> diff --git a/app/views/admin/research/journal/articles/static.html.erb b/app/views/admin/research/journal/articles/static.html.erb index 1f6f1684491ab620bc46b8280feb7b6a2788e20d..ebeb64a936066dc2bf1ccbc38477890391c5a698 100644 --- a/app/views/admin/research/journal/articles/static.html.erb +++ b/app/views/admin/research/journal/articles/static.html.erb @@ -6,7 +6,7 @@ description: > volumes: - "<%= @article.volume.path %>" <% end %> -weight: 1 +weight: <%= @article.position %> date: <%= @article.published_at %> UTC keywords: > <%= @article.keywords %> diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb index 0b53bf2925635413346a07237845b8101d9d7b13..77e82605d2174ed4943dca1dd5fd03eed0c91a9d 100644 --- a/app/views/admin/research/journal/volumes/_form.html.erb +++ b/app/views/admin/research/journal/volumes/_form.html.erb @@ -30,6 +30,7 @@ </div> <div class="card-body"> <%= f.input :number %> + <%= f.input :published %> <%= f.input :published_at, html5: true %> <%= f.input :keywords %> </div> diff --git a/app/views/admin/research/journal/volumes/index.html.erb b/app/views/admin/research/journal/volumes/index.html.erb index cd16b28fe4268b948f95c8600251eecfe3cc67df..0b72e856a09933706cba2c4c5c59b5e3ecc0cc95 100644 --- a/app/views/admin/research/journal/volumes/index.html.erb +++ b/app/views/admin/research/journal/volumes/index.html.erb @@ -12,7 +12,11 @@ <tbody> <% @volumes.each do |volume| %> <tr> - <td><%= link_to volume, admin_research_journal_volume_path(journal_id: @journal, id: volume) %></td> + <td> + <%= link_to volume, + admin_research_journal_volume_path(journal_id: @journal, id: volume), + class: "#{'opacity-50' unless volume.published?}" %> + </td> <td><%= image_tag volume.featured_image.variant(resize: 'x200'), height: 100 if volume.featured_image.attached? %></td> <td><%= volume.published_at %></td> diff --git a/app/views/admin/research/journal/volumes/show.html.erb b/app/views/admin/research/journal/volumes/show.html.erb index 403477a987f7de9db0da36b6d50b1cc7391be1f5..da93defb44dc656924bfa7525c335a8b5b387732 100644 --- a/app/views/admin/research/journal/volumes/show.html.erb +++ b/app/views/admin/research/journal/volumes/show.html.erb @@ -9,9 +9,41 @@ <div class="card-body"> <h3 class="h5"><%= Research::Journal::Volume.human_attribute_name('description') %></h3> <p><%= @volume.description %></p> - <% if @volume.articles.any? %> + <% if @articles.any? %> <h3 class="h5 mt-4"><%= Research::Journal::Volume.human_attribute_name('articles') %></h3> - <%= render 'admin/research/journal/articles/list', articles: @volume.articles %> + <table class="table table-sortable"> + <thead> + <tr> + <th><%= Research::Journal::Article.model_name.human %></th> + <th><%= Research::Journal::Article.human_attribute_name('published_at') %></th> + <th></th> + </tr> + </thead> + <tbody data-reorder-url="<%= reorder_admin_research_journal_articles_path(journal_id: @journal.id) %>"> + <% @articles.each do |article| %> + <tr class="handle" data-id="<%= article.id %>"> + <td> + <%= link_to article, + admin_research_journal_article_path(journal_id: article.journal, id: article), + class: "#{'opacity-50' unless article.published?}" %> + </td> + <td><%= article.published_at %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= link_to t('edit'), + edit_admin_research_journal_article_path(journal_id: article.journal, id: article), + class: button_classes %> + <%= link_to t('delete'), + admin_research_journal_article_path(journal_id: article.journal, id: article), + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> <% end %> </div> </div> diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb index 19fe4178023d4d87f3f767e8e9fef06eb64a3b40..6866b76a8a9a243db2253d4a2113704c378e798a 100644 --- a/app/views/admin/research/journals/show.html.erb +++ b/app/views/admin/research/journals/show.html.erb @@ -30,7 +30,9 @@ <div class="card"> <%= image_tag volume.featured_image, class: 'img-fluid' if volume.featured_image.attached? %> <div class="card-body"> - <%= link_to volume, admin_research_journal_volume_path(journal_id: @journal, id: volume), class: 'stretched-link' %> + <%= link_to volume, + admin_research_journal_volume_path(journal_id: @journal, id: volume), + class: "stretched-link #{'opacity-50' unless volume.published?}" %> </div> </div> </div> @@ -50,7 +52,7 @@ <%= link_to Research::Journal::Article.model_name.human(count: 2), admin_research_journal_articles_path(journal_id: @journal) %></h2> </div> - <%= render 'admin/research/journal/articles/list', articles: @journal.articles.ordered.limit(10) %> + <%= render 'admin/research/journal/articles/list', articles: @articles %> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index 2a083df900647ebd38e6466161293e952aea19bb..63a54605764ad8a163aeb05b6a8fadf8a432709b 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -25,6 +25,24 @@ <%= f.input :biography, as: :rich_text_area %> </div> </div> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= University::Person.human_attribute_name('abilities') %></h5> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-md-6"> + <%= f.input :is_teacher %> + </div> + <div class="col-md-6"> + <%= f.input :is_researcher %> + </div> + <div class="col-md-6"> + <%= f.input :is_administration %> + </div> + </div> + </div> + </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> @@ -43,13 +61,16 @@ </div> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title mb-0"><%= University::Person.human_attribute_name('abilities') %></h5> + <h5 class="card-title mb-0"><%= University::Person.human_attribute_name('picture') %></h5> </div> <div class="card-body"> - <%= f.input :is_author %> - <%= f.input :is_teacher %> - <%= f.input :is_researcher %> - <%= f.input :is_administration %> + <%= f.input :picture, + as: :single_deletable_file, + label: false, + input_html: { accept: '.jpg,.jpeg,.png' }, + preview: 200, + resize: 1, + direct_upload: true %> </div> </div> </div> diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb index 9a5f7ebe40c41eef589c8420e2d6ef73a7e9b5d8..0ac59b529258ba56980a0c747f139de6e14bccec 100644 --- a/app/views/admin/university/people/_main_infos.html.erb +++ b/app/views/admin/university/people/_main_infos.html.erb @@ -32,5 +32,22 @@ <% end %> </div> </div> + <% if person.best_picture.attached? %> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= t('activerecord.attributes.university/person.picture') %></h2> + </div> + <div class="card-body"> + <% if person.best_picture_inherits_from_user? %> + <p> + <span class="small text-muted"> + <%= t 'admin.inheritance.sentence_html', link: link_to(person.user, [:admin, person.user]) %> + </span> + </p> + <% end %> + <%= kamifusen_tag person.best_picture, class: 'img-fluid' %> + </div> + </div> + <% end %> </div> </div> diff --git a/app/views/admin/university/people/static.html.erb b/app/views/admin/university/people/static.html.erb index 53dc13c4d1faa0110a248c149d139b87791ee0da..a90dfeb621a774b90760b1c8ea2117b59118b96e 100644 --- a/app/views/admin/university/people/static.html.erb +++ b/app/views/admin/university/people/static.html.erb @@ -6,6 +6,9 @@ first_name: "<%= @person.first_name %>" last_name: "<%= @person.last_name %>" phone: "<%= @person.phone %>" email: "<%= @person.email %>" +<% if @person.best_picture.attached? %> +image: "<%= @person.best_picture.blob.id %>" +<% end %> roles: <% if @person.author.for_website?(@website) %> - author diff --git a/app/views/admin/university/person/administrators/static.html.erb b/app/views/admin/university/person/administrators/static.html.erb index 0424fd9996b4f088369a72d1eed11dc5f47e9fde..d7ea4ecd235cae5ee597d1a00decdc22799f425d 100644 --- a/app/views/admin/university/person/administrators/static.html.erb +++ b/app/views/admin/university/person/administrators/static.html.erb @@ -3,5 +3,9 @@ title: > Responsabilités de <%= @administrator.to_s %> person: > <%= @administrator.to_s %> +first_name: > + <%= @administrator.first_name %> +last_name: > + <%= @administrator.last_name %> slug: "<%= @administrator.slug %>" --- diff --git a/app/views/admin/university/person/authors/static.html.erb b/app/views/admin/university/person/authors/static.html.erb index caef355c905532c463041ff091a9251a8672f467..80685cbe2857d545ae666c0aa488051503873734 100644 --- a/app/views/admin/university/person/authors/static.html.erb +++ b/app/views/admin/university/person/authors/static.html.erb @@ -3,5 +3,9 @@ title: > Actualités de <%= @author.to_s %> person: > <%= @author.to_s %> +first_name: > + <%= @author.first_name %> +last_name: > + <%= @author.last_name %> slug: "<%= @author.slug %>" --- diff --git a/app/views/admin/university/person/researchers/static.html.erb b/app/views/admin/university/person/researchers/static.html.erb index 7286358c1e21d95dc59fd84943446a7bb74459ef..1c7bac29984ee5c79f6df88b211def620f28639e 100644 --- a/app/views/admin/university/person/researchers/static.html.erb +++ b/app/views/admin/university/person/researchers/static.html.erb @@ -3,5 +3,9 @@ title: > Publications de <%= @researcher.to_s %> person: > <%= @researcher.to_s %> +first_name: > + <%= @researcher.first_name %> +last_name: > + <%= @researcher.last_name %> slug: "<%= @researcher.slug %>" --- diff --git a/app/views/admin/university/person/teachers/static.html.erb b/app/views/admin/university/person/teachers/static.html.erb index be19ccd3ebc44ac1bb3ced94ef71271e38acb48d..37c0b6307995d87a12e255df54dd93d4ddae4374 100644 --- a/app/views/admin/university/person/teachers/static.html.erb +++ b/app/views/admin/university/person/teachers/static.html.erb @@ -3,5 +3,9 @@ title: > Enseignements de <%= @teacher.to_s %> person: > <%= @teacher.to_s %> +first_name: > + <%= @teacher.first_name %> +last_name: > + <%= @teacher.last_name %> slug: "<%= @teacher.slug %>" --- diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index 795cc6f972d2a2f4edf3aeb75fa361b3b3b9b44f..f77d0d0e47837266e3fcb44372e230a1899baab9 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -21,6 +21,7 @@ en: abstract: Abstract keywords: Keywords pdf: Article PDF + published: Published? published_at: Published at references: References researchers: Authors @@ -32,6 +33,7 @@ en: description: Description keywords: Keywords number: Number + published: Published? published_at: Published at title: Title research: diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index df48aabfb290845b60937959d574fefa5baa9ee6..3e0afa1768d4d3ccb1202c07d69daba423cfd6f5 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -21,6 +21,7 @@ fr: abstract: Extrait keywords: Mots clés pdf: PDF de l'article + published: Publié ? published_at: Publié le references: Références researchers: Auteu·rs·rices @@ -32,6 +33,7 @@ fr: description: Description keywords: Mots clés number: Numéro + published: Publié ? published_at: Publié le title: Titre research: diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index ef74dc7e08c604706aa06e88ef0ce5567c50669f..edcf48f2b0441d6ef1be9bca74f8327d39d39df6 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -28,6 +28,7 @@ en: last_name: Last name name: Name phone: Phone + picture: Profile picture research_journal_articles: Articles slug: Slug user: User diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index 56e561bb66d4859a3a2f664943c4631ffe624f58..8434dd1ed9612721b113833fedf0ee89ae4f22f9 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -28,6 +28,7 @@ fr: last_name: Nom de famille name: Nom phone: Téléphone + picture: Photo de profil research_journal_articles: Articles slug: Slug user: Utilisateur diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index 678f7e597e92990a02acc56ed29c64a429cd31c0..255b3c3e49fcc576f68c49212de1e73cbfeb59ef 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -2,6 +2,10 @@ namespace :research do resources :researchers, only: [:index, :show] resources :journals do resources :volumes, controller: 'journal/volumes' - resources :articles, controller: 'journal/articles' + resources :articles, controller: 'journal/articles' do + collection do + post :reorder + end + end end end diff --git a/db/migrate/20220111092324_add_published_and_position_to_research_journal_articles.rb b/db/migrate/20220111092324_add_published_and_position_to_research_journal_articles.rb new file mode 100644 index 0000000000000000000000000000000000000000..b6adc118dd4470ff60b6f077aee8dfd234816782 --- /dev/null +++ b/db/migrate/20220111092324_add_published_and_position_to_research_journal_articles.rb @@ -0,0 +1,6 @@ +class AddPublishedAndPositionToResearchJournalArticles < ActiveRecord::Migration[6.1] + def change + add_column :research_journal_articles, :published, :boolean, default: false + add_column :research_journal_articles, :position, :integer + end +end diff --git a/db/migrate/20220111101410_add_published_to_research_journal_volumes.rb b/db/migrate/20220111101410_add_published_to_research_journal_volumes.rb new file mode 100644 index 0000000000000000000000000000000000000000..0ef13b71113451affa970312d687c9538cfae30f --- /dev/null +++ b/db/migrate/20220111101410_add_published_to_research_journal_volumes.rb @@ -0,0 +1,5 @@ +class AddPublishedToResearchJournalVolumes < ActiveRecord::Migration[6.1] + def change + add_column :research_journal_volumes, :published, :boolean, default: false + end +end diff --git a/db/migrate/20220112085221_remove_is_author_from_university_people.rb b/db/migrate/20220112085221_remove_is_author_from_university_people.rb new file mode 100644 index 0000000000000000000000000000000000000000..96b1d644e5d319106c952ecc6a7945383e506bbb --- /dev/null +++ b/db/migrate/20220112085221_remove_is_author_from_university_people.rb @@ -0,0 +1,5 @@ +class RemoveIsAuthorFromUniversityPeople < ActiveRecord::Migration[6.1] + def change + remove_column :university_people, :is_author, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 9a2421980d580e5e09e8176f9b8f203d45eb52ce..44cbf87b63419edbf53d97ac4f855275e7f098b5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_01_10_162001) do +ActiveRecord::Schema.define(version: 2022_01_12_085221) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -450,6 +450,8 @@ ActiveRecord::Schema.define(version: 2022_01_10_162001) do t.text "references" t.text "keywords" t.string "slug" + t.boolean "published", default: false + t.integer "position" t.index ["research_journal_id"], name: "index_research_journal_articles_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_articles_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_articles_on_university_id" @@ -475,6 +477,7 @@ ActiveRecord::Schema.define(version: 2022_01_10_162001) do t.text "keywords" t.string "slug" t.string "featured_image_alt" + t.boolean "published", default: false t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id" t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end @@ -512,7 +515,6 @@ ActiveRecord::Schema.define(version: 2022_01_10_162001) do t.string "last_name" t.string "first_name" t.string "slug" - t.boolean "is_author" t.boolean "is_researcher" t.boolean "is_teacher" t.boolean "is_administration" diff --git a/init.js b/init.js deleted file mode 100644 index ca5dbc77126cce4d9d6af840f543c628bfe69555..0000000000000000000000000000000000000000 --- a/init.js +++ /dev/null @@ -1,46 +0,0 @@ -/*global window, document, $ */ -window.b2bylon.training.paths = { - invoke: function () { - 'use strict'; - return { - init: this.init.bind(this) - }; - }, - - init: function () { - 'use strict'; - - this.$kindSelect = $('select#features_training_path_kind'); - if (!this.$kindSelect.length) { - return; - } - this.$folderKindForms = $('.kind-folder'); - this.$activityKindForms = $('.kind-activity'); - this.$activityField = $('input#features_training_path_activity_uid'); - this.$kindSelect.on('change', this.kindChanged.bind(this)); - - this.kindChanged(); - }, - - kindChanged: function () { - 'use strict'; - if (this.$kindSelect.val() === 'activity') { - this.$folderKindForms.hide(); - $('.form-group.required select, .form-group.required input', this.$folderKindForms).removeAttr('required'); - this.$activityKindForms.show(); - $('.form-group.required select, .form-group.required input', this.$activityKindForms).attr('required', 'required'); - } else { - this.$folderKindForms.show(); - $('.form-group.required select, .form-group.required input', this.$folderKindForms).attr('required', 'required'); - this.$activityKindForms.hide(); - $('.form-group.required select, .form-group.required input', this.$activityKindForms).removeAttr('required', 'required'); - } - } - -}.invoke(); - - -document.addEventListener('DOMContentLoaded', function () { - 'use strict'; - window.b2bylon.training.paths.init(); -}); diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 5e728c671e6056d7d58a6e9fee141e99493a3ed6..95f457320e643228f706a753a365cb72f1c4425b 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -29,6 +29,18 @@ namespace :app do Communication::Website::Post.find_each do |post| post.categories = post.categories.select { |category| category.children.none? { |child| post.categories.include?(child) } } end + + Research::Journal::Article.where(position: nil).order(:published_at, :created_at).group_by(&:research_journal_volume_id).each do |_, articles| + articles.each_with_index do |article, index| + article.update_columns({ + published: article.published_at.present?, + position: index + 1 + }) + end + end + Research::Journal::Volume.find_each do |volume| + volume.update_column :published, volume.published_at.present? + end end namespace :db do