mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 00:06:21 +00:00
126 lines
2.6 KiB
Ruby
126 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Controlador de sitios
|
|
class SitesController < ApplicationController
|
|
include Pundit
|
|
before_action :authenticate_usuarie!
|
|
|
|
# Ver un listado de sitios
|
|
def index
|
|
authorize Site
|
|
@sites = current_usuarie.sites
|
|
end
|
|
|
|
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
|
# artículos
|
|
def show
|
|
site = find_site
|
|
authorize site
|
|
|
|
redirect_to site_posts_path(site)
|
|
end
|
|
|
|
def new
|
|
@site = Site.new
|
|
authorize @site
|
|
|
|
@site.deploys.build type: 'DeployLocal'
|
|
@site.deploys.build type: 'DeployZip'
|
|
end
|
|
|
|
def create
|
|
service = SiteService.new(usuarie: current_usuarie,
|
|
params: site_params)
|
|
|
|
if (@site = service.create).persisted?
|
|
redirect_to site_path(@site)
|
|
else
|
|
render 'new'
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@site = find_site
|
|
|
|
# TODO: esto está acá para ayudar en la migración de
|
|
if @site.deploys.empty?
|
|
@site.deploys.build(type: 'DeployLocal')
|
|
@site.deploys.build type: 'DeployZip'
|
|
end
|
|
|
|
authorize @site
|
|
end
|
|
|
|
def update
|
|
@site = find_site
|
|
authorize @site
|
|
|
|
service = SiteService.new(site: @site, params: site_params,
|
|
usuarie: current_usuarie)
|
|
|
|
if service.update.valid?
|
|
redirect_to sites_path
|
|
else
|
|
render 'edit'
|
|
end
|
|
end
|
|
|
|
def enqueue
|
|
site = find_site
|
|
authorize site
|
|
|
|
# XXX: Convertir en una máquina de estados?
|
|
DeployWorker.perform_async site.id if site.enqueue!
|
|
|
|
redirect_to sites_path
|
|
end
|
|
|
|
def reorder_posts
|
|
@site = find_site
|
|
authorize @site
|
|
lang = params.require(:posts).require(:lang)
|
|
|
|
if params[:posts][:force].present?
|
|
result = @site.reorder_collection! lang
|
|
else
|
|
result = @site
|
|
.reorder_collection(lang, params.require(:posts).require(:order))
|
|
end
|
|
|
|
if result
|
|
flash[:info] = I18n.t('info.posts.reorder')
|
|
else
|
|
flash[:danger] = I18n.t('errors.posts.reorder')
|
|
end
|
|
|
|
redirect_to site_posts_path @site
|
|
end
|
|
|
|
def fetch
|
|
@site = find_site
|
|
authorize @site
|
|
|
|
@commits = @site.repository.commits
|
|
end
|
|
|
|
def merge
|
|
@site = find_site
|
|
authorize @site
|
|
|
|
if @site.repository.merge(current_usuarie)
|
|
flash[:success] = I18n.t('sites.fetch.merge.success')
|
|
else
|
|
flash[:error] = I18n.t('sites.fetch.merge.error')
|
|
end
|
|
|
|
redirect_to sites_path
|
|
end
|
|
|
|
private
|
|
|
|
def site_params
|
|
params.require(:site)
|
|
.permit(:name, :design_id, :licencia_id, :description, :title,
|
|
deploys_attributes: %i[type id _destroy])
|
|
end
|
|
end
|