Sha256: c6bcc82fb7a2733368e9a1705939a84ff1dcf77a5708985876dbe207eb1e37b5

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'scrivito/cms_field_tag'
require 'fiona7/permitted_mixin'

module Scrivito
  class CmsFieldTag
    include Fiona7::PermittedMixin

    # support shadowclassing
    def build_valid_widget_classes
      obj_or_widget.valid_widget_ruby_classes_for(field_name).map do |widget_class|
        real_widget_class_name = widget_class.name
        fake_widget_class = widget_class.to_s
        widget_class = widget_class.to_s
        {
          name: fake_widget_class,
          description: description_for_widget_class(real_widget_class_name),
        }
      end
    end


    private
    # add permission checking
    def authenticated_editor?
      # NOTE: we check the permissions on the object and not on the widget object itself. It would probaby be better (but slower) to check on the widget object
      editing_context.authenticated_editor? &&
        (permitted?(editing_context.editor.id, obj_not_widget_id, :root) ||
         permitted?(editing_context.editor.id, obj_not_widget_id, :write))
    end

    def obj_not_widget_id
      case obj_or_widget
      when Scrivito::BasicObj
        obj_or_widget.id
      when Scrivito::BasicWidget
        obj_or_widget.obj.id
      else
        raise ScrivitoError, "Expected an Obj or Widget to be passed to scrivito_tag, but #{obj_or_widget.class.name} received"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/scrivito_patches/cms_field_tag.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/scrivito_patches/cms_field_tag.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/scrivito_patches/cms_field_tag.rb