Sha256: 998ece84874a95cabaa344b86c8ca3beb9408c4ca9977343dba6d42355137fd7
Contents?: true
Size: 1.2 KB
Versions: 87
Compression:
Stored size: 1.2 KB
Contents
module Pageflow class FilePolicy < ApplicationPolicy def initialize(user, file) @user = user @file = file end def manage? if @file.parent_file can_edit_any_entry_using_file?(@file.parent_file) else can_edit_any_entry_using_file?(@file) end end def use? can_preview_any_entry_using_file? end private def can_preview_any_entry_using_file? previewer_of_any_entry_using_file_or_its_account?(@user, @file) end def previewer_of_any_entry_using_file_or_its_account?(user, file) entries_user_is_previewer_or_above_on = EntryPolicy::Scope .new(user, Entry).resolve (entries_user_is_previewer_or_above_on.map(&:id) & file.using_entry_ids).any? end def can_edit_any_entry_using_file?(file) editor_of_any_entry_using_file_or_its_account?(@user, file) end def editor_of_any_entry_using_file_or_its_account?(user, file) entries_user_is_editor_or_above_on = EntryPolicy::Scope .new(user, Entry).editor_or_above (entries_user_is_editor_or_above_on.map(&:id) & file.using_entry_ids).any? end end end
Version data entries
87 entries across 87 versions & 1 rubygems