2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
# Controlador de sitios
|
2018-01-29 18:09:30 +00:00
|
|
|
class SitesController < ApplicationController
|
2019-07-03 23:25:23 +00:00
|
|
|
before_action :authenticate_usuarie!
|
2018-01-29 18:09:30 +00:00
|
|
|
|
2021-05-09 16:08:18 +00:00
|
|
|
breadcrumb -> { current_usuarie.email }, :edit_usuarie_registration_path
|
|
|
|
breadcrumb 'sites.index', :sites_path, match: :exact
|
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
# Ver un listado de sitios
|
2018-01-29 18:09:30 +00:00
|
|
|
def index
|
2018-09-28 15:27:25 +00:00
|
|
|
authorize Site
|
2023-03-27 15:38:31 +00:00
|
|
|
@sites = current_usuarie.sites.order(updated_at: :desc)
|
2020-05-11 20:28:38 +00:00
|
|
|
|
|
|
|
fresh_when @sites
|
2018-01-29 22:19:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
|
|
|
# artículos
|
|
|
|
def show
|
2019-07-12 23:40:44 +00:00
|
|
|
authorize site
|
2018-01-29 22:19:10 +00:00
|
|
|
|
2021-05-10 18:18:04 +00:00
|
|
|
redirect_to site_posts_path(site, locale: site.default_locale)
|
2018-01-29 18:09:30 +00:00
|
|
|
end
|
2018-02-20 17:47:11 +00:00
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
def new
|
2021-05-09 16:08:18 +00:00
|
|
|
breadcrumb 'sites.new', :new_site_path
|
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
@site = Site.new
|
|
|
|
authorize @site
|
2020-09-28 22:38:24 +00:00
|
|
|
|
|
|
|
@site.deploys.build type: 'DeployLocal'
|
2019-07-12 23:40:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2019-08-09 19:49:25 +00:00
|
|
|
service = SiteService.new(usuarie: current_usuarie,
|
|
|
|
params: site_params)
|
|
|
|
|
|
|
|
if (@site = service.create).persisted?
|
2021-05-10 18:18:04 +00:00
|
|
|
redirect_to site_posts_path(@site, locale: @site.default_locale)
|
2019-07-12 23:40:44 +00:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-13 00:20:36 +00:00
|
|
|
def edit
|
2020-09-11 15:31:53 +00:00
|
|
|
authorize site
|
2021-05-09 16:08:18 +00:00
|
|
|
|
2021-05-10 18:18:04 +00:00
|
|
|
breadcrumb site.title, site_posts_path(site, locale: site.default_locale), match: :exact
|
2021-05-09 16:08:18 +00:00
|
|
|
breadcrumb 'sites.edit', site_path(site)
|
|
|
|
|
2020-09-11 15:31:53 +00:00
|
|
|
SiteService.new(site: site).build_deploys
|
2019-07-13 00:20:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-09-11 15:31:53 +00:00
|
|
|
authorize site
|
2019-07-13 00:20:36 +00:00
|
|
|
|
2020-09-11 15:31:53 +00:00
|
|
|
service = SiteService.new(site: site, params: site_params,
|
2019-08-09 19:49:25 +00:00
|
|
|
usuarie: current_usuarie)
|
|
|
|
|
2019-09-12 18:10:37 +00:00
|
|
|
if service.update.valid?
|
2021-05-10 18:18:04 +00:00
|
|
|
redirect_to site_posts_path(site, locale: site.default_locale)
|
2019-07-13 00:20:36 +00:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 17:47:11 +00:00
|
|
|
def enqueue
|
2019-07-26 01:11:01 +00:00
|
|
|
authorize site
|
2018-02-20 17:47:11 +00:00
|
|
|
|
2023-03-15 21:22:20 +00:00
|
|
|
SiteService.new(site: site).deploy
|
2018-02-20 17:47:11 +00:00
|
|
|
|
2021-05-10 18:18:04 +00:00
|
|
|
redirect_to site_posts_path(site, locale: site.default_locale)
|
2018-02-20 17:47:11 +00:00
|
|
|
end
|
2018-04-30 18:51:39 +00:00
|
|
|
|
|
|
|
def reorder_posts
|
2020-09-11 15:31:53 +00:00
|
|
|
authorize site
|
2018-04-30 18:51:39 +00:00
|
|
|
lang = params.require(:posts).require(:lang)
|
|
|
|
|
2020-08-03 18:58:08 +00:00
|
|
|
result = if params[:posts][:force].present?
|
2020-09-11 15:31:53 +00:00
|
|
|
site.reorder_collection! lang
|
2020-08-03 18:58:08 +00:00
|
|
|
else
|
2020-09-11 15:31:53 +00:00
|
|
|
site
|
2020-08-03 18:58:08 +00:00
|
|
|
.reorder_collection(lang, params.require(:posts).require(:order))
|
|
|
|
end
|
2018-05-02 17:23:45 +00:00
|
|
|
|
|
|
|
if result
|
2018-04-30 18:51:39 +00:00
|
|
|
flash[:info] = I18n.t('info.posts.reorder')
|
|
|
|
else
|
|
|
|
flash[:danger] = I18n.t('errors.posts.reorder')
|
|
|
|
end
|
|
|
|
|
2021-05-10 18:18:04 +00:00
|
|
|
redirect_to site_posts_path(site, locale: site.default_locale)
|
2018-04-30 18:51:39 +00:00
|
|
|
end
|
2019-07-12 23:40:44 +00:00
|
|
|
|
2019-07-16 19:47:44 +00:00
|
|
|
def fetch
|
2020-09-11 15:31:53 +00:00
|
|
|
authorize site
|
2019-07-16 19:47:44 +00:00
|
|
|
|
2020-09-11 15:31:53 +00:00
|
|
|
@commits = site.repository.commits
|
2019-07-16 19:47:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge
|
2020-09-11 15:31:53 +00:00
|
|
|
authorize site
|
2019-07-16 19:47:44 +00:00
|
|
|
|
2021-05-31 16:23:40 +00:00
|
|
|
if SiteService.new(site: site, usuarie: current_usuarie).merge
|
2019-07-16 19:47:44 +00:00
|
|
|
flash[:success] = I18n.t('sites.fetch.merge.success')
|
|
|
|
else
|
|
|
|
flash[:error] = I18n.t('sites.fetch.merge.error')
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to sites_path
|
|
|
|
end
|
|
|
|
|
2020-10-30 21:57:46 +00:00
|
|
|
# Obtiene y streamea archivos estáticos desde el repositorio mismo,
|
|
|
|
# pero sólo los públicos (es decir los archivos subidos desde Sutty).
|
|
|
|
def static_file
|
|
|
|
authorize site
|
|
|
|
|
|
|
|
file = params.require(:file) + '.' + params.require(:format)
|
|
|
|
|
2020-11-02 22:43:55 +00:00
|
|
|
raise ActionController::RoutingError.new(nil, nil) unless file.start_with? 'public/'
|
2020-10-30 21:57:46 +00:00
|
|
|
|
|
|
|
path = site.relative_path file
|
|
|
|
|
2020-11-02 22:43:55 +00:00
|
|
|
raise ActionController::RoutingError.new(nil, nil) unless File.exist? path
|
2020-10-30 21:57:46 +00:00
|
|
|
|
|
|
|
# TODO: Hacer esto usa recursos, pero menos que generar el sitio
|
|
|
|
# cada vez. Para poder usar X-Accel tendríamos que montar los
|
|
|
|
# repositorios en el servidor web, cosa que no queremos, o hacer
|
|
|
|
# links simbólicos desde todos los public, o usar un servidor web
|
|
|
|
# local que soporte sendfile mejor que Rails (nghttpd?)
|
|
|
|
send_file path
|
|
|
|
end
|
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
private
|
|
|
|
|
2020-09-11 15:31:53 +00:00
|
|
|
def site
|
|
|
|
@site ||= find_site
|
|
|
|
end
|
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
def site_params
|
2019-07-25 18:51:32 +00:00
|
|
|
params.require(:site)
|
2019-07-31 20:55:34 +00:00
|
|
|
.permit(:name, :design_id, :licencia_id, :description, :title,
|
2020-08-22 20:56:37 +00:00
|
|
|
:colaboracion_anonima, :contact, :acepta_invitades,
|
2020-11-11 21:15:58 +00:00
|
|
|
:tienda_api_key, :tienda_url,
|
2019-07-31 20:55:34 +00:00
|
|
|
deploys_attributes: %i[type id _destroy])
|
2019-07-12 23:40:44 +00:00
|
|
|
end
|
2018-01-29 18:09:30 +00:00
|
|
|
end
|