2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-03 23:25:23 +00:00
|
|
|
# Política de acceso para sitios
|
|
|
|
class SitePolicy
|
|
|
|
attr_reader :site, :usuarie
|
|
|
|
|
|
|
|
def initialize(usuarie, site)
|
|
|
|
@usuarie = usuarie
|
2018-09-28 15:27:25 +00:00
|
|
|
@site = site
|
|
|
|
end
|
|
|
|
|
2019-07-04 00:47:59 +00:00
|
|
|
# Todes les usuaries pueden ver sus propios sitios
|
2018-09-28 15:27:25 +00:00
|
|
|
def index?
|
2019-07-03 23:25:23 +00:00
|
|
|
true
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|
|
|
|
|
2020-08-23 00:04:46 +00:00
|
|
|
# Puede ver la versión privada del sitio?
|
|
|
|
def private?
|
|
|
|
edit? && site.deploys.find_by_type('DeployPrivate')
|
|
|
|
end
|
|
|
|
|
2019-07-10 19:58:06 +00:00
|
|
|
# Todes les usuaries pueden ver el sitio si aceptaron la invitación
|
2018-09-28 15:27:25 +00:00
|
|
|
def show?
|
2019-07-12 23:40:44 +00:00
|
|
|
!current_role.temporal
|
|
|
|
end
|
|
|
|
|
2020-10-30 21:57:46 +00:00
|
|
|
# Todes pueden ver los archivos
|
|
|
|
def static_file?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
# Todes pueden crear nuevos sitios
|
|
|
|
def new?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
|
|
|
new?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Para poder editarlos también tienen que haber aceptado la invitación
|
|
|
|
def edit?
|
|
|
|
show? && usuarie?
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
edit?
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
edit?
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|
|
|
|
|
2019-07-10 19:58:06 +00:00
|
|
|
# Les invitades no pueden generar el sitio y les usuaries solo hasta
|
|
|
|
# que aceptan la invitación
|
2018-09-28 15:27:25 +00:00
|
|
|
def build?
|
2019-07-12 23:40:44 +00:00
|
|
|
show? && usuarie?
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue?
|
2019-07-04 00:47:59 +00:00
|
|
|
build?
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reorder_posts?
|
2019-07-04 00:47:59 +00:00
|
|
|
build?
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|
2019-07-12 23:40:44 +00:00
|
|
|
|
2019-07-16 19:47:44 +00:00
|
|
|
def pull?
|
|
|
|
build?
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch?
|
|
|
|
pull?
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge?
|
|
|
|
pull?
|
|
|
|
end
|
|
|
|
|
2019-10-18 20:35:09 +00:00
|
|
|
# Solo les usuaries pueden reordenar artículos
|
|
|
|
def reorder?
|
|
|
|
site.usuarie? usuarie
|
|
|
|
end
|
|
|
|
|
2019-07-12 23:40:44 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def current_role
|
|
|
|
usuarie.rol_for_site(site)
|
|
|
|
end
|
|
|
|
|
|
|
|
def usuarie?
|
|
|
|
site.usuarie? usuarie
|
|
|
|
end
|
|
|
|
|
|
|
|
def invitade?
|
|
|
|
site.invitade? usuarie
|
|
|
|
end
|
2018-09-28 15:27:25 +00:00
|
|
|
end
|