diff --git a/app/controllers/admin/communication/blocks_controller.rb b/app/controllers/admin/communication/blocks_controller.rb index b0269fa9e76ddeaf4a7b383584ca60d96d6596d1..e1dda11bf1197cda071631d194170fbe432df08f 100644 --- a/app/controllers/admin/communication/blocks_controller.rb +++ b/app/controllers/admin/communication/blocks_controller.rb @@ -29,6 +29,7 @@ class Admin::Communication::BlocksController < Admin::Communication::Application if @block.save redirect_to [:edit, :admin, @block], notice: t('admin.successfully_created_html', model: @block.to_s) else + breadcrumb render :new, status: :unprocessable_entity end end @@ -38,6 +39,7 @@ class Admin::Communication::BlocksController < Admin::Communication::Application @block.about.save_and_sync redirect_to about_path, notice: t('admin.successfully_updated_html', model: @block.to_s) else + breadcrumb add_breadcrumb t('edit') render :edit, status: :unprocessable_entity end diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..0329293ca8109949ecd81eb37556e0bc94c3e524 --- /dev/null +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -0,0 +1,60 @@ +class Admin::Communication::ExtranetsController < Admin::Communication::ApplicationController + load_and_authorize_resource class: Communication::Extranet, + through: :current_university, + through_association: :communication_extranets + + def index + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + add_breadcrumb t('edit') + end + + def create + @extranet.university = current_university + if @extranet.save + redirect_to [:admin, @extranet], notice: t('admin.successfully_created_html', model: @extranet.to_s) + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @extranet.update(extranet_params) + redirect_to [:admin, @extranet], notice: t('admin.successfully_updated_html', model: @extranet.to_s) + else + breadcrumb + add_breadcrumb t('edit') + render :edit, status: :unprocessable_entity + end + end + + def destroy + @extranet.destroy + redirect_to admin_communication_websites_url, notice: t('admin.successfully_destroyed_html', model: @extranet.to_s) + end + + protected + + def breadcrumb + super + add_breadcrumb Communication::Extranet.model_name.human(count: 2), admin_communication_extranets_path + breadcrumb_for @extranet + end + + def extranet_params + params.require(:communication_extranet) + .permit(:name, :domain) + end +end diff --git a/app/models/administration/qualiopi/indicator.rb b/app/models/administration/qualiopi/indicator.rb index 300286f22c2b5b35c92568f4cde1b0c4b2bd6691..6e06a027333a734dbc6b5b039d18b1b21626969a 100644 --- a/app/models/administration/qualiopi/indicator.rb +++ b/app/models/administration/qualiopi/indicator.rb @@ -20,7 +20,7 @@ # # Foreign Keys # -# fk_rails_31f1a0a2c9 (criterion_id => administration_qualiopi_criterions.id) +# fk_rails_eed87f7acf (criterion_id => administration_qualiopi_criterions.id) # class Administration::Qualiopi::Indicator < ApplicationRecord include Sanitizable diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb new file mode 100644 index 0000000000000000000000000000000000000000..ee7404ad87d539ce1d29c71cc6dd5d0447311483 --- /dev/null +++ b/app/models/communication/extranet.rb @@ -0,0 +1,32 @@ +# == Schema Information +# +# Table name: communication_extranets +# +# id :uuid not null, primary key +# domain :string +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_extranets_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_c2268c7ebd (university_id => universities.id) +# +class Communication::Extranet < ApplicationRecord + belongs_to :university + + validates_presence_of :name, :domain + + def url + "https://#{domain}" + end + + def to_s + "#{name}" + end +end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index e4a3519a60314e5505a737e2e6ac1da72bc2d351..b72ab03ad9624fe10a4dd3cc7de6b2f2f10aa7cc 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -31,7 +31,7 @@ # # Foreign Keys # -# fk_rails_94b0abd85b (university_id => universities.id) +# fk_rails_bb6a496c08 (university_id => universities.id) # class Communication::Website < ApplicationRecord include WithAbouts diff --git a/app/models/communication/website/configs/base_url.rb b/app/models/communication/website/configs/base_url.rb index b016268e4d884e5188ec9dced44fc257064bc3b9..ffae459359e38b6ebbd72a6ba4deff313e44175a 100644 --- a/app/models/communication/website/configs/base_url.rb +++ b/app/models/communication/website/configs/base_url.rb @@ -31,7 +31,7 @@ # # Foreign Keys # -# fk_rails_94b0abd85b (university_id => universities.id) +# fk_rails_bb6a496c08 (university_id => universities.id) # class Communication::Website::Configs::BaseUrl < Communication::Website diff --git a/app/models/communication/website/configs/permalinks.rb b/app/models/communication/website/configs/permalinks.rb index b38d3d26f44ec3fce4b6f777ac6946900447d3ad..0f269522ac9088f6e58be42e405358bfc6719c50 100644 --- a/app/models/communication/website/configs/permalinks.rb +++ b/app/models/communication/website/configs/permalinks.rb @@ -31,7 +31,7 @@ # # Foreign Keys # -# fk_rails_94b0abd85b (university_id => universities.id) +# fk_rails_bb6a496c08 (university_id => universities.id) # class Communication::Website::Configs::Permalinks < Communication::Website diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 9857f76eb20a24c68eed429a9469dbf193956f5e..69cc14e8e4ae5b1e677a7f81b14dd8d10d358d88 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -39,7 +39,7 @@ # # Foreign Keys # -# fk_rails_6e16107511 (university_id => universities.id) +# fk_rails_08b351087c (university_id => universities.id) # fk_rails_ec1f16f607 (parent_id => education_programs.id) # class Education::Program < ApplicationRecord diff --git a/app/models/university/with_communication.rb b/app/models/university/with_communication.rb index 01ae9f54b8a413f1e7e9bf21eb913d9e8e9a6238..ccf765d5ec5650ef9e4e1b17c7f0806e43a16f26 100644 --- a/app/models/university/with_communication.rb +++ b/app/models/university/with_communication.rb @@ -2,6 +2,7 @@ module University::WithCommunication extend ActiveSupport::Concern included do + has_many :communication_extranets, class_name: 'Communication::Extranet', dependent: :destroy has_many :communication_websites, class_name: 'Communication::Website', dependent: :destroy has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy end diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..b4b40af7ca312246322e4e4941a10c45de99b959 --- /dev/null +++ b/app/views/admin/communication/extranets/_form.html.erb @@ -0,0 +1,18 @@ +<%= simple_form_for [:admin, extranet] do |f| %> + <div class="row"> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('metadata') %></h5> + </div> + <div class="card-body"> + <%= f.input :name %> + <%= f.input :domain %> + </div> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/communication/extranets/edit.html.erb b/app/views/admin/communication/extranets/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..150f6bddf9920578e92cb5e04588dbb2269b156b --- /dev/null +++ b/app/views/admin/communication/extranets/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @extranet %> + +<%= render 'form', extranet: @extranet %> diff --git a/app/views/admin/communication/extranets/index.html.erb b/app/views/admin/communication/extranets/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..94ba7170829cd03ec1157b54785b6d814fe17d3d --- /dev/null +++ b/app/views/admin/communication/extranets/index.html.erb @@ -0,0 +1,29 @@ +<% content_for :title, Communication::Extranet.model_name.human(count: 2) %> + +<table class="<%= table_classes %>"> + <thead> + <tr> + <th><%= Communication::Website.human_attribute_name('name') %></th> + <th><%= Communication::Website.human_attribute_name('url') %></th> + <th></th> + </tr> + </thead> + <tbody> + <% @extranets.each do |extranet| %> + <tr> + <td><%= link_to extranet, [:admin, extranet] %></td> + <td><%= link_to extranet.url, extranet.url, target: :_blank %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= edit_link extranet %> + <%= destroy_link extranet %> + </div> + </td> + </tr> + <% end %> + </tbody> +</table> + +<% content_for :action_bar_right do %> + <%= create_link Communication::Extranet %> +<% end %> diff --git a/app/views/admin/communication/extranets/new.html.erb b/app/views/admin/communication/extranets/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..31c0c33482607b006e20365069cb0950227f9292 --- /dev/null +++ b/app/views/admin/communication/extranets/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Communication::Extranet.model_name.human %> + +<%= render 'form', extranet: @extranet %> diff --git a/app/views/admin/communication/extranets/show.html.erb b/app/views/admin/communication/extranets/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c2ce9ea944e5c45dd612257f2c26632899a2d777 --- /dev/null +++ b/app/views/admin/communication/extranets/show.html.erb @@ -0,0 +1,10 @@ +<% content_for :title, @extranet %> + +<% content_for :title_right do %> + <%= link_to @extranet.url, @extranet.url, target: :_blank %> +<% end unless @extranet.url.blank? %> + +<% content_for :action_bar_right do %> + <%= edit_link @extranet %> + <%= destroy_link @extranet %> +<% end %> diff --git a/config/admin_navigation.rb b/config/admin_navigation.rb index b4d9e9996d22498f700a1a5a1fe681340f6b2f7b..9dee7c0151ec154c800ac8ab746c91717562b37b 100644 --- a/config/admin_navigation.rb +++ b/config/admin_navigation.rb @@ -30,10 +30,11 @@ SimpleNavigation::Configuration.run do |navigation| end if can?(:read, Communication::Website) - primary.item :communication, 'Communication', nil, { kind: :header } - primary.item :communication_websites, 'Sites Web', admin_communication_websites_path, { icon: 'sitemap' } if can?(:read, Communication::Website) - primary.item :communication, 'Lettres d\'information', nil, { icon: 'envelope' } - primary.item :communication, 'Alumni', nil, { icon: 'users' } + primary.item :communication, Communication.model_name.human, nil, { kind: :header } + primary.item :communication_websites, Communication::Website.model_name.human(count: 2), admin_communication_websites_path, { icon: 'sitemap' } if can?(:read, Communication::Website) + primary.item :communication_extranets, Communication::Extranet.model_name.human(count: 2), admin_communication_extranets_path, { icon: 'project-diagram' } + primary.item :communication_newsletters, 'Lettres d\'information', nil, { icon: 'envelope' } + primary.item :communication_alumni, 'Alumni', nil, { icon: 'users' } end if can?(:read, Administration::Qualiopi::Criterion) diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 177a39aabc04a8c18e1f5f5e3cafb79ea8cce5cd..b19b790886b1f13919c790db2e59c82308108cba 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -7,6 +7,9 @@ en: communication/block: one: Content block other: Content blocks + communication/extranet: + one: Extranet + other: Extranets communication/website: one: Website other: Websites @@ -36,6 +39,12 @@ en: other: Posts all: All posts attributes: + communication/extranet: + name: Name + domain: Domain + communication/block: + name: Name + template: Kind of block communication/website: about: About about_: Independent website (no specific subject) @@ -45,9 +54,6 @@ en: about_type: About name: Name url: URL - communication/block: - name: Name - template: Kind of block communication/website/category: children: Children categories description: Description (SEO) diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 2bce8c491defe541c730447a208462a63c50f950..12410839bca9dacb223b5969c689bc6b5331d81e 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -7,6 +7,9 @@ fr: communication/block: one: Bloc de contenu other: Blocs de contenu + communication/extranet: + one: Extranet + other: Extranets communication/website: one: Site Web other: Sites Web @@ -36,6 +39,12 @@ fr: other: Actualités all: Toutes les actualités attributes: + communication/block: + name: Nom + template: Type de bloc + communication/extranet: + name: Nom + domain: Domaine communication/website: about: Sujet du site about_: Site indépendant (aucun sujet) @@ -45,9 +54,6 @@ fr: about_type: Sujet du site name: Nom url: URL - communication/block: - name: Nom - template: Type de bloc communication/website/category: children: Catégories enfants description: Description (SEO) diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index a0af0b14eff9793948dd4147e4cc5ade146cb5c9..7b07d35b56ea04d6dd3a83c853adea8dca3a1a1b 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -56,4 +56,5 @@ namespace :communication do post :reorder end end + resources :extranets, controller: 'extranets' end diff --git a/db/migrate/20220302140425_create_communication_extranets.rb b/db/migrate/20220302140425_create_communication_extranets.rb new file mode 100644 index 0000000000000000000000000000000000000000..c870c65b5b7822bc266ab487fc3f092439728b43 --- /dev/null +++ b/db/migrate/20220302140425_create_communication_extranets.rb @@ -0,0 +1,11 @@ +class CreateCommunicationExtranets < ActiveRecord::Migration[6.1] + def change + create_table :communication_extranets, id: :uuid do |t| + t.string :name + t.references :university, null: false, foreign_key: true, type: :uuid + t.string :domain + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 247ea75c5b44b87a80aa6a3583097dd446018630..8afbdb0f0c4f2d46a1b0e1d27d31d23c54dd7a71 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_02_27_163249) do +ActiveRecord::Schema.define(version: 2022_03_02_140425) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -93,6 +93,15 @@ ActiveRecord::Schema.define(version: 2022_02_27_163249) do t.index ["university_id"], name: "index_communication_blocks_on_university_id" end + create_table "communication_extranets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name" + t.uuid "university_id", null: false + t.string "domain" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["university_id"], name: "index_communication_extranets_on_university_id" + end + create_table "communication_website_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false @@ -660,6 +669,7 @@ ActiveRecord::Schema.define(version: 2022_02_27_163249) do add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id" add_foreign_key "communication_blocks", "universities" + add_foreign_key "communication_extranets", "universities" add_foreign_key "communication_website_categories", "communication_website_categories", column: "parent_id" add_foreign_key "communication_website_categories", "communication_websites" add_foreign_key "communication_website_categories", "education_programs", column: "program_id" diff --git a/test/controllers/communication/extranets_controller_test.rb b/test/controllers/communication/extranets_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..3e3c20c8bf074e5f67ab68f4a86af24ca9b61f3b --- /dev/null +++ b/test/controllers/communication/extranets_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class Communication::ExtranetsControllerTest < ActionDispatch::IntegrationTest + setup do + @communication_extranet = communication_extranets(:one) + end + + test "should get index" do + get communication_extranets_url + assert_response :success + end + + test "should get new" do + get new_communication_extranet_url + assert_response :success + end + + test "should create communication_extranet" do + assert_difference('Communication::Extranet.count') do + post communication_extranets_url, params: { communication_extranet: { name: @communication_extranet.name, university_id: @communication_extranet.university_id, url: @communication_extranet.url } } + end + + assert_redirected_to communication_extranet_url(Communication::Extranet.last) + end + + test "should show communication_extranet" do + get communication_extranet_url(@communication_extranet) + assert_response :success + end + + test "should get edit" do + get edit_communication_extranet_url(@communication_extranet) + assert_response :success + end + + test "should update communication_extranet" do + patch communication_extranet_url(@communication_extranet), params: { communication_extranet: { name: @communication_extranet.name, university_id: @communication_extranet.university_id, url: @communication_extranet.url } } + assert_redirected_to communication_extranet_url(@communication_extranet) + end + + test "should destroy communication_extranet" do + assert_difference('Communication::Extranet.count', -1) do + delete communication_extranet_url(@communication_extranet) + end + + assert_redirected_to communication_extranets_url + end +end diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml new file mode 100644 index 0000000000000000000000000000000000000000..bc8e28dc28879f1b8d9154076ecc63db7e04380b --- /dev/null +++ b/test/fixtures/communication/extranets.yml @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: communication_extranets +# +# id :uuid not null, primary key +# domain :string +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_extranets_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_c2268c7ebd (university_id => universities.id) +# + +one: + name: MyString + university: one + url: MyString + +two: + name: MyString + university: two + url: MyString diff --git a/test/fixtures/communication/websites.yml b/test/fixtures/communication/websites.yml index d6718e99b8c79f6967a82171b5515d883b190d85..33965b28a8dd69b5dbcc9a665aa1e1a116fd2b17 100644 --- a/test/fixtures/communication/websites.yml +++ b/test/fixtures/communication/websites.yml @@ -31,7 +31,7 @@ # # Foreign Keys # -# fk_rails_94b0abd85b (university_id => universities.id) +# fk_rails_bb6a496c08 (university_id => universities.id) # website_with_github: university: default_university diff --git a/test/models/communication/extranet_test.rb b/test/models/communication/extranet_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..6230afc9a5003701d77724c0def02121a97d160e --- /dev/null +++ b/test/models/communication/extranet_test.rb @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: communication_extranets +# +# id :uuid not null, primary key +# domain :string +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_extranets_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_c2268c7ebd (university_id => universities.id) +# +require "test_helper" + +class Communication::ExtranetTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/communication/extranets_test.rb b/test/system/communication/extranets_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..ae1fdbd6aff317aead355956fdb57bc3706636ed --- /dev/null +++ b/test/system/communication/extranets_test.rb @@ -0,0 +1,47 @@ +require "application_system_test_case" + +class Communication::ExtranetsTest < ApplicationSystemTestCase + setup do + @communication_extranet = communication_extranets(:one) + end + + test "visiting the index" do + visit communication_extranets_url + assert_selector "h1", text: "Communication/Extranets" + end + + test "creating a Extranet" do + visit communication_extranets_url + click_on "New Communication/Extranet" + + fill_in "Name", with: @communication_extranet.name + fill_in "University", with: @communication_extranet.university_id + fill_in "Url", with: @communication_extranet.url + click_on "Create Extranet" + + assert_text "Extranet was successfully created" + click_on "Back" + end + + test "updating a Extranet" do + visit communication_extranets_url + click_on "Edit", match: :first + + fill_in "Name", with: @communication_extranet.name + fill_in "University", with: @communication_extranet.university_id + fill_in "Url", with: @communication_extranet.url + click_on "Update Extranet" + + assert_text "Extranet was successfully updated" + click_on "Back" + end + + test "destroying a Extranet" do + visit communication_extranets_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Extranet was successfully destroyed" + end +end