mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 20:06:22 +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,16 +1,21 @@
|
||||||
class PostsController < ApplicationController
|
class PostsController < ApplicationController
|
||||||
|
include Pundit
|
||||||
before_action :authenticate!
|
before_action :authenticate!
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@site = find_site
|
@site = find_site
|
||||||
|
authorize @site
|
||||||
@lang = find_lang(@site)
|
@lang = find_lang(@site)
|
||||||
@category = session[:category] = params.dig(:category)
|
@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?
|
if params[:sort_by].present?
|
||||||
|
begin
|
||||||
@posts.sort_by! do |p|
|
@posts.sort_by! do |p|
|
||||||
p.send(params[:sort_by].to_s)
|
p.send(params[:sort_by].to_s)
|
||||||
end
|
end
|
||||||
|
rescue ArgumentError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,10 @@ class Post
|
||||||
get_front_matter 'title'
|
get_front_matter 'title'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def author
|
||||||
|
get_front_matter 'author'
|
||||||
|
end
|
||||||
|
|
||||||
def date
|
def date
|
||||||
get_front_matter 'date'
|
get_front_matter 'date'
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,4 +8,13 @@ class SuttyPolicy
|
||||||
def usuaria?
|
def usuaria?
|
||||||
usuarix.is_a? Usuaria
|
usuarix.is_a? Usuaria
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Scope < SuttyPolicy
|
||||||
|
attr_reader :scope
|
||||||
|
|
||||||
|
def initialize(usuarix, scope)
|
||||||
|
@usuarix = usuarix
|
||||||
|
@scope = scope
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue