Skip to content

Commit

Permalink
Merge branch 'main' into images-in-block-files
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudlevy authored Mar 3, 2025
2 parents 2453742 + cf165cb commit 29b71aa
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.4.1"

gem "activestorage-scaleway-service"#, path: "../activestorage-scaleway-service"
gem "active_hashcash", "~> 0.3.2"
gem "active_storage_validations", "~> 1"
gem "add_to_calendar"
gem "aws-sdk-s3"
Expand Down Expand Up @@ -39,6 +40,7 @@ gem "i18n_data", "~> 0"
gem "i18n_date_range"
# gem "i18n_date_range", path: "../../noesya/i18n_date_range"
gem "image_processing"
gem "invisible_captcha", "~> 2.3"
gem "jbuilder"
gem "jquery-rails"
gem "jquery-ui-rails", git: "https://github.com/jquery-ui-rails/jquery-ui-rails.git", tag: "v7.0.0"
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
active_hashcash (0.3.2)
rails (>= 5.2.0)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
Expand Down Expand Up @@ -331,6 +333,8 @@ GEM
image_processing (1.13.0)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
invisible_captcha (2.3.0)
rails (>= 5.2)
io-console (0.8.0)
irb (1.15.1)
pp (>= 0.6.0)
Expand Down Expand Up @@ -720,6 +724,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
active_hashcash (~> 0.3.2)
active_storage_validations (~> 1)
activestorage-scaleway-service
add_to_calendar
Expand Down Expand Up @@ -755,6 +760,7 @@ DEPENDENCIES
i18n_data (~> 0)
i18n_date_range
image_processing
invisible_captcha (~> 2.3)
jbuilder
jquery-rails
jquery-ui-rails!
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/commons/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ window.osuny.search = {
this.modal = document.getElementById('searchModal');
this.field = document.getElementById('searchField');
this.results = document.getElementById('searchResults');
if (this.modal === null) {
return;
}
this.modal.addEventListener('shown.bs.modal', this.open.bind(this));
this.field.addEventListener('input', this.update.bind(this));
this.request = new XMLHttpRequest();
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/devise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//= require simple_form_bs5_file_input
//= require cropperjs/dist/cropper
//= require jquery-cropper/dist/jquery-cropper
//= require hashcash
//= require_self

window.osuny = {};
1 change: 1 addition & 0 deletions app/assets/javascripts/extranet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//= require simple_form_bs5_file_input
//= require summernote/summernote-bs5
//= require autocomplete-rails
//= require hashcash
//= require_tree ./application/plugins
//= require_tree ./extranet
//= require osuny-hugo-theme/script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def publish_batch
target_posts.each do |post|
l10n = post.localization_for(current_language)
next unless l10n.present?
l10n.publish!
is_published ? l10n.publish! : l10n.unpublish!
post.save_and_sync
end
redirect_back fallback_location: admin_communication_website_posts_path,
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class Users::RegistrationsController < Devise::RegistrationsController
include ActiveHashcash
include Users::AddContextToRequestParams
include Users::LayoutChoice

invisible_captcha only: [:create], honeypot: :osuny_verification

before_action :check_hashcash, only: :create
before_action :configure_sign_up_params, only: :create
before_action :configure_account_update_params, only: :update
before_action :confirm_two_factor_authenticated, except: [:new, :create, :cancel]
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
class Users::SessionsController < Devise::SessionsController
include ActiveHashcash
include Users::AddContextToRequestParams
include Users::LayoutChoice

invisible_captcha only: [:create], honeypot: :osuny_verification

before_action :check_hashcash, only: :create

# DELETE /resource/sign_out
def destroy
current_user.invalidate_all_sessions!
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability/program_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def managed_programs_ids
end

def managed_program_localization_ids
@managed_program_localization_ids ||= Education::Program::Localization.where(about_id: managed_program_ids).pluck(:id)
@managed_program_localization_ids ||= Education::Program::Localization.where(about_id: managed_programs_ids).pluck(:id)
end

def managed_program_category_ids
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/block/template/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def selected_programs
program = element.program
next if program.nil?
l10n = program.localization_for(about.language)
next if l10n.draft?
next if l10n.nil? || l10n.draft?
element.program
}.compact
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def to_s

