Class: CamaleonCms::Admin::Appearances::Widgets::AssignController

Inherits:
CamaleonCms::AdminController show all
Includes:
CustomFieldsConcern
Defined in:
app/controllers/camaleon_cms/admin/appearances/widgets/assign_controller.rb

Instance Method Summary collapse

Methods inherited from CamaleonCms::AdminController

#ajax, #cama_get_i18n_frontend, #dashboard, #index, #search

Instance Method Details

#destroyObject



34
35
36
37
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/assign_controller.rb', line 34

def destroy
  @assigned.destroy
  render plain: ''
end

#newObject



12
13
14
15
16
17
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/assign_controller.rb', line 12

def new
  @widget = current_site.widgets.find(params[:widget_id])
  @assigned = @sidebar.assigned.create!({ title: 'Default', widget_id: @widget.id })
  render partial: 'form', locals: { assigned: @assigned, widget: @widget, sidebar: @sidebar },
         layout: 'camaleon_cms/admin/ajax'
end

#updateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/assign_controller.rb', line 19

def update
  # sidebar_id (post_parent) and widget_id (visibility) identify the tenant-scoped sidebar and
  # widget this assignment belongs to; they are set from @sidebar/@widget on create and must
  # not be reassigned from the request, or the assignment could be re-pointed into another
  # site's sidebar or widget (audit finding H9). Reordering has its own current-site-scoped
  # action (sidebar#reorder).
  if @assigned.update(params.require(:assign).permit(:title, :content, :item_order))
    @assigned.set_field_values(cama_permitted_field_options('Main'))
    flash[:notice] = t('camaleon_cms.admin.widgets.assign.updated')
  else
    flash[:error] = t('camaleon_cms.admin.widgets.assign.error_updated')
  end
  redirect_to cama_admin_appearances_widgets_main_index_path
end