mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 17:41:41 +00:00
lxs invitadxs solo pueden ver sus propios posts
This commit is contained in:
parent
c9e4356dba
commit
50c77564b1
3 changed files with 21 additions and 3 deletions
|
@ -1,15 +1,20 @@
|
|||
class PostsController < ApplicationController
|
||||
include Pundit
|
||||
before_action :authenticate!
|
||||
|
||||
def index
|
||||
@site = find_site
|
||||
authorize @site
|
||||
@lang = find_lang(@site)
|
||||
@category = session[:category] = params.dig(:category)
|
||||
@posts = @site.posts_for(@lang)
|
||||
@posts = policy_scope(@site.posts_for(@lang), policy_scope_class: PostPolicy::Scope)
|
||||
|
||||
if params[:sort_by].present?
|
||||
@posts.sort_by! do |p|
|
||||
p.send(params[:sort_by].to_s)
|
||||
begin
|
||||
@posts.sort_by! do |p|
|
||||
p.send(params[:sort_by].to_s)
|
||||
end
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -135,6 +135,10 @@ class Post
|
|||
get_front_matter 'title'
|
||||
end
|
||||
|
||||
def author
|
||||
get_front_matter 'author'
|
||||
end
|
||||
|
||||
def date
|
||||
get_front_matter 'date'
|
||||
end
|
||||
|
|
|
@ -8,4 +8,13 @@ class SuttyPolicy
|
|||
def usuaria?
|
||||
usuarix.is_a? Usuaria
|
||||
end
|
||||
|
||||
class Scope < SuttyPolicy
|
||||
attr_reader :scope
|
||||
|
||||
def initialize(usuarix, scope)
|
||||
@usuarix = usuarix
|
||||
@scope = scope
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue