2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-28 17:15:09 +00:00
|
|
|
class PostPolicy < SuttyPolicy
|
|
|
|
attr_reader :post
|
|
|
|
|
|
|
|
def initialize(usuarix, post)
|
|
|
|
@usuarix = usuarix
|
|
|
|
@post = post
|
|
|
|
end
|
|
|
|
|
|
|
|
def index?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Lxs invitadxs solo pueden ver sus propios posts
|
|
|
|
def show?
|
|
|
|
usuaria? || post.author == usuarix.email
|
|
|
|
end
|
|
|
|
|
|
|
|
def new?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit?
|
|
|
|
update?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Lxs invitadxs solo pueden modificar sus propios artículos
|
|
|
|
def update?
|
|
|
|
usuaria? || post.author == usuarix.email
|
|
|
|
end
|
|
|
|
|
2019-05-30 17:33:51 +00:00
|
|
|
# Solo las usuarias pueden eliminar artículos. Lxs invitadxs pueden
|
|
|
|
# borrar sus propios artículos
|
|
|
|
def destroy?
|
|
|
|
update?
|
|
|
|
end
|
|
|
|
|
2018-09-28 17:15:09 +00:00
|
|
|
class Scope < SuttyPolicy::Scope
|
|
|
|
# Las usuarias pueden ver todos los posts
|
|
|
|
#
|
|
|
|
# Lxs invitadxs solo pueden ver sus propios posts
|
|
|
|
def resolve
|
|
|
|
return scope if usuaria?
|
|
|
|
|
|
|
|
# Asegurarse que al menos devolvemos []
|
|
|
|
[scope.find do |post|
|
|
|
|
post.author == usuarix.email
|
|
|
|
end].flatten.compact
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|