Sha256: 36cd6edae84772499877da718e06a2c1209461f33827856b7d3b183f9952cb49
Contents?: true
Size: 1.49 KB
Versions: 25
Compression:
Stored size: 1.49 KB
Contents
# frozen_string_literal: true module Decidim module Comments class Permissions < Decidim::DefaultPermissions def permissions return permission_action if permission_action.subject != :comment case permission_action.action when :read can_read_comments? when :create can_create_comment? when :update, :destroy can_update_comment? when :vote can_vote_comment? end permission_action end private def can_read_comments? return disallow! unless commentable.commentable? allow! end def can_create_comment? return disallow! unless user return disallow! unless commentable.commentable? return disallow! unless commentable&.user_allowed_to_comment?(user) allow! end def can_update_comment? return disallow! unless user return disallow! unless comment.authored_by?(user) allow! end def can_vote_comment? return disallow! unless user return disallow! unless commentable&.user_allowed_to_vote_comment?(user) allow! end def commentable @commentable ||= if comment comment.root_commentable else context.fetch(:commentable, nil) end end def comment @comment ||= context.fetch(:comment, nil) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems