mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 08:51:41 +00:00
Merge branch 'issue-13266' into 'rails'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Issue #13266 See merge request sutty/sutty!179
This commit is contained in:
commit
26952ee314
2 changed files with 75 additions and 0 deletions
|
@ -36,6 +36,15 @@ class IndexedPost < ApplicationRecord
|
|||
|
||||
belongs_to :site
|
||||
|
||||
# Encuentra el post original
|
||||
#
|
||||
# @return [nil,Post]
|
||||
def post
|
||||
return if post_id.blank?
|
||||
|
||||
@post ||= site.posts(lang: locale).find(post_id, uuid: true)
|
||||
end
|
||||
|
||||
# Convertir locale a direccionario de PG
|
||||
#
|
||||
# @param [String,Symbol]
|
||||
|
|
66
app/policies/indexed_post_policy.rb
Normal file
66
app/policies/indexed_post_policy.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Política de acceso a artículos
|
||||
class IndexedPostPolicy
|
||||
attr_reader :indexed_post, :usuarie, :site
|
||||
|
||||
def initialize(usuarie, indexed_post)
|
||||
@usuarie = usuarie
|
||||
@indexed_post = indexed_post
|
||||
@site = indexed_post.site
|
||||
end
|
||||
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
# Les invitades solo pueden ver sus propios posts
|
||||
def show?
|
||||
site.usuarie?(usuarie) || site.indexed_posts.by_usuarie(usuarie.id).find_by_post_id(indexed_post.post_id).present?
|
||||
end
|
||||
|
||||
def preview?
|
||||
show?
|
||||
end
|
||||
|
||||
def new?
|
||||
create?
|
||||
end
|
||||
|
||||
def create?
|
||||
true
|
||||
end
|
||||
|
||||
def edit?
|
||||
update?
|
||||
end
|
||||
|
||||
# Les invitades solo pueden modificar sus propios artículos
|
||||
def update?
|
||||
show?
|
||||
end
|
||||
|
||||
# Solo las usuarias pueden eliminar artículos. Les invitades pueden
|
||||
# borrar sus propios artículos
|
||||
def destroy?
|
||||
update?
|
||||
end
|
||||
|
||||
# Las usuarias pueden ver todos los posts
|
||||
#
|
||||
# Les invitades solo pueden ver sus propios posts
|
||||
class Scope
|
||||
attr_reader :usuarie, :scope
|
||||
|
||||
def initialize(usuarie, scope)
|
||||
@usuarie = usuarie
|
||||
@scope = scope
|
||||
end
|
||||
|
||||
def resolve
|
||||
return scope if scope&.first&.site&.usuarie? usuarie
|
||||
|
||||
scope.by_usuarie(usuarie.id)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue