Skip to content
Snippets Groups Projects
Unverified Commit d84759cd authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

Merge branch 'curation'

parents 8a19f7d0 34a46d47
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ gem 'octokit'
gem 'front_matter_parser'
gem 'two_factor_authentication', git: 'https://github.com/noesya/two_factor_authentication.git'
# gem 'two_factor_authentication', path: '../two_factor_authentication'
gem 'curation'#, path: '../../arnaudlevy/curation'
# Front
gem 'jquery-rails'
......
......@@ -130,6 +130,9 @@ GEM
countries (~> 4.0)
sort_alphabetical (~> 1.1)
crass (1.0.6)
curation (1.7)
metainspector
nokogiri
delayed_job (4.1.9)
activesupport (>= 3.0, < 6.2)
delayed_job_active_record (4.1.6)
......@@ -148,6 +151,8 @@ GEM
warden (~> 1.2.3)
devise-i18n (1.10.1)
devise (>= 4.8.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
encryptor (3.0.0)
enum-i18n (0.1.1)
activerecord (>= 4.1)
......@@ -168,14 +173,24 @@ GEM
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-cookie_jar (0.0.7)
faraday (>= 0.8.0)
http-cookie (~> 1.0.0)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-encoding (0.0.5)
faraday
faraday-excon (1.1.0)
faraday-http-cache (2.2.0)
faraday (>= 0.8)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.5)
ffi (1.15.4)
figaro (1.2.0)
thor (>= 0.14.0, < 2)
......@@ -186,6 +201,8 @@ GEM
sassc-rails
globalid (0.5.2)
activesupport (>= 5.0)
http-cookie (1.0.4)
domain_name (~> 0.5)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
i18n_data (0.13.0)
......@@ -227,6 +244,16 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.2)
matrix (0.4.2)
metainspector (5.11.2)
addressable (~> 2.7)
faraday (~> 1.4)
faraday-cookie_jar (~> 0.0)
faraday-encoding (~> 0.0)
faraday-http-cache (~> 2.2)
faraday_middleware (~> 1.0)
fastimage (~> 2.2)
nesty (~> 1.0)
nokogiri (~> 1.11)
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.1.2)
......@@ -236,6 +263,7 @@ GEM
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nesty (1.0.2)
nio4r (2.5.8)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
......@@ -355,6 +383,9 @@ GEM
ethon (>= 0.9.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unicode_utils (1.4.0)
warden (1.2.9)
rack (>= 2.0.9)
......@@ -389,6 +420,7 @@ DEPENDENCIES
cancancan
capybara (>= 3.26)
country_select
curation
delayed_job_active_record
delayed_job_web
devise
......
class Admin::Communication::Website::Posts::CurationsController < Admin::Communication::Website::ApplicationController
def new
breadcrumb
end
def create
@curator = Curator.new @website, current_user, curation_params[:url]
if @curator.valid?
redirect_to [:edit, :admin, @curator.post], notice: t('admin.successfully_created_html', model: @curator.post.to_s)
else
breadcrumb
byebug
flash[:alert] = "Erreur lors de la curation"
render :new, status: :unprocessable_entity
end
end
protected
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
def curation_params
params.require(:curation).permit(:url)
end
end
......@@ -61,7 +61,7 @@ class User < ApplicationRecord
belongs_to :university
belongs_to :language
has_one :researcher, class_name: 'Research::Researcher', dependent: :nullify
has_one :auhtor, class_name: 'Communication::Website::Author', dependent: :nullify
has_one :author, class_name: 'Communication::Website::Author', dependent: :nullify
scope :ordered, -> { order(:last_name, :first_name) }
......
class Curator
attr_reader :website, :user, :url, :post
def initialize(website, user, url)
@website = website
@user = user
@url = url
create_post!
attach_image! unless page.image.blank?
end
def valid?
@post.valid?
end
protected
def create_post!
text = Wordpress.clean_html("#{page.text}<br><a href=\"#{@url}\" target=\"_blank\">Source</a>")
@post = website.posts.create(
university: website.university,
title: page.title,
text: text,
slug: page.title.parameterize,
author: @user.author,
published_at: Time.now
)
end
def attach_image!
@post.featured_image.attach(
io: URI.open(page.image),
filename: File.basename(page.image).split('?').first
)
rescue
puts "Attach image failed"
end
def page
@page ||= Curation::Page.new(@url)
end
end
<% content_for :title, t('communication.website.posts.new_curation') %>
<%= simple_form_for :curation, url: admin_communication_website_post_curations_path, html: { id: 'new_communication_website_post_curation' } 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"><%= t('content') %></h5>
</div>
<div class="card-body">
<%= f.input :url,
label: 'URL',
value: params.dig(:curation, :url) %>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= submit f %>
<% end %>
<% end %>
......@@ -5,4 +5,7 @@
<% content_for :action_bar_right do %>
<%= create_link Communication::Website::Post %>
<%= link_to t('communication.website.posts.new_curation'),
new_admin_communication_website_post_curation_path(website_id: @website.id),
class: button_classes if can?(:create, Communication::Website::Post) %>
<% end %>
......@@ -11,6 +11,7 @@
<% end %>
<%= render 'admin/communication/websites/show/posts' %>
<div class="row">
<div class="col-md-4">
<%= render 'admin/communication/websites/show/home' %>
......
<div class="card mt-5">
<div class="card-header">
<div class="float-end">
<%= link_to t('communication.website.posts.new_curation'),
new_admin_communication_website_post_curation_path(website_id: @website.id),
class: button_classes if can?(:create, Communication::Website::Post) %>
<%= link_to t('create'),
new_admin_communication_website_post_path(website_id: @website),
class: button_classes if can?(:create, Communication::Website::Post) %>
......
......@@ -15,6 +15,8 @@ en:
pending: Import in progress
last_pages: Last pages
last_posts: Last posts
posts:
new_curation: New curation
see_all: See the full list (%{number} elements)
activemodel:
models:
......
......@@ -15,6 +15,8 @@ fr:
pending: Import en cours
last_pages: Dernières pages
last_posts: Dernières actualités
posts:
new_curation: Nouvelle curation
see_all: Voir la liste complète (%{number} éléments)
activemodel:
models:
......
......@@ -35,6 +35,7 @@ namespace :communication do
post :publish
end
end
resources :curations, path: 'posts/curations', as: :post_curations, controller: 'website/posts/curations', only: [:new, :create]
resources :menus, controller: 'website/menus' do
resources :items, controller: 'website/menu/items', except: :index do
collection do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment