diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index f7ddbfa470f82c9134c93fdd0699ea4304097988..fc0e9fe7fcb9fcf84c2ef31b7134afcd33c0b142 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -11,7 +11,6 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web end def new - @page.website = @website breadcrumb end @@ -22,6 +21,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def create @page.university = current_university + @page.website = @website if @page.save redirect_to admin_communication_website_page_path(@page), notice: "Page was successfully created." else diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..d6a49f8ead9fac4f08109ecdc8b6d8ad35e33bad --- /dev/null +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -0,0 +1,60 @@ +class Admin::Communication::Website::PostsController < Admin::Communication::Website::ApplicationController + load_and_authorize_resource class: Communication::Website::Post + + def index + @posts = @website.posts.ordered + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + add_breadcrumb t('edit') + end + + def create + @post.university = current_university + @post.website = @website + if @post.save + redirect_to admin_communication_website_post_path(@post), notice: "Post was successfully created." + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @post.update(post_params) + redirect_to admin_communication_website_post_path(@post), notice: "Post was successfully updated." + else + breadcrumb + render :edit, status: :unprocessable_entity + end + end + + def destroy + @communication_website_post.destroy + redirect_to admin_communication_website_posts_url, notice: "Post was successfully destroyed." + end + + protected + + def breadcrumb + super + add_breadcrumb Communication::Website::Post.model_name.human(count: 2), + admin_communication_website_posts_path + breadcrumb_for @post + end + + def post_params + params.require(:communication_website_post) + .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at) + end +end diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 81ada3583a6a17a1815561e4720f1db53ebf6fc9..2af62df5c2d4b1e848b868141bae6541e478d107 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -21,6 +21,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati end @imported_website = @website.imported_website @imported_pages = @imported_website.pages + @imported_posts = @imported_website.posts breadcrumb add_breadcrumb Communication::Website::Imported::Website.model_name.human end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 77a6fc3b39f549115d6868b42cd1588889c94cb0..dc939770197e5d782eb77a4b383dfde968f0944e 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -26,6 +26,7 @@ class Communication::Website < ApplicationRecord belongs_to :university belongs_to :about, polymorphic: true, optional: true has_many :pages, foreign_key: :communication_website_id + has_many :posts, foreign_key: :communication_website_id has_one :imported_website, class_name: 'Communication::Website::Imported::Website', dependent: :destroy diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index 28bb55c227fd73fc4c641f98197914fee2ce8d52..8400f0fb78f7515c48aa1398450b8e872dbaea75 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -34,7 +34,7 @@ class Communication::Website::Imported::Page < ApplicationRecord class_name: 'Communication::Website::Page', optional: true - before_validation :sync_page + before_validation :sync def to_s "#{title}" @@ -42,7 +42,7 @@ class Communication::Website::Imported::Page < ApplicationRecord protected - def sync_page + def sync if page.nil? self.page = Communication::Website::Page.new university: university, website: website.website, # Real website, not imported website @@ -50,8 +50,10 @@ class Communication::Website::Imported::Page < ApplicationRecord self.page.title = "TMP" self.page.save end - # TODO only if not modified + # TODO only if not modified since import page.title = title.to_s + # TODO add that + # page.description = description.to_s page.text = content.to_s page.save end diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb new file mode 100644 index 0000000000000000000000000000000000000000..ff80c8b51e5185a7556e1b7fbd3db3ab4e0eca74 --- /dev/null +++ b/app/models/communication/website/imported/post.rb @@ -0,0 +1,62 @@ +# == Schema Information +# +# Table name: communication_website_imported_posts +# +# id :uuid not null, primary key +# content :text +# description :text +# identifier :string +# path :text +# published_at :datetime +# status :integer default(0) +# title :string +# url :text +# created_at :datetime not null +# updated_at :datetime not null +# post_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_posts_on_post_id (post_id) +# index_communication_website_imported_posts_on_university_id (university_id) +# index_communication_website_imported_posts_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (post_id => communication_website_posts.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +class Communication::Website::Imported::Post < ApplicationRecord + belongs_to :university + belongs_to :website, + class_name: 'Communication::Website::Imported::Website' + belongs_to :post, + class_name: 'Communication::Website::Post', + optional: true + + before_validation :sync + + def to_s + "#{title}" + end + + protected + + def sync + if post.nil? + self.post = Communication::Website::Post.new university: university, + website: website.website # Real website, not imported website + self.post.title = "TMP" # No title yet + self.post.save + end + # TODO only if not modified since import + post.title = title.to_s + post.description = description.to_s + post.text = content.to_s + post.published_at = published_at if published_at + post.save + end +end diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index e4d908c3510656139cbeef1cad214f6165e0831c..ecc802bf2ae3a3dea89d7e838629b9ab5576545c 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -21,24 +21,51 @@ # class Communication::Website::Imported::Website < ApplicationRecord belongs_to :university - belongs_to :website, class_name: 'Communication::Website' - has_many :pages, class_name: 'Communication::Website::Imported::Page' + belongs_to :website, + class_name: 'Communication::Website' + has_many :pages, + class_name: 'Communication::Website::Imported::Page' + has_many :posts, + class_name: 'Communication::Website::Imported::Post' def run! - load("#{website.domain_url}/wp-json/wp/v2/pages").each do |hash| + sync_posts + sync_pages + end + + protected + + def sync_pages + # TODO paginate + load("#{website.domain_url}/wp-json/wp/v2/pages?per_page=100").each do |hash| url = hash['link'] path = URI(url).path - title = hash['title']['rendered'] - content = hash['content']['rendered'] + # TODO id page = pages.where(university: university, path: path).first_or_create page.url = url - page.title = title - page.content = content + page.title = hash['title']['rendered'] + page.content = hash['content']['rendered'] page.save end end - protected + def sync_posts + # TODO paginate + # Communication::Website::Imported::Post.destroy_all + # Communication::Website::Post.destroy_all + load("#{website.domain_url}/wp-json/wp/v2/posts?per_page=100").each do |hash| + identifier = hash['id'] + post = posts.where(university: university, identifier: identifier).first_or_create + post.url = hash['link'] + post.path = URI(post.url).path + post.title = hash['title']['rendered'] + # TODO excerpt + post.description = hash['content']['excerpt'] + post.content = hash['content']['rendered'] + post.published_at = hash['date'] + post.save + end + end def load(url) uri = URI(url) diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 931f3072822a8ca01eaa64de2d5671aa52076d08..3fa0fe5013c259dd2dbb096c66c4c5969a814f78 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -49,7 +49,7 @@ class Communication::Website::Page < ApplicationRecord after_save :publish_to_github scope :ordered, -> { order(:path) } - scope :recent, -> { order(updated_at: :desc).limit(10) } + scope :recent, -> { order(updated_at: :desc).limit(5) } def content @content ||= github.read_file_at "_pages/#{id}.html" diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb new file mode 100644 index 0000000000000000000000000000000000000000..b453f2082b4759c55da244bc42253c729f862daa --- /dev/null +++ b/app/models/communication/website/post.rb @@ -0,0 +1,42 @@ +# == Schema Information +# +# Table name: communication_website_posts +# +# id :uuid not null, primary key +# description :text +# published :boolean default(FALSE) +# published_at :datetime +# text :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# communication_website_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_communication_website_posts_on_communication_website_id (communication_website_id) +# index_communication_website_posts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (communication_website_id => communication_websites.id) +# fk_rails_... (university_id => universities.id) +# +class Communication::Website::Post < ApplicationRecord + belongs_to :university + belongs_to :website, + foreign_key: :communication_website_id + has_one :imported_post, + class_name: 'Communication::Website::Imported::Post', + foreign_key: :post_id + + scope :ordered, -> { order(published_at: :desc, created_at: :desc) } + scope :recent, -> { order(published_at: :desc).limit(5) } + + validates :title, presence: true + + def to_s + "#{title}" + end +end diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index da8707a0ebb96ccc9414804bab27be372d011b1d..15edf3743eb5bd8e6375f308aa683ae97628bcb0 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -21,7 +21,6 @@ <%= f.input :slug %> <%= f.input :published %> <%= f.association :parent, collection: page.website.pages.where.not(id: page) %> - <%= f.association :website, include_blank: false %> </div> </div> </div> diff --git a/app/views/admin/communication/website/pages/_list.html.erb b/app/views/admin/communication/website/pages/_list.html.erb index 1679b84ed2345bf2a102ef7179ca8d5a02c3505d..dba9d2fd4f51a2b50e5ee877f75ed98e2b43f6eb 100644 --- a/app/views/admin/communication/website/pages/_list.html.erb +++ b/app/views/admin/communication/website/pages/_list.html.erb @@ -1,17 +1,17 @@ <table class="table"> <thead> <tr> - <th><%= Communication::Website::Page.human_attribute_name('title') %></th> + <th class="ps-0"><%= Communication::Website::Page.human_attribute_name('title') %></th> <th><%= Communication::Website::Page.human_attribute_name('path') %></th> - <th></th> + <th width="150"></th> </tr> </thead> <tbody> <% pages.each do |page| %> <tr> - <td><%= link_to page, admin_communication_website_page_path(website_id: page.website.id, id: page.id) %></td> + <td class="ps-0"><%= link_to page, admin_communication_website_page_path(website_id: page.website.id, id: page.id) %></td> <td><%= page.path %></td> - <td class="text-end"> + <td class="text-end pe-0"> <%= link_to t('edit'), edit_admin_communication_website_page_path(website_id: page.website.id, id: page.id), class: button_classes %> diff --git a/app/views/admin/communication/website/pages/new.html.erb b/app/views/admin/communication/website/pages/new.html.erb index 4817c4565fdba6c1fb85315820e461ccf4cacf38..7f249a1c4448fddeafc77223d502d9679877259a 100644 --- a/app/views/admin/communication/website/pages/new.html.erb +++ b/app/views/admin/communication/website/pages/new.html.erb @@ -1,3 +1,3 @@ -<% content_for :title, Research::Journal::Article.model_name.human %> +<% content_for :title, Communication::Website::Page.model_name.human %> <%= render 'form', page: @page %> diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index 926d0e646a716ec81fbd7c54482cd165105e20db..b3f80e9321136c55491bf8d7881f24095cce2aef 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -46,5 +46,5 @@ </div> <% content_for :buttons do %> - <%= link_to 'Modifier', edit_admin_communication_website_page_path(@page.id), class: button_classes %> + <%= edit_link @page %> <% end %> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0201b4e0825c993c4bfce611e10c28850773e3b5 --- /dev/null +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -0,0 +1,30 @@ +<%= simple_form_for [:admin, post] do |f| %> + <div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0">Content</h5> + </div> + <div class="card-body"> + <%= f.input :title %> + <%= f.input :description %> + <%= f.input :text, input_html: { rows: 20 } %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0">Metadata</h5> + </div> + <div class="card-body"> + <%= f.input :published %> + <%= f.input :published_at, html5: true %> + </div> + </div> + </div> + </div> + <% content_for :buttons do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/communication/website/posts/_list.html.erb b/app/views/admin/communication/website/posts/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..6dae7e87f343a108c46aab30a3b1db9e2725fae0 --- /dev/null +++ b/app/views/admin/communication/website/posts/_list.html.erb @@ -0,0 +1,27 @@ +<table class="table"> + <thead> + <tr> + <th class="ps-0"><%= Communication::Website::Post.human_attribute_name('title') %></th> + <th><%= Communication::Website::Post.human_attribute_name('published_at') %></th> + <th width="150"></th> + </tr> + </thead> + <tbody> + <% posts.each do |post| %> + <tr> + <td class="ps-0"><%= link_to post, admin_communication_website_post_path(website_id: post.website.id, id: post.id) %></td> + <td><%= l post.published_at, format: :long if post.published_at %></td> + <td class="text-end pe-0"> + <%= link_to t('edit'), + edit_admin_communication_website_post_path(website_id: post.website.id, id: post.id), + class: button_classes %> + <%= link_to t('delete'), + admin_communication_website_post_path(website_id: post.website.id, id: post.id), + method: :delete, + data: { confirm: t('please-confirm') }, + class: button_classes_danger %> + </td> + </tr> + <% end %> + </tbody> +</table> diff --git a/app/views/admin/communication/website/posts/edit.html.erb b/app/views/admin/communication/website/posts/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..6a9e1ccb8f225e98346ec3fcd28816463eebd780 --- /dev/null +++ b/app/views/admin/communication/website/posts/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @post %> + +<%= render 'form', post: @post %> diff --git a/app/views/admin/communication/website/posts/index.html.erb b/app/views/admin/communication/website/posts/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..395eec23b8745384f8fc77806f78f55a4afcfd69 --- /dev/null +++ b/app/views/admin/communication/website/posts/index.html.erb @@ -0,0 +1,7 @@ +<% content_for :title, Communication::Website::Post.model_name.human(count: 2) %> + +<%= render 'admin/communication/website/posts/list', posts: @posts %> + +<% content_for :buttons do %> + <%= create_link Communication::Website::Post %> +<% end %> diff --git a/app/views/admin/communication/website/posts/new.html.erb b/app/views/admin/communication/website/posts/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e004e29efa3947da1c4e6ee1df75a91f9f054c2f --- /dev/null +++ b/app/views/admin/communication/website/posts/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Communication::Website::Post.model_name.human %> + +<%= render 'form', post: @post %> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c4c1240332515975b46d01ec27dd01d0db63f119 --- /dev/null +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -0,0 +1,45 @@ +<% content_for :title, @post %> + +<div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0">Content</h5> + </div> + <div class="card-body"> + <p> + <strong>Description</strong> + <%= @post.description %> + </p> + + <p> + <strong>Text</strong> + </p> + <%= raw @post.text %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0">Metadata</h5> + </div> + <div class="card-body"> + <p> + <strong>Published</strong> + <%= @post.published %> + </p> + <% if @post.imported_post %> + <p> + <strong>Imported from</strong> + <a href="<%= @post.imported_post.url %>" target="_blank"><%= @post.imported_post.url %></a> + </p> + <% end %> + </div> + </div> + </div> +</div> + +<% content_for :buttons do %> + <%= edit_link @post %> +<% end %> diff --git a/app/views/admin/communication/websites/import.html.erb b/app/views/admin/communication/websites/import.html.erb index 3be008d690ff3b273ecc0668a5156e3f31d25197..bdc56cc6592db600fff2aa451df5855e2a5abb4e 100644 --- a/app/views/admin/communication/websites/import.html.erb +++ b/app/views/admin/communication/websites/import.html.erb @@ -6,20 +6,37 @@ class: button_classes %> <% end %> +<h2><%= @imported_posts.count %> posts</h2> <table class="table"> <thead> <tr> - <th><%= Communication::Website::Imported::Page.human_attribute_name('title') %></th> - <th><%= Communication::Website::Imported::Page.human_attribute_name('original_page') %></th> - <th><%= Communication::Website::Imported::Page.human_attribute_name('imported_page') %></th> + <th class="ps-0"><%= Communication::Website::Imported::Post.human_attribute_name('title') %></th> + <th><%= Communication::Website::Imported::Post.human_attribute_name('original') %></th> + </tr> + </thead> + <tbody> + <% @imported_posts.each do |post| %> + <tr> + <td class="ps-0"><%= link_to post, admin_communication_website_post_path(website_id: post.post.website.id, id: post.post.id) %></td> + <td class="small"><%= link_to post.path, post.url, target: :_blank %></td> + </tr> + <% end %> + </tbody> +</table> + +<h2 class="mt-5"><%= @imported_pages.count %> pages</h2> +<table class="table"> + <thead> + <tr> + <th class="ps-0"><%= Communication::Website::Imported::Page.human_attribute_name('title') %></th> + <th><%= Communication::Website::Imported::Page.human_attribute_name('original') %></th> </tr> </thead> <tbody> <% @imported_pages.each do |page| %> <tr> - <td><%= page %></td> - <td><%= link_to page.path, page.url, target: :_blank %></td> - <td><%= link_to 'Imported page', admin_communication_website_page_path(website_id: page.page.website.id, id: page.page.id) %></td> + <td><%= link_to page, admin_communication_website_page_path(website_id: page.page.website.id, id: page.page.id) %></td> + <td class="small"><%= link_to page.path, page.url, target: :_blank %></td> </tr> <% end %> </tbody> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 7388fad413eab0eae30685a2cd5a910ddef0b115..c80c33b936d5f9579047fce5f6ba14091e73bb05 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -9,15 +9,21 @@ <%= link_to @website.about, [:admin, @website.about] unless @website.about.nil? %> </p> +<h2 class="mt-5"><%= Communication::Website::Post.model_name.human(count: 2) %></h2> +<%= link_to t('create'), + new_admin_communication_website_post_path(website_id: @website), + class: button_classes('me-3') %> +<%= link_to t('activerecord.models.communication/website/post.all'), + admin_communication_website_posts_path(website_id: @website) %> +<%= render 'admin/communication/website/posts/list', posts: @website.posts.recent %> + <h2 class="mt-5"><%= Communication::Website::Page.model_name.human(count: 2) %></h2> <%= link_to t('create'), new_admin_communication_website_page_path(website_id: @website), class: button_classes('me-3') %> - -<%= link_to 'Toutes les pages', +<%= link_to t('activerecord.models.communication/website/page.all'), admin_communication_website_pages_path(website_id: @website) %> - <%= render 'admin/communication/website/pages/list', pages: @website.pages.recent %> <% content_for :buttons do %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 91b44b6c05c0e127bc1053e6eeb199b5a129903a..9623e92378d6110cb217066926dc2302927c515b 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -17,6 +17,11 @@ en: communication/website/page: one: Page other: Pages + all: All pages + communication/website/post: + one: Post + other: Posts + all: All posts communication/website/imported/website: one: Imported website other: Imported websites diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 2c2bd16424a7e3f65d966f36d39d432cc25c70fa..f8c2eb904bbdb3208b9bb69eab8d93fbf4c6e258 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -17,6 +17,11 @@ fr: communication/website/page: one: Page other: Pages + all: Toutes les pages + communication/website/post: + one: Actualité + other: Actualités + all: Toutes les actualités communication/website/imported/website: one: Site importé other: Sites importés diff --git a/config/routes.rb b/config/routes.rb index 540db86ee20d0bdd567df9c6a1f6fa5070fb73d8..a2c11953dd159267771f6958138f2848d1b932eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,11 @@ Rails.application.routes.draw do - resources :languages devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions' } + resources :languages + namespace :admin do resources :users draw 'education' diff --git a/config/routes/communication.rb b/config/routes/communication.rb index 038649e631b86d0420ae8fd777c6489ecf423a60..edff8b75eb1570af6416b7d74b990163c3e93617 100644 --- a/config/routes/communication.rb +++ b/config/routes/communication.rb @@ -1,9 +1,10 @@ namespace :communication do resources :websites do - resources :pages, controller: 'website/pages' member do get :import post :import end + resources :pages, controller: 'website/pages' + resources :posts, controller: 'website/posts' end end diff --git a/db/migrate/20211008120417_create_communication_website_posts.rb b/db/migrate/20211008120417_create_communication_website_posts.rb new file mode 100644 index 0000000000000000000000000000000000000000..224dac398b7afab899f026fc923492824cf1fcf2 --- /dev/null +++ b/db/migrate/20211008120417_create_communication_website_posts.rb @@ -0,0 +1,15 @@ +class CreateCommunicationWebsitePosts < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_posts, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :communication_website, null: false, foreign_key: true, type: :uuid + t.string :title + t.text :description + t.text :text + t.boolean :published, default: false + t.datetime :published_at + + t.timestamps + end + end +end diff --git a/db/migrate/20211008124637_create_communication_website_imported_posts.rb b/db/migrate/20211008124637_create_communication_website_imported_posts.rb new file mode 100644 index 0000000000000000000000000000000000000000..2c8a278e7302bfa05329176a5cf98fa2a15d8931 --- /dev/null +++ b/db/migrate/20211008124637_create_communication_website_imported_posts.rb @@ -0,0 +1,19 @@ +class CreateCommunicationWebsiteImportedPosts < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_imported_posts, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :website, null: false, foreign_key: {to_table: :communication_website_imported_websites}, type: :uuid + t.references :post, null: false, foreign_key: {to_table: :communication_website_posts}, type: :uuid + t.integer :status, default: 0 + t.string :title + t.text :description + t.text :content + t.text :path + t.text :url + t.datetime :published_at + t.string :identifier + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ef44af74f7500f6c9f2cd55f56ce31a3ea83f5d5..752a392f4ce362e2ee6cf131188bedba69aa25e5 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: 2021_10_08_090117) do +ActiveRecord::Schema.define(version: 2021_10_08_124637) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -82,6 +82,25 @@ ActiveRecord::Schema.define(version: 2021_10_08_090117) do t.index ["website_id"], name: "index_communication_website_imported_pages_on_website_id" end + create_table "communication_website_imported_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.uuid "post_id", null: false + t.integer "status", default: 0 + t.string "title" + t.text "description" + t.text "content" + t.text "path" + t.text "url" + t.datetime "published_at" + t.string "identifier" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["post_id"], name: "index_communication_website_imported_posts_on_post_id" + t.index ["university_id"], name: "index_communication_website_imported_posts_on_university_id" + t.index ["website_id"], name: "index_communication_website_imported_posts_on_website_id" + end + create_table "communication_website_imported_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false @@ -113,6 +132,20 @@ ActiveRecord::Schema.define(version: 2021_10_08_090117) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end + create_table "communication_website_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "communication_website_id", null: false + t.string "title" + t.text "description" + t.text "text" + t.boolean "published", default: false + t.datetime "published_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id" + t.index ["university_id"], name: "index_communication_website_posts_on_university_id" + end + create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" @@ -283,11 +316,16 @@ ActiveRecord::Schema.define(version: 2021_10_08_090117) do add_foreign_key "communication_website_imported_pages", "communication_website_imported_websites", column: "website_id" add_foreign_key "communication_website_imported_pages", "communication_website_pages", column: "page_id" add_foreign_key "communication_website_imported_pages", "universities" + add_foreign_key "communication_website_imported_posts", "communication_website_imported_websites", column: "website_id" + add_foreign_key "communication_website_imported_posts", "communication_website_posts", column: "post_id" + add_foreign_key "communication_website_imported_posts", "universities" add_foreign_key "communication_website_imported_websites", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_websites", "universities" add_foreign_key "communication_website_pages", "communication_website_pages", column: "parent_id" add_foreign_key "communication_website_pages", "communication_websites" add_foreign_key "communication_website_pages", "universities" + add_foreign_key "communication_website_posts", "communication_websites" + add_foreign_key "communication_website_posts", "universities" add_foreign_key "communication_websites", "universities" add_foreign_key "education_programs", "universities" add_foreign_key "research_journal_articles", "research_journal_volumes" diff --git a/docs/websites/readme.md b/docs/websites/readme.md index e60cc76ce2cd04dca45306ddbd18834fdd48c865..4c78d105b13b7fe3903ce3ebe39cfa5b83670a14 100644 --- a/docs/websites/readme.md +++ b/docs/websites/readme.md @@ -11,19 +11,23 @@ Attributes: Attributes: - university:references +- website:references - title:string - description:text -- data:json +- text:text +- published:boolean - published_at:datetime ## websites/Page Attributes: - university:references +- website:references - title:string - description:text -- data:json +- text:text - parent:references +- published:boolean ## websites/Document diff --git a/test/controllers/communication/website/posts_controller_test.rb b/test/controllers/communication/website/posts_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..96ca644e10a91a035adc76e615f36c1e0e4ca9a5 --- /dev/null +++ b/test/controllers/communication/website/posts_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class Communication::Website::PostsControllerTest < ActionDispatch::IntegrationTest + setup do + @communication_website_post = communication_website_posts(:one) + end + + test "should get index" do + get communication_website_posts_url + assert_response :success + end + + test "should get new" do + get new_communication_website_post_url + assert_response :success + end + + test "should create communication_website_post" do + assert_difference('Communication::Website::Post.count') do + post communication_website_posts_url, params: { communication_website_post: { description: @communication_website_post.description, published: @communication_website_post.published, published_at: @communication_website_post.published_at, text: @communication_website_post.text, title: @communication_website_post.title, university_id: @communication_website_post.university_id, website_id: @communication_website_post.website_id } } + end + + assert_redirected_to communication_website_post_url(Communication::Website::Post.last) + end + + test "should show communication_website_post" do + get communication_website_post_url(@communication_website_post) + assert_response :success + end + + test "should get edit" do + get edit_communication_website_post_url(@communication_website_post) + assert_response :success + end + + test "should update communication_website_post" do + patch communication_website_post_url(@communication_website_post), params: { communication_website_post: { description: @communication_website_post.description, published: @communication_website_post.published, published_at: @communication_website_post.published_at, text: @communication_website_post.text, title: @communication_website_post.title, university_id: @communication_website_post.university_id, website_id: @communication_website_post.website_id } } + assert_redirected_to communication_website_post_url(@communication_website_post) + end + + test "should destroy communication_website_post" do + assert_difference('Communication::Website::Post.count', -1) do + delete communication_website_post_url(@communication_website_post) + end + + assert_redirected_to communication_website_posts_url + end +end diff --git a/test/fixtures/communication/website/imported/posts.yml b/test/fixtures/communication/website/imported/posts.yml new file mode 100644 index 0000000000000000000000000000000000000000..a59f72baaa85440da8187cef35884578cead9f53 --- /dev/null +++ b/test/fixtures/communication/website/imported/posts.yml @@ -0,0 +1,53 @@ +# == Schema Information +# +# Table name: communication_website_imported_posts +# +# id :uuid not null, primary key +# content :text +# description :text +# identifier :string +# path :text +# published_at :datetime +# status :integer default(0) +# title :string +# url :text +# created_at :datetime not null +# updated_at :datetime not null +# post_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_posts_on_post_id (post_id) +# index_communication_website_imported_posts_on_university_id (university_id) +# index_communication_website_imported_posts_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (post_id => communication_website_posts.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# + +one: + university: one + website: one + post: one + status: 1 + title: MyString + description: MyText + content: MyText + published_at: 2021-10-08 14:46:37 + identifier: MyString + +two: + university: two + website: two + post: two + status: 1 + title: MyString + description: MyText + content: MyText + published_at: 2021-10-08 14:46:37 + identifier: MyString diff --git a/test/fixtures/communication/website/posts.yml b/test/fixtures/communication/website/posts.yml new file mode 100644 index 0000000000000000000000000000000000000000..28582416bce539d44657e676c5c17d8f2407f874 --- /dev/null +++ b/test/fixtures/communication/website/posts.yml @@ -0,0 +1,43 @@ +# == Schema Information +# +# Table name: communication_website_posts +# +# id :uuid not null, primary key +# description :text +# published :boolean default(FALSE) +# published_at :datetime +# text :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# communication_website_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_communication_website_posts_on_communication_website_id (communication_website_id) +# index_communication_website_posts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (communication_website_id => communication_websites.id) +# fk_rails_... (university_id => universities.id) +# + +one: + university: one + website: one + title: MyString + description: MyText + text: MyText + published: + published_at: 2021-10-08 14:04:23 + +two: + university: two + website: two + title: MyString + description: MyText + text: MyText + published: + published_at: 2021-10-08 14:04:23 diff --git a/test/models/communication/website/imported/post_test.rb b/test/models/communication/website/imported/post_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..4319bd5f8d69d551faae9467bca4d1bfbdc0cb84 --- /dev/null +++ b/test/models/communication/website/imported/post_test.rb @@ -0,0 +1,38 @@ +# == Schema Information +# +# Table name: communication_website_imported_posts +# +# id :uuid not null, primary key +# content :text +# description :text +# identifier :string +# path :text +# published_at :datetime +# status :integer default(0) +# title :string +# url :text +# created_at :datetime not null +# updated_at :datetime not null +# post_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_posts_on_post_id (post_id) +# index_communication_website_imported_posts_on_university_id (university_id) +# index_communication_website_imported_posts_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (post_id => communication_website_posts.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +require "test_helper" + +class Communication::Website::Imported::PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/communication/website/post_test.rb b/test/models/communication/website/post_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..9673a3e4810ecdb511f559018ebcec755696fe5e --- /dev/null +++ b/test/models/communication/website/post_test.rb @@ -0,0 +1,32 @@ +# == Schema Information +# +# Table name: communication_website_posts +# +# id :uuid not null, primary key +# description :text +# published :boolean default(FALSE) +# published_at :datetime +# text :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# communication_website_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_communication_website_posts_on_communication_website_id (communication_website_id) +# index_communication_website_posts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (communication_website_id => communication_websites.id) +# fk_rails_... (university_id => universities.id) +# +require "test_helper" + +class Communication::Website::PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/communication/website/posts_test.rb b/test/system/communication/website/posts_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..cbd0d35c7b3491e166337ec2e0e6e0a7dabfbebf --- /dev/null +++ b/test/system/communication/website/posts_test.rb @@ -0,0 +1,55 @@ +require "application_system_test_case" + +class Communication::Website::PostsTest < ApplicationSystemTestCase + setup do + @communication_website_post = communication_website_posts(:one) + end + + test "visiting the index" do + visit communication_website_posts_url + assert_selector "h1", text: "Communication/Website/Posts" + end + + test "creating a Post" do + visit communication_website_posts_url + click_on "New Communication/Website/Post" + + fill_in "Description", with: @communication_website_post.description + fill_in "Published", with: @communication_website_post.published + fill_in "Published at", with: @communication_website_post.published_at + fill_in "Text", with: @communication_website_post.text + fill_in "Title", with: @communication_website_post.title + fill_in "University", with: @communication_website_post.university_id + fill_in "Website", with: @communication_website_post.website_id + click_on "Create Post" + + assert_text "Post was successfully created" + click_on "Back" + end + + test "updating a Post" do + visit communication_website_posts_url + click_on "Edit", match: :first + + fill_in "Description", with: @communication_website_post.description + fill_in "Published", with: @communication_website_post.published + fill_in "Published at", with: @communication_website_post.published_at + fill_in "Text", with: @communication_website_post.text + fill_in "Title", with: @communication_website_post.title + fill_in "University", with: @communication_website_post.university_id + fill_in "Website", with: @communication_website_post.website_id + click_on "Update Post" + + assert_text "Post was successfully updated" + click_on "Back" + end + + test "destroying a Post" do + visit communication_website_posts_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Post was successfully destroyed" + end +end