lxs invitadxs solo pueden ver sus propios posts

This commit is contained in:
f 2018-09-28 12:47:28 -03:00
parent c9e4356dba
commit 50c77564b1
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
3 changed files with 21 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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