5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 21:06:21 +00:00

autorizacion para sitios

This commit is contained in:
f 2018-09-28 12:27:25 -03:00
parent 15a4bed83b
commit e3c42bc606
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
6 changed files with 115 additions and 32 deletions

View file

@ -1,13 +1,16 @@
class I18nController < ApplicationController class I18nController < ApplicationController
include Pundit
before_action :authenticate! before_action :authenticate!
def index def index
authorize :i18n
@site = find_site @site = find_site
redirect_to site_i18n_edit_path(@site) redirect_to site_i18n_edit_path(@site)
end end
def edit def edit
authorize :i18n
@site = find_site @site = find_site
@lang_from = params.fetch(:from, I18n.locale.to_s) @lang_from = params.fetch(:from, I18n.locale.to_s)
@lang_to = params.fetch(:to, @lang_from) @lang_to = params.fetch(:to, @lang_from)
@ -17,6 +20,7 @@ class I18nController < ApplicationController
end end
def update def update
authorize :i18n
@site = find_site @site = find_site
@lang_to = params.require(:i18n).require(:lang_to) @lang_to = params.require(:i18n).require(:lang_to)
# No usamos params porque nos obliga a hacer una lista blanca de # No usamos params porque nos obliga a hacer una lista blanca de

View file

@ -1,15 +1,18 @@
# Controlador de sitios # Controlador de sitios
class SitesController < ApplicationController class SitesController < ApplicationController
include Pundit
before_action :authenticate! before_action :authenticate!
# Ver un listado de sitios # Ver un listado de sitios
def index def index
authorize Site
@sites = current_user.sites @sites = current_user.sites
end end
# No tenemos propiedades de un sitio aún, así que vamos al listado de # No tenemos propiedades de un sitio aún, así que vamos al listado de
# artículos # artículos
def show def show
authorize Site
site = find_site site = find_site
redirect_to site_posts_path(site) redirect_to site_posts_path(site)
@ -17,6 +20,7 @@ class SitesController < ApplicationController
# Envía un archivo del directorio público de Jekyll # Envía un archivo del directorio público de Jekyll
def send_public_file def send_public_file
authorize Site
@site = find_site @site = find_site
file = [params[:basename], params[:format]].join('.') file = [params[:basename], params[:format]].join('.')
path = Pathname.new(File.join(@site.path, 'public', params[:type], file)) path = Pathname.new(File.join(@site.path, 'public', params[:type], file))
@ -36,6 +40,7 @@ class SitesController < ApplicationController
def enqueue def enqueue
@site = find_site @site = find_site
authorize @site
@site.enqueue! @site.enqueue!
redirect_to sites_path redirect_to sites_path
@ -43,6 +48,7 @@ class SitesController < ApplicationController
def build_log def build_log
@site = find_site @site = find_site
authorize @site
# TODO eliminar ANSI # TODO eliminar ANSI
render file: @site.build_log, render file: @site.build_log,
@ -52,6 +58,7 @@ class SitesController < ApplicationController
def reorder_posts def reorder_posts
@site = find_site @site = find_site
authorize @site
lang = params.require(:posts).require(:lang) lang = params.require(:posts).require(:lang)
if params[:posts][:force].present? if params[:posts][:force].present?
@ -68,5 +75,4 @@ class SitesController < ApplicationController
redirect_to site_posts_path @site redirect_to site_posts_path @site
end end
end end

View file

@ -0,0 +1,19 @@
class I18nPolicy < SuttyPolicy
def initialize(usuarix, i18n)
@usuarix = usuarix
end
# Solo las usuarias
def index?
usuaria?
end
def edit?
update?
end
def update?
usuaria?
end
end

View file

@ -0,0 +1,39 @@
class SitePolicy < SuttyPolicy
attr_reader :usuarix, :site
def initialize(usuarix, site)
@usuarix = usuarix
@site = site
end
# Todxs lxs usuarixs pueden ver el índice
def index?
true
end
# Todxs lxs usuarixs pueden ver el sitio
def show?
true
end
# Solo las usuarias
def build?
usuaria?
end
def send_public_file?
true
end
def enqueue?
usuaria?
end
def build_log?
usuaria?
end
def reorder_posts?
usuaria?
end
end

View file

@ -0,0 +1,11 @@
class SuttyPolicy
attr_reader :usuarix
def invitadx?
usuarix.is_a? Invitadx
end
def usuaria?
usuarix.is_a? Usuaria
end
end

View file

@ -16,36 +16,40 @@
%h2= link_to site.name, site_path(site) %h2= link_to site.name, site_path(site)
%br %br
.btn-group{role: 'group', 'aria-label': t('sites.actions')} .btn-group{role: 'group', 'aria-label': t('sites.actions')}
= render 'layouts/btn_with_tooltip', - if policy(site).show?
tooltip: t('help.sites.edit_posts'),
type: 'success',
link: site_path(site),
text: t('sites.posts')
= render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.edit_translations'),
text: t('i18n.edit'),
type: 'info',
link: site_i18n_edit_path(site)
- if site.enqueued?
= render 'layouts/btn_with_tooltip', = render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.enqueued'), tooltip: t('help.sites.edit_posts'),
text: t('sites.enqueued'), type: 'success',
type: 'secondary', link: site_path(site),
link: nil text: t('sites.posts')
- else - if policy(:i18n).edit?
= form_tag site_enqueue_path(site), method: :post, class: 'form-inline' do = render 'layouts/btn_with_tooltip',
= button_tag type: 'submit', tooltip: t('help.sites.edit_translations'),
class: 'btn btn-success', text: t('i18n.edit'),
title: t('help.sites.enqueue'), type: 'info',
data: { toggle: 'tooltip' } do link: site_i18n_edit_path(site)
= fa_icon 'building' - if policy(site).build?
= t('sites.enqueue') - if site.enqueued?
= render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.enqueued'),
text: t('sites.enqueued'),
type: 'secondary',
link: nil
- else
= form_tag site_enqueue_path(site), method: :post, class: 'form-inline' do
= button_tag type: 'submit',
class: 'btn btn-success',
title: t('help.sites.enqueue'),
data: { toggle: 'tooltip' } do
= fa_icon 'building'
= t('sites.enqueue')
- if site.failed? - if policy(site).build_log?
%button.btn.btn-danger= t('sites.failed') - if site.failed?
- if site.build_log? %button.btn.btn-danger= t('sites.failed')
= render 'layouts/btn_with_tooltip', - if site.build_log?
tooltip: t('help.sites.build_log'), = render 'layouts/btn_with_tooltip',
text: t('sites.build_log'), tooltip: t('help.sites.build_log'),
type: 'warning', text: t('sites.build_log'),
link: site_build_log_path(site) type: 'warning',
link: site_build_log_path(site)