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

Merge pull request #1345 from noesya/api

Amélioration de l'API Osuny en lien avec les importers
parents ce5a344f 26d53b75
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 59 deletions
......@@ -4,7 +4,7 @@ class Admin::Communication::Websites::Posts::CurationsController < Admin::Commun
end
def create
@curator = Curator.new @website, current_user, current_website_language, curation_params[:url]
@curator = Importers::Curator.new @website, current_user, current_website_language, curation_params[:url]
if @curator.valid?
redirect_to [:admin, @curator.post],
notice: t('admin.successfully_created_html', model: @curator.post.to_s)
......
class Api::Osuny::ApplicationController < Api::ApplicationController
protected
def verify_app_token
@app = current_university.apps.find_by(token: request.headers['X-Osuny-Token'])
raise_403_unless @app
end
end
\ No newline at end of file
class Api::Osuny::Communication::Websites::ApplicationController < Api::Osuny::ApplicationController
protected
def website
@website ||= current_university.websites.find params[:website_id]
end
end
class Api::Osuny::Communication::Websites::PagesController < Api::Osuny::Communication::Websites::ApplicationController
skip_before_action :verify_authenticity_token, only: :import
before_action :verify_app_token, only: :import
def import
Importers::Api::Osuny::Communication::Website::Page.new university: current_university,
website: website,
params: params[:page]
render json: :ok
end
end
class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::ApplicationController
class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Communication::Websites::ApplicationController
skip_before_action :verify_authenticity_token, only: :import
before_action :verify_app_token, only: :import
def import
create_post
import_blocks
Importers::Api::Osuny::Communication::Website::Post.new university: current_university,
website: website,
params: params[:post]
render json: :ok
end
protected
def create_post
post.language = website.default_language
post.update post_params
post.save
end
def post
@post ||= website.posts
.where(
university: current_university,
website: website,
migration_identifier: migration_identifier
)
.first_or_initialize
end
def import_blocks
blocks.each do |b|
migration_identifier = b[:migration_identifier]
template_kind = b[:template_kind]
block = post.blocks
.where(
template_kind: template_kind,
migration_identifier: migration_identifier
)
.first_or_initialize
block.university = current_university
data = b[:data].to_unsafe_hash
block.data = block.template.data.merge data
block.save
end
end
def blocks
return [] unless params[:post].has_key?(:blocks)
@blocks ||= params[:post][:blocks]
end
def website
@website ||= current_university.websites.find params[:website_id]
end
def migration_identifier
@migration_identifier ||= params[:migration_identifier]
end
def post_params
params.require(:post)
.permit(
:title, :language, :meta_description, :summary,
)
end
end
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
......@@ -11,6 +11,7 @@
# header_text :text
# kind :integer
# meta_description :text
# migration_identifier :string
# position :integer default(0), not null
# published :boolean default(FALSE)
# slug :string indexed
......
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