Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Séparation des catégories #1454

Merged
merged 19 commits into from
Dec 1, 2023
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ GEM
autoprefixer-rails (10.4.16.0)
execjs (~> 2)
aws-eventstream (1.3.0)
aws-partitions (1.857.0)
aws-partitions (1.859.0)
aws-sdk-core (3.188.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -554,7 +554,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
stringio (3.0.9)
stringio (3.1.0)
sugar-high (0.7.3)
sweetloader (0.1.6)
activesupport (>= 3.0.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Admin::Communication::Websites::Agenda::ApplicationController < Admin::Com

def breadcrumb
super
add_breadcrumb Communication::Website::Agenda.model_name.human(count: 2)
add_breadcrumb Communication::Website::Agenda.model_name.human(count: 2),
admin_communication_website_agenda_events_path
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class Admin::Communication::Websites::Agenda::CategoriesController < Admin::Communication::Websites::Agenda::ApplicationController
load_and_authorize_resource class: 'Communication::Website::Agenda::Category',
through: :website,
through_association: :agenda_categories

include Admin::Translatable

def index
@categories = @categories.for_language(current_website_language).ordered
breadcrumb
end

def reorder
ids = params[:ids] || []
ids.each.with_index do |id, index|
category = @website.post_categories.find(id)
category.update_column :position, index + 1
end
@category = @website.agenda_categories.find(params[:itemId])
@category.sync_with_git # Will sync siblings
end

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

def static
@about = @category
render_as_plain_text
end

def new
breadcrumb
end

def edit
breadcrumb
add_breadcrumb t('edit')
end

def create
@category.website = @website
@category.add_photo_import params[:photo_import]
if @category.save_and_sync
redirect_to admin_communication_website_agenda_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end

def update
@category.add_photo_import params[:photo_import]
if @category.update_and_sync(category_params)
redirect_to admin_communication_website_agenda_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end

def destroy
@category.destroy
redirect_to admin_communication_website_agenda_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s)
end

protected

def breadcrumb
arnaudlevy marked this conversation as resolved.
Show resolved Hide resolved
super
add_breadcrumb Communication::Website::Agenda::Category.model_name.human(count: 2),
admin_communication_website_agenda_categories_path
breadcrumb_for @category
end

def category_params
params.require(:communication_website_agenda_category)
.permit(
:name, :meta_description, :summary, :slug,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit
)
.merge(
university_id: current_university.id,
language_id: current_website_language.id
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ class Admin::Communication::Websites::Agenda::EventsController < Admin::Communic
load_and_authorize_resource class: Communication::Website::Agenda::Event,
through: :website

before_action :load_categories, only: [:new, :edit, :create, :update]
before_action :load_categories

def index
@events = apply_scopes(@events).for_language(current_website_language).ordered_desc.page params[:page]
@root_categories = @website.categories.for_language(current_website_language).root.ordered
breadcrumb
end

Expand Down Expand Up @@ -78,6 +77,10 @@ def breadcrumb
breadcrumb_for @event
end

def load_categories
@categories = @website.agenda_categories.for_language(current_website_language).ordered
end

def event_params
params.require(:communication_website_agenda_event)
.permit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,4 @@ def default_url_options
end
options
end

def load_categories
@categories = @website.categories.for_language(current_website_language)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::Communication::Websites::Posts::ApplicationController < Admin::Communication::Websites::ApplicationController

protected

def breadcrumb
super
add_breadcrumb Communication::Website::Post.model_name.human(count: 2),
admin_communication_website_posts_path
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Communication::Websites::AuthorsController < Admin::Communication::Websites::ApplicationController
class Admin::Communication::Websites::Posts::AuthorsController < Admin::Communication::Websites::Posts::ApplicationController

has_scope :for_search_term

Expand All @@ -13,15 +13,15 @@ def show
@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
add_breadcrumb @author
end

protected

def breadcrumb
super
add_breadcrumb t('communication.authors', count: 2),
admin_communication_website_authors_path
breadcrumb_for @author
admin_communication_website_post_authors_path
end

end
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
class Admin::Communication::Websites::CategoriesController < Admin::Communication::Websites::ApplicationController
load_and_authorize_resource class: Communication::Website::Category, through: :website
class Admin::Communication::Websites::Posts::CategoriesController < Admin::Communication::Websites::Posts::ApplicationController
load_and_authorize_resource class: Communication::Website::Post::Category,
through: :website,
Copy link
Member

Choose a reason for hiding this comment

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

la classe est supposée être une string

through_association: :post_categories

include Admin::Translatable

before_action :get_root_categories, only: [:index, :new, :create, :edit, :update]

def index
@categories = @website.categories.for_language(current_website_language).ordered
@categories = @website.post_categories.for_language(current_website_language).ordered
breadcrumb
end

def reorder
parent_id = params[:parentId].blank? ? nil : params[:parentId]
old_parent_id = params[:oldParentId].blank? ? nil : params[:oldParentId]
parent_id = params.dig(:parentId)
old_parent_id = params.dig(:oldParentId)
ids = params[:ids] || []
ids.each.with_index do |id, index|
category = @website.categories.find(id)
category = @website.post_categories.find(id)
category.update_columns parent_id: parent_id,
position: index + 1
end
if old_parent_id
old_parent = @website.categories.find(old_parent_id)
old_parent = @website.post_categories.find(old_parent_id)
old_parent.sync_with_git
end
@website.categories.find(params[:itemId]).sync_with_git # Will sync siblings
@website.post_categories.find(params[:itemId]).sync_with_git # Will sync siblings
end

def children
return unless request.xhr?
@category = @website.categories.for_language(current_website_language).find(params[:id])
@category = @website.post_categories.for_language(current_website_language).find(params[:id])
@children = @category.children.ordered
end

Expand Down Expand Up @@ -56,7 +58,7 @@ def create
@category.website = @website
@category.add_photo_import params[:photo_import]
if @category.save_and_sync
redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s)
redirect_to admin_communication_website_post_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
Expand All @@ -66,7 +68,7 @@ def create
def update
@category.add_photo_import params[:photo_import]
if @category.update_and_sync(category_params)
redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s)
redirect_to admin_communication_website_post_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s)
else
breadcrumb
add_breadcrumb t('edit')
Expand All @@ -82,18 +84,18 @@ def destroy
protected

def get_root_categories
@root_categories = @website.categories.root.for_language(current_website_language).ordered
@root_categories = @website.post_categories.root.for_language(current_website_language).ordered
end

def breadcrumb
super
add_breadcrumb Communication::Website::Category.model_name.human(count: 2),
admin_communication_website_categories_path
add_breadcrumb Communication::Website::Post::Category.model_name.human(count: 2),
admin_communication_website_post_categories_path
breadcrumb_for @category
end

def category_params
params.require(:communication_website_category)
params.require(:communication_website_post_category)
.permit(
:name, :meta_description, :summary, :slug, :parent_id,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Communication::Websites::Posts::CurationsController < Admin::Communication::Websites::ApplicationController
class Admin::Communication::Websites::Posts::CurationsController < Admin::Communication::Websites::Posts::ApplicationController
def new
breadcrumb
end
Expand All @@ -20,8 +20,6 @@ def create

def breadcrumb
super
add_breadcrumb Communication::Website::Post.model_name.human(count: 2),
admin_communication_website_posts_path
add_breadcrumb t('communication.website.posts.new_curation')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
.accessible_by(current_ability)
.ordered
.page(params[:authors_page])
@root_categories = @website.categories.for_language(current_website_language).root.ordered
@root_categories = @website.post_categories.for_language(current_website_language).root.ordered
breadcrumb
end

Expand Down Expand Up @@ -129,4 +129,8 @@ def post_params
def load_filters
@filters = ::Filters::Admin::Communication::Website::Posts.new(current_user, @website).list
end

def load_categories
@categories = @website.post_categories.for_language(current_website_language)
end
end
3 changes: 2 additions & 1 deletion app/models/ability/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def admin_communication
# Le risque de faussse manip est grand.
cannot :destroy, Communication::Website, university_id: @user.university_id
can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id
can :manage, Communication::Website::Category, university_id: @user.university_id
can :manage, Communication::Website::Agenda::Category, university_id: @user.university_id
can :manage, Communication::Website::Post::Category, university_id: @user.university_id
can :manage, Communication::Website::Menu, university_id: @user.university_id
can :manage, Communication::Website::Menu::Item, university_id: @user.university_id
can :manage, Communication::Website::Page, university_id: @user.university_id
Expand Down
3 changes: 2 additions & 1 deletion app/models/ability/website_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def initialize(user)
manage_blocks
can [:read, :analytics], Communication::Website, university_id: @user.university_id, id: managed_websites_ids
can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id, communication_website_id: managed_websites_ids
can :manage, Communication::Website::Category, university_id: @user.university_id, communication_website_id: managed_websites_ids
can :manage, Communication::Website::Agenda::Category, university_id: @user.university_id, communication_website_id: managed_websites_ids
can :manage, Communication::Website::Post::Category, university_id: @user.university_id, communication_website_id: managed_websites_ids
can [:read, :update, :reorder], Communication::Website::Menu, university_id: @user.university_id, communication_website_id: managed_websites_ids
can :manage, Communication::Website::Menu::Item, university_id: @user.university_id, website_id: managed_websites_ids
can :create, Communication::Website::Menu::Item, university_id: @user.university_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/block/component/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Communication::Block::Component::Category < Communication::Block::Componen

def category
return unless website
website.categories.find_by(id: data)
website.post_categories.find_by(id: data)
end

def dependencies
Expand Down
57 changes: 28 additions & 29 deletions app/models/communication/extranet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@
#
# Table name: communication_extranets
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# allow_experiences_modification :boolean default(TRUE)
# color :string
# cookies_policy :text
# css :text
# feature_alumni :boolean default(FALSE)
# feature_contacts :boolean default(FALSE)
# feature_jobs :boolean default(FALSE)
# feature_library :boolean default(FALSE)
# feature_posts :boolean default(FALSE)
# has_sso :boolean default(FALSE)
# home_sentence :text
# host :string
# name :string
# privacy_policy :text
# registration_contact :string
# sass :text
# sso_button_label :string
# sso_cert :text
# sso_mapping :jsonb
# sso_name_identifier_format :string
# sso_provider :integer default("saml")
# sso_target_url :string
# terms :text
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# color :string
# cookies_policy :text
# css :text
# feature_alumni :boolean default(FALSE)
# feature_contacts :boolean default(FALSE)
# feature_jobs :boolean default(FALSE)
# feature_library :boolean default(FALSE)
# feature_posts :boolean default(FALSE)
# has_sso :boolean default(FALSE)
# home_sentence :text
# host :string
# name :string
# privacy_policy :text
# registration_contact :string
# sass :text
# sso_button_label :string
# sso_cert :text
# sso_mapping :jsonb
# sso_name_identifier_format :string
# sso_provider :integer default("saml")
# sso_target_url :string
# terms :text
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
#
# Indexes
#
Expand Down
Loading
Loading