diff --git a/app/controllers/admin/communication/extranets/contacts_controller.rb b/app/controllers/admin/communication/extranets/contacts_controller.rb index e23b7f2c72acd52ac1c2e7ea2a2ab0d80f485941..a20240f473c1aef650c53d2266befb57ac9524bc 100644 --- a/app/controllers/admin/communication/extranets/contacts_controller.rb +++ b/app/controllers/admin/communication/extranets/contacts_controller.rb @@ -40,6 +40,15 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication redirect_back(fallback_location: admin_communication_extranet_contacts_path(@extranet)) end + def toggle + load_object + # connect / disconnect + @connection = params[:connection] + @connection == 'connect' ? @extranet.connect(@object) + : @extranet.disconnect(@object) + redirect_back(fallback_location: admin_communication_extranet_contacts_path(@extranet)) + end + protected diff --git a/app/views/admin/communication/extranets/contacts/_toggle.html.erb b/app/views/admin/communication/extranets/contacts/_toggle.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0f6c5b52274e6634a8b5df9ad2a7dd10384ece01 --- /dev/null +++ b/app/views/admin/communication/extranets/contacts/_toggle.html.erb @@ -0,0 +1,20 @@ +<% +connected = @extranet.connected?(about) +path = toggle_admin_communication_extranet_contacts_path( + extranet_id: @extranet.id, + objectId: about.id, + objectType: about.class, + connection: connected ? 'disconnect' : 'connect' +) +%> +<%= form_tag path, remote: true do %> + <input class="form-check-input" + type="checkbox" + id="checkbox-<%= about.id %>" + onchange="this.form.submit()" + <% if connected %> checked<% end %>> + <label class="form-check-label" + for="checkbox-<%= about.id %>"> + <%= Communication::Extranet::Connection.human_attribute_name 'connected' %> + </label> +<% end %> diff --git a/app/views/admin/communication/extranets/contacts/index.html.erb b/app/views/admin/communication/extranets/contacts/index.html.erb index d737b23932ba03a2c273dc7128da4c66f7b22592..117a74808c55b86f7c9a8ad95c8563180425fcf8 100644 --- a/app/views/admin/communication/extranets/contacts/index.html.erb +++ b/app/views/admin/communication/extranets/contacts/index.html.erb @@ -12,27 +12,7 @@ <tr> <td><%= link_to person, [:admin, person] %></td> <td><%= person.email %></td> - <td> - <% if @extranet.connected?(person) %> - <%= link_to 'Déconnecter', - disconnect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: person.id, - objectType: person.class - ), - class: button_classes_danger, - method: :post %> - <% else %> - <%= link_to 'Connecter', - connect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: person.id, - objectType: person.class - ), - class: button_classes, - method: :post %> - <% end %> - </td> + <td><%= render 'toggle', about: person %></td> </tr> <% end %> </tbody> @@ -50,27 +30,7 @@ <% @organizations.each do |organization| %> <tr> <td><%= link_to organization, [:admin, organization] %></td> - <td> - <% if @extranet.connected?(organization) %> - <%= link_to 'Déconnecter', - disconnect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: organization.id, - objectType: organization.class - ), - class: button_classes_danger, - method: :post %> - <% else %> - <%= link_to 'Connecter', - connect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: organization.id, - objectType: organization.class - ), - class: button_classes, - method: :post %> - <% end %> - </td> + <td><%= render 'toggle', about: organization %></td> </tr> <% end %> </tbody> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index a30f9cc6530a7b98cf326b13ce61532888c6f700..62bf1cfef31779177b7f5145f6e2ac2f1ebec762 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -90,6 +90,8 @@ en: sso_name_identifier_format: Name Identifier Format sso_target_url: Target URL terms: Terms of service + communication/extranet/connection: + connected: Connected communication/extranet/document: name: Name published: Published? diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 03479f4a8788d7e0df289e035561c722200470bb..84d8a6c0d2fd9a31f28424b27f6e34d960dd24d2 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -90,6 +90,8 @@ fr: sso_name_identifier_format: Name Identifier Format sso_target_url: URL cible terms: Conditions d'utilisation + communication/extranet/connection: + connected: Connecté communication/extranet/document: name: Nom published: Publié ? diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index f6b9c18591232102c1ce5703f9bdae0986d1df21..c5ddb466f4dbc1e3564ebde5ed0fc659dced1a4e 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -70,6 +70,7 @@ namespace :communication do resources :alumni, only: :index, controller: 'extranets/alumni' resources :contacts, only: :index, controller: 'extranets/contacts' do collection do + post :toggle post :connect post :disconnect end diff --git a/db/schema.rb b/db/schema.rb index 4f551719bca8e6c85a315cc08d4f2505e17f2039..3fccca92202f4d5023daf89b57fc72f79ab2193f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -202,7 +202,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_13_144352) do t.text "home_sentence" t.text "sass" t.text "css" - t.boolean "allow_experiences_modification", default: true t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end @@ -241,6 +240,18 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_13_144352) do t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end + create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.string "object_type", null: false + t.uuid "object_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["object_type", "object_id"], name: "index_communication_website_connections_on_object" + t.index ["university_id"], name: "index_communication_website_connections_on_university_id" + t.index ["website_id"], name: "index_communication_website_connections_on_website_id" + end + create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false @@ -429,7 +440,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_13_144352) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -1081,6 +1092,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_13_144352) do add_foreign_key "communication_website_categories", "education_programs", column: "program_id" add_foreign_key "communication_website_categories", "languages" add_foreign_key "communication_website_categories", "universities" + add_foreign_key "communication_website_connections", "communication_websites", column: "website_id" + add_foreign_key "communication_website_connections", "universities" add_foreign_key "communication_website_git_files", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "communication_website_imported_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "universities"