mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 16:36:22 +00:00
119 lines
2.4 KiB
Ruby
119 lines
2.4 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.order(:title)
|
|
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
|
|
SiteService.new(site: @site).build_deploys
|
|
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
|
|
authorize @site
|
|
SiteService.new(site: @site).build_deploys
|
|
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?
|
|
DeployJob.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,
|
|
:colaboracion_anonima,
|
|
deploys_attributes: %i[type id _destroy])
|
|
end
|
|
end
|