def slug_unavailable?(slug)
self.class.unscoped
.where(extranet_id: self.extranet_id, slug: slug)
.where(
extranet_id: self.extranet_id,
language_id: self.language_id,
slug: slug
)
.where.not(id: self.id)
.exists?
end
Expand Down
10 changes: 7 additions & 3 deletions app/models/communication/extranet/post/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class Communication::Extranet::Post::Localization < ApplicationRecord
include WithUniversity

belongs_to :extranet, class_name: 'Communication::Extranet'

has_summernote :summary

validates :title, presence: true
before_validation :set_extranet_id, on: :create

Expand All @@ -62,7 +62,11 @@ def check_accessibility

def slug_unavailable?(slug)
self.class.unscoped
.where(extranet_id: self.extranet_id, slug: slug)
.where(
extranet_id: self.extranet_id,
language_id: self.language_id,
slug: slug
)
.where.not(id: self.id)
.exists?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# header_cta_url :string
# meta_description :string
# migration_identifier :string
# notes :text
# published :boolean default(FALSE)
# published_at :datetime
# slug :string
Expand Down
1 change: 0 additions & 1 deletion app/models/communication/website/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# id :uuid not null, primary key
# bodyclass :string
# design_options :jsonb
# full_width :boolean default(FALSE)
# migration_identifier :string
# position :integer default(0), not null
Expand Down
4 changes: 3 additions & 1 deletion app/models/concerns/as_localized_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module AsLocalizedTree
joins(:about).where(about_table_name => { parent_id: nil })
}
scope :ordered, -> (language = nil) {
joins(:about).order("#{about_table_name}.position")
# Use the ordered scope from the about class
joins(:about)
.merge(about_class.ordered(language))
}
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/duplicable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def duplicate_localizations_for(instance)
instance_l10n.about = instance
# note: fragile. It only works because every duplicate objects currently has a "title" property.
instance_l10n.title = I18n.t('copy_of', title: l10n.title)
instance_l10n.published = false if instance_l10n.respond_to?(:published)
instance_l10n.published_at = nil if instance_l10n.respond_to?(:published_at)
instance_l10n.save
duplicate_featured_image(l10n, instance_l10n)
duplicate_blocks(l10n, instance_l10n)
Expand Down
6 changes: 6 additions & 0 deletions app/models/concerns/with_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def publish!
save
end

def unpublish!
self.published = false
self.published_at = nil
save
end

def draft?
!published
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/education/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Education::Program < ApplicationRecord
include Filterable
include Categorizable # Must be loaded after Filterable to be filtered by categories
include Localizable
include LocalizableOrderBySlugScope
include LocalizableOrderByNameScope
include Sanitizable
include Searchable
include WebsitesLinkable
Expand Down
4 changes: 3 additions & 1 deletion app/models/education/program/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#
class Education::Program::Localization < ApplicationRecord
include AsLocalization
include AsLocalizedTree
include AsLocalizedTree # ordered scope is overridden below
include Contentful
include Initials
include Pathable
Expand Down Expand Up @@ -92,6 +92,8 @@ class Education::Program::Localization < ApplicationRecord
validates :downloadable_summary, size: { less_than: 50.megabytes }
validates :logo, size: { less_than: 5.megabytes }

scope :ordered, -> (language = nil) { order(:slug) }

def git_path(website)
return unless published? && for_website?(website)
clean_path = Static.clean_path "#{git_path_content_prefix(website)}programs/#{path}/"
Expand Down
5 changes: 5 additions & 0 deletions app/models/education/program/with_websites_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module Education::Program::WithWebsitesCategories
class_name: 'Communication::Website::Portfolio::Category',
dependent: :destroy

has_many :website_page_categories,
class_name: 'Communication::Website::Page::Category',
dependent: :destroy

has_many :website_post_categories,
class_name: 'Communication::Website::Post::Category',
dependent: :destroy
Expand All @@ -26,6 +30,7 @@ def website_category_l10ns_for(website, language)
categories[:events] = website_agenda_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories[:posts] = website_post_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories[:projects] = website_portfolio_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories[:pages] = website_page_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories.compact
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ taxonomies:
if free_categories_content.present? %>
- name: "<%= t('category.title') %>"
slug: ""
path: ""
categories:
<%= sanitize free_categories_content %>
<% end %>
Expand All @@ -47,6 +48,7 @@ taxonomies:
if taxonomy_content.present? %>
- name: "<%= prepare_text_for_static taxonomy_l10n.to_s %>"
slug: "<%= hugo.slug %>"
path: "<%= hugo.path %>"
categories:
<%= sanitize taxonomy_content %>
<%
Expand Down
22 changes: 11 additions & 11 deletions app/views/admin/communication/blocks/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="spinner-border text-primary" role="status">
<span class="sr-only"><%= t 'loading' %></span>
</div>
<%= simple_form_for [:admin, @block],
<%= simple_form_for [:admin, @block],
remote: true,
html: { id: 'block-form' } do |f| %>
<%= f.error_notification %>
Expand All @@ -26,20 +26,20 @@
input_html: { data: { translatable: true } } %>

<%= render "admin/communication/blocks/templates/#{@block.template_kind}/edit", f: f, block: @block %>

<div class="mt-5">
<a class="text-muted small"
data-bs-toggle="collapse"
href="#advanced"
role="button"
aria-expanded="false"
data-bs-toggle="collapse"
href="#advanced"
role="button"
aria-expanded="false"
aria-controls="advanced">
<i class="bi bi-gear-fill"></i>
<%= t('admin.advanced_settings') %>
</a>
<div class="collapse mt-3" id="advanced">
<%
if @block.title.present?
<%
if @block.title.present?
slug = @block.slug
about_l10n = @block.about
about = about_l10n.about
Expand All @@ -48,7 +48,7 @@
<%= osuny_label t('admin.communication.blocks.advanced.anchor') %>
<pre>#<%= slug %></pre>
<%
if about.is_direct_object?
if about.try(:is_direct_object?)
website = about.website
hugo = about_l10n.hugo(website)
%>
Expand Down Expand Up @@ -266,9 +266,9 @@
window.addEventListener('load', function(){
setTimeout(function() {
app.mount('#app');

$("#block-form").on("ajax:success", function(e) {
let blockIdentifier = "<%= @block.id %>",
let blockIdentifier = "<%= @block.id %>",
blockPath = "<%= admin_communication_block_path(@block) %>";
parent.window.osuny.contentEditor.offcanvas.onBlockSave(blockIdentifier, blockPath);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ partial = "admin/communication/medias/contexts/#{key}"
<% rescue %>
<%
object = context.about
next if object.nil?
# If it's a localization, get real object
if object.respond_to?(:about)
object = object.about
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ section_taxonomies:
<% if free_categories_content.present? %>
- name: "<%= t('category.title') %>"
slug: ""
path: ""
categories:
<%= sanitize free_categories_content %>
<% end %>
Expand All @@ -32,6 +33,7 @@ section_taxonomies:
if taxonomy_content.present? %>
- name: "<%= prepare_text_for_static taxonomy_l10n.to_s %>"
slug: "<%= hugo.slug %>"
path: "<%= hugo.path %>"
categories:
<%= sanitize taxonomy_content %><%
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/admin/search/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<%
@results.each do |result|
object = result.about_object
next unless can?(:read, object)
l10n = result.about_localization
next unless object.present? && can?(:read, object)
# communication_website_post
path_class = object.class.polymorphic_name.parameterize.underscore
# admin_communication_website_post_path
Expand Down
2 changes: 2 additions & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<div class="row">
<div class="col-lg-6">
<%= f.invisible_captcha :osuny_verification %>
<%= hashcash_hidden_field_tag %>
<%= f.input :email,
required: true,
input_html: {
Expand Down
2 changes: 2 additions & 0 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.invisible_captcha :osuny_verification %>
<%= hashcash_hidden_field_tag %>
<%= f.input :email,
required: false,
autofocus: true,
Expand Down
1 change: 1 addition & 0 deletions config/initializers/active_hashcash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ActiveHashcash.bits = 18
6 changes: 6 additions & 0 deletions config/initializers/invisible_captcha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
InvisibleCaptcha.setup do |config|
# Timestamp check enabled except in test environment
config.timestamp_enabled = !Rails.env.test?
# Spinner check enabled except in test environment
config.spinner_enabled = !Rails.env.test?
end
Loading

0 comments on commit 29b71aa

Please sign in to comment.