Skip to content

Commit

Permalink
Hide plugin buttons when changing the parent object isn't allowed
Browse files Browse the repository at this point in the history
Also, fall back to the readonly representation when determining the
region of plugins.

Closes feincms/feincms3#40
  • Loading branch information
matthiask committed May 2, 2024
1 parent 69b59da commit 006403d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions content_editor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ class ContentEditor(ModelAdmin):

def _content_editor_context(self, request, context):
instance = context.get("original")
if not instance:
show_plugins = True
if instance is None:
instance = self.model()
else:
show_plugins = self.has_change_permission(request, instance)

plugins = []
adding_not_allowed = ["_adding_not_allowed"]
Expand All @@ -139,7 +142,7 @@ def _content_editor_context(self, request, context):
if callable(iaf.opts.regions)
else iaf.opts.regions
)
if iaf.opts.has_add_permission(request, instance)
if show_plugins and iaf.opts.has_add_permission(request, instance)
else adding_not_allowed
)
plugins.append(
Expand Down
5 changes: 4 additions & 1 deletion content_editor/static/content_editor/content_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ django.jQuery(function ($) {
function assignRegionDataAttribute() {
orderMachine.find(".inline-related:not(.empty-form)").each(function () {
const $this = $(this)
let region = $this.find(".field-region input").val()
// Try input first and fall back to the readonly presentation
let region =
$this.find(".field-region input").val() ||
$this.find(".field-region .readonly").text()

if (!ContentEditor.regionsByKey[region]) {
const key = `_unknown_${region}`
Expand Down

0 comments on commit 006403d

Please sign in to comment.