diff --git a/app/controllers/admin/communication/extranets/contacts_controller.rb b/app/controllers/admin/communication/extranets/contacts_controller.rb index a23385428b6cabd62926db64f9ebaa9969469a0b..abd295674c6452ee215f4af1e8ffd224e671c773 100644 --- a/app/controllers/admin/communication/extranets/contacts_controller.rb +++ b/app/controllers/admin/communication/extranets/contacts_controller.rb @@ -1,5 +1,6 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication::Extranets::ApplicationController def index + @persons = @extranet.connections.where(object_type: 'University::Person').page params[:page] breadcrumb add_breadcrumb Communication::Extranet.human_attribute_name(:feature_contacts) end diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb index ab3057119687b4bd4bbbb82dda400464c2523408..bb6fae817299cfbf83c76dd6a0ded2127051f917 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -45,6 +45,7 @@ class Communication::Extranet < ApplicationRecord # We don't include Sanitizable because too many complex attributes. We handle it below. include WithAbouts + include WithConnections include WithFeatures include WithLegal include WithStyle diff --git a/app/models/communication/extranet/connection.rb b/app/models/communication/extranet/connection.rb new file mode 100644 index 0000000000000000000000000000000000000000..30cc10e73c1a9daca0b247b86939f03094c171fc --- /dev/null +++ b/app/models/communication/extranet/connection.rb @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: communication_extranet_connections +# +# id :uuid not null, primary key +# object_type :string indexed => [object_id] +# created_at :datetime not null +# updated_at :datetime not null +# extranet_id :uuid not null, indexed +# object_id :uuid indexed => [object_type] +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_extranet_connections_on_extranet_id (extranet_id) +# index_communication_extranet_connections_on_object (object_type,object_id) +# index_communication_extranet_connections_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_14a6af7258 (university_id => universities.id) +# fk_rails_cfa28a3d00 (extranet_id => communication_extranets.id) +# +class Communication::Extranet::Connection < ApplicationRecord + belongs_to :university + belongs_to :extranet, class_name: 'Communication::Extranet' + belongs_to :object, polymorphic: true +end diff --git a/app/models/communication/extranet/with_connections.rb b/app/models/communication/extranet/with_connections.rb new file mode 100644 index 0000000000000000000000000000000000000000..b1b4d61d70377e5500af91c46135a6a1827b891f --- /dev/null +++ b/app/models/communication/extranet/with_connections.rb @@ -0,0 +1,8 @@ +module Communication::Extranet::WithConnections + extend ActiveSupport::Concern + + included do + has_many :connections + end + +end \ No newline at end of file diff --git a/app/views/admin/communication/extranets/contacts/index.html.erb b/app/views/admin/communication/extranets/contacts/index.html.erb index 1144f2d72cb936de2dc03703290dd78dd5b1d43d..77986c9ce6a2380528a6c928520c55b6b8b6398f 100644 --- a/app/views/admin/communication/extranets/contacts/index.html.erb +++ b/app/views/admin/communication/extranets/contacts/index.html.erb @@ -1,4 +1,23 @@ <% content_for :title, Communication::Extranet.human_attribute_name(:feature_contacts) %> <%= render 'admin/communication/extranets/sidebar' do %> + Search + <table class="<%= table_classes%>"> + <tbody> + <% @persons.each do |person| %> + <tr> + <td><%= link_to person, [:admin, person] %></td> + <td><%= 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 %></td> + </tr> + <% end %> + </tbody> + </table> + <%= paginate @persons, theme: 'bootstrap-5' %> <% end %> \ No newline at end of file diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 6d9ad440342c2a36675cde92a01c9e054bd60ebc..ff54b5e6a83fc11a8af22c8f95b12f7475ca2bb9 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -67,7 +67,12 @@ namespace :communication do end resources :extranets, controller: 'extranets' do resources :alumni, only: :index, controller: 'extranets/alumni' - resources :contacts, only: :index, controller: 'extranets/contacts' + resources :contacts, only: :index, controller: 'extranets/contacts' do + collection do + post :connect + post :disconnect + end + end resources :posts, only: :index, controller: 'extranets/posts' resources :assets, only: :index, controller: 'extranets/assets' resources :jobs, only: :index, controller: 'extranets/jobs' diff --git a/db/migrate/20230306134627_create_communication_extranet_connections.rb b/db/migrate/20230306134627_create_communication_extranet_connections.rb new file mode 100644 index 0000000000000000000000000000000000000000..f731d24654a3f03661530f3d635c576be9f740d0 --- /dev/null +++ b/db/migrate/20230306134627_create_communication_extranet_connections.rb @@ -0,0 +1,11 @@ +class CreateCommunicationExtranetConnections < ActiveRecord::Migration[7.0] + def change + create_table :communication_extranet_connections, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :extranet, null: false, foreign_key: {to_table: :communication_extranets}, type: :uuid + t.references :object, type: :uuid, polymorphic: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 83c445005f4226a7f9a714ec7a7070565fdece41..88f02d69126df9bb0d02d10cf9c8b35742f8336a 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[7.0].define(version: 2023_02_27_052540) do +ActiveRecord::Schema[7.0].define(version: 2023_03_06_134627) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -93,6 +93,18 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_27_052540) do t.index ["university_id"], name: "index_communication_blocks_on_university_id" end + create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "extranet_id", null: false + t.string "object_type" + t.uuid "object_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["extranet_id"], name: "index_communication_extranet_connections_on_extranet_id" + t.index ["object_type", "object_id"], name: "index_communication_extranet_connections_on_object" + t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" + end + create_table "communication_extranets", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false @@ -950,6 +962,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_27_052540) 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_extranet_connections", "communication_extranets", column: "extranet_id" + add_foreign_key "communication_extranet_connections", "universities" add_foreign_key "communication_extranets", "universities" add_foreign_key "communication_website_categories", "communication_website_categories", column: "original_id" add_foreign_key "communication_website_categories", "communication_website_categories", column: "parent_id" diff --git a/test/fixtures/create_communication_extranet_connections.yml b/test/fixtures/create_communication_extranet_connections.yml new file mode 100644 index 0000000000000000000000000000000000000000..3573c98adf71989ab399aeab19ea3d6b4304f568 --- /dev/null +++ b/test/fixtures/create_communication_extranet_connections.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + extranet: one + object: one + +two: + university: two + extranet: two + object: two diff --git a/test/models/create_communication_extranet_connection_test.rb b/test/models/create_communication_extranet_connection_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..ff00ca53a3164592e0b14a6459cd09e0acda9e85 --- /dev/null +++ b/test/models/create_communication_extranet_connection_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CreateCommunicationExtranetConnectionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end