5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-02 11:24:17 +00:00
panel/app/policies/post_policy.rb

66 lines
1.1 KiB
Ruby
Raw Normal View History

2019-03-26 15:32:20 +00:00
# frozen_string_literal: true
2019-07-03 23:40:24 +00:00
# Política de acceso a artículos
class PostPolicy
2019-07-04 16:23:43 +00:00
attr_reader :post, :usuarie
2018-09-28 17:15:09 +00:00
2019-07-03 23:40:24 +00:00
def initialize(usuarie, post)
@usuarie = usuarie
2018-09-28 17:15:09 +00:00
@post = post
end
def index?
true
end
2019-08-06 17:50:58 +00:00
# Les invitades solo pueden ver sus propios posts
2018-09-28 17:15:09 +00:00
def show?
post.site.usuarie?(usuarie) || post.usuaries.include?(usuarie)
2018-09-28 17:15:09 +00:00
end
def preview?
show?
end
2018-09-28 17:15:09 +00:00
def new?
create?
end
def create?
true
end
def edit?
update?
end
2019-08-06 17:50:58 +00:00
# Les invitades solo pueden modificar sus propios artículos
2018-09-28 17:15:09 +00:00
def update?
post.site.usuarie?(usuarie) || post.usuaries.include?(usuarie)
2018-09-28 17:15:09 +00:00
end
2019-08-06 17:50:58 +00:00
# Solo las usuarias pueden eliminar artículos. Les invitades pueden
2019-05-30 17:33:51 +00:00
# borrar sus propios artículos
def destroy?
update?
end
2019-07-03 23:40:24 +00:00
# Las usuarias pueden ver todos los posts
#
2019-08-06 17:50:58 +00:00
# Les invitades solo pueden ver sus propios posts
2019-07-03 23:40:24 +00:00
class Scope
attr_reader :usuarie, :scope
def initialize(usuarie, scope)
@usuarie = usuarie
@scope = scope
end
2018-09-28 17:15:09 +00:00
def resolve
return scope if scope&.first&.site&.usuarie? usuarie
2019-07-04 16:23:43 +00:00
scope.by_usuarie(usuarie.id)
2018-09-28 17:15:09 +00:00
end
end
end