Skip to content

Commit

Permalink
fix: Disable toolbar items without sufficient permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Nov 11, 2024
1 parent 3ab96c4 commit 7284e75
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 77 deletions.
17 changes: 0 additions & 17 deletions djangocms_blog/cms_appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"use_placeholder": get_setting("USE_PLACEHOLDER"),
"use_abstract": get_setting("USE_ABSTRACT"),
"use_related": int(get_setting("USE_RELATED")),
"urlconf": get_setting("URLCONF") if isinstance(get_setting("URLCONF"), str) else get_setting("URLCONF")[0][0],
"set_author": get_setting("AUTHOR_DEFAULT"),
"paginate_by": get_setting("PAGINATION"),
"template_prefix": "",
Expand Down Expand Up @@ -143,15 +142,6 @@ class Meta:
(2, _("Yes, from this site")),
),
)
#: Adjust urlconf (default: :ref:`USE_RELATED <USE_RELATED>`)
urlconf = models.CharField(
max_length=200,
verbose_name=_("URL config"),
default=config_defaults["urlconf"],
choices=(
[(get_setting("URLCONF"), "---")] if isinstance(get_setting("URLCONF"), str) else get_setting("URLCONF")
),
)
#: Set author by default (default: :ref:`AUTHOR_DEFAULT <AUTHOR_DEFAULT>`)
set_author = models.BooleanField(
verbose_name=_("Set author by default"),
Expand Down Expand Up @@ -280,13 +270,6 @@ class Meta:
help_text=_("Emits a desktop notification -if enabled- when editing a published post"),
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
"""Remove urlconf from form if no apphook-based url config is enabled"""
if isinstance(get_setting("URLCONF"), str):
self.fields["urlconf"].widget = forms.HiddenInput()
self.fields["urlconf"].label = "" # Admin otherwise displays label for hidden field

def get_app_title(self):
return getattr(self, "app_title", _("untitled"))

Expand Down
13 changes: 2 additions & 11 deletions djangocms_blog/cms_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
@apphook_pool.register
class BlogApp(CMSApp):
name = _("Blog")
_urls = [get_setting("URLCONF") if isinstance(get_setting("URLCONF"), str) else get_setting("URLCONF")[0][0]]
app_name = "djangocms_blog"
app_config = BlogConfig
_urls = [get_setting("URLCONF")]
_menus = [BlogCategoryMenu]
auto_setup = {
"enabled": get_setting("AUTO_SETUP"),
Expand All @@ -31,16 +31,7 @@ class BlogApp(CMSApp):
}

def get_urls(self, page=None, language=None, **kwargs):
urlconf = get_setting("URLCONF")
if page is None or not page.application_namespace or isinstance(urlconf, str):
return [urlconf] # Single urlconf
return [
getattr(
self.app_config.objects.filter(namespace=page.application_namespace).first(),
"urlconf",
get_setting("URLCONF")[0][0],
)
] # Default if no urlconf is configured
return [get_setting("URLCONF")]

@property
def urls(self):
Expand Down
6 changes: 5 additions & 1 deletion djangocms_blog/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def populate(self):
admin_menu.add_modal_item(
_("%(object_name)s properties") % dict(object_name=object_name.capitalize()),
admin_reverse("djangocms_blog_post_change", args=(current_content.post.pk,)),
disabled=not self.request.user.has_perm("djangocms_blog.change_post"),
)
admin_menu.add_break()
# Entry list menu entry
Expand All @@ -118,6 +119,7 @@ def populate(self):
admin_menu.add_sideframe_item(
_("All entries"),
url=url,
disabled=not self.request.user.has_perm("djangocms_blog.change_post"),
)
# Create menu entry
url = admin_reverse("djangocms_blog_post_add")
Expand All @@ -126,10 +128,12 @@ def populate(self):
admin_menu.add_modal_item(
_("New %(object_name)s") % dict(object_name=object_name),
url=url,
disabled=not self.request.user.has_perm("djangocms_blog.add_post"),
)
if current_config:
url = admin_reverse("djangocms_blog_blogconfig_change", args=(current_config.pk,))
admin_menu.add_modal_item(_("Edit Configuration"), url=url)
disabled = not self.request.user.has_perm("djangocms_blog.change_blogconfig")
admin_menu.add_modal_item(_("Edit Configuration"), url=url, disabled=disabled)
self.add_preview_button()
self.add_view_published_button() # Takes the user the published post version

Expand Down
9 changes: 3 additions & 6 deletions djangocms_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,14 @@
it's a dictionary with ``size``, ``crop`` and ``upscale`` keys.
"""

BLOG_URLCONF = (
("djangocms_blog.urls", _("Blog: Blog list at root url of blog")),
("djangocms_blog.urls_hub", _("Content hub: Category list at root url of blog")),
)
BLOG_URLCONF = "djangocms_blog.urls"
"""
.. _URLCONF:
List of alternative URL configurations which can be set per app hook.
Standard Apphook URLConf.
"""

BLOG_PAGINATION = 10
BLOG_PAGINATION = 20
"""
.. _PAGINATION:
Expand Down
33 changes: 30 additions & 3 deletions djangocms_blog/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
from .urls_base import get_urls
from django.urls import path

from .feeds import FBInstantArticles, LatestEntriesFeed, TagFeed
from .settings import get_setting
from .views import (
AuthorEntriesView,
CategoryEntriesView,
CategoryListView,
PostArchiveView,
PostDetailView,
PostListView,
TaggedListView,
)

# module-level app_name attribute as per django 1.9+
app_name = "djangocms_blog"
urlpatterns = get_urls(post_list_path="", category_path="category/", category_list_path="category/")
urlpatterns = [
path("", PostListView.as_view(), name="posts-latest"),
path("category/", CategoryListView.as_view(), name="categories-all"),
path("category/<str:category>/", CategoryEntriesView.as_view(), name="posts-category"),
path("feed/", LatestEntriesFeed(), name="posts-latest-feed"),
path("feed/fb/", FBInstantArticles(), name="posts-latest-feed-fb"),
path("<int:year>/", PostArchiveView.as_view(), name="posts-archive"),
path("<int:year>/<int:month>/", PostArchiveView.as_view(), name="posts-archive"),
path("author/<str:username>/", AuthorEntriesView.as_view(), name="posts-author"),
path("tag/<slug:tag>/", TaggedListView.as_view(), name="posts-tagged"),
path("tag/<slug:tag>/feed/", TagFeed(), name="posts-tagged-feed"),
]
permalink_urls = get_setting("PERMALINK_URLS")
for urlconf in permalink_urls.values():
urlpatterns.append(
path(urlconf, PostDetailView.as_view(), name="post-detail"),
)
34 changes: 0 additions & 34 deletions djangocms_blog/urls_base.py

This file was deleted.

5 changes: 0 additions & 5 deletions djangocms_blog/urls_hub.py

This file was deleted.

0 comments on commit 7284e75

Please sign in to comment.