5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 04:16: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,16 +16,19 @@
%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')}
- if policy(site).show?
= render 'layouts/btn_with_tooltip', = render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.edit_posts'), tooltip: t('help.sites.edit_posts'),
type: 'success', type: 'success',
link: site_path(site), link: site_path(site),
text: t('sites.posts') text: t('sites.posts')
- if policy(:i18n).edit?
= render 'layouts/btn_with_tooltip', = render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.edit_translations'), tooltip: t('help.sites.edit_translations'),
text: t('i18n.edit'), text: t('i18n.edit'),
type: 'info', type: 'info',
link: site_i18n_edit_path(site) link: site_i18n_edit_path(site)
- if policy(site).build?
- if site.enqueued? - if site.enqueued?
= render 'layouts/btn_with_tooltip', = render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.enqueued'), tooltip: t('help.sites.enqueued'),
@ -41,6 +44,7 @@
= fa_icon 'building' = fa_icon 'building'
= t('sites.enqueue') = t('sites.enqueue')
- if policy(site).build_log?
- if site.failed? - if site.failed?
%button.btn.btn-danger= t('sites.failed') %button.btn.btn-danger= t('sites.failed')
- if site.build_log? - if site.build_log?