We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Permission edit_page not working for region users
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
The permission `edit_page` throws an error for region users when called on a non-existing page

### Steps to Reproduce

1. Login as region user (not superadmin or staff)
2. Click on Pages
4. See error

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
The page tree should appear

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
The following error appears:
```
AttributeError at /augsburg/pages/de-de/

'NoneType' object has no attribute 'region'
```

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->
The error arises because `page.region` is accessed, even if no page is supplied:
```
if page.region not in user.profile.regions.all():
    return False
```
We have two possibilities here:
1. somehow inject the current region into the rule predicate and use this instead of `page.region`
2. Rely on the fact that the region permissions are checked elsewhere. E.g. the user can't open a page form in another region than he belongs to (this is already checked by the `@method_decorator(region_permission_required, name="dispatch")` in the page form) and a page form can only be used to edit pages of the current region (this is alredy checked by `page = region.pages.filter(id=kwargs.get("page_id")).first()`). So in theory, the check might not be necessary altogether, or am I missing something?

<details>
  <summary>Debug Information</summary>
  
Environment:


Request Method: GET
Request URL: http://localhost:8000/augsburg/pages/de-de/

Django Version: 2.2.16
Python Version: 3.7.9
Installed Applications:
['cms.apps.CmsConfig',
 'gvz_api.apps.GvzApiConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sitemaps',
 'django.contrib.staticfiles',
 'compressor',
 'compressor_toolkit',
 'corsheaders',
 'widget_tweaks',
 'easy_thumbnails',
 'filer',
 'mptt',
 'rules.apps.AutodiscoverRulesConfig']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/timo/job/integreat/django/src/cms/decorators.py" in wrap
  56.             return function(request, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/mixins.py" in dispatch
  85.         return super().dispatch(request, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
  97.         return handler(request, *args, **kwargs)

File "/home/timo/job/integreat/django/src/cms/views/pages/page_tree_view.py" in get
  56.         if not request.user.has_perm("cms.edit_page"):

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/models.py" in has_perm
  268.         return _user_has_perm(self, perm, obj)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/models.py" in _user_has_perm
  182.             if backend.has_perm(user, perm, obj):

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/permissions.py" in has_perm
  32.         return has_perm(perm, user, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/permissions.py" in has_perm
  24.     return permissions.test_rule(name, *args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/rulesets.py" in test_rule
  6.         return name in self and self[name].test(*args, **kwargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in test
  154.             return bool(self._apply(*args))

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _apply
  213.         result = self.fn(*callargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in OR
  165.             return self._combine(other, operator.or_, args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _combine
  184.         self_result = self._apply(*args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _apply
  213.         result = self.fn(*callargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in OR
  165.             return self._combine(other, operator.or_, args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _combine
  184.         self_result = self._apply(*args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _apply
  213.         result = self.fn(*callargs)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in OR
  165.             return self._combine(other, operator.or_, args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _combine
  184.         self_result = self._apply(*args)

File "/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py" in _apply
  213.         result = self.fn(*callargs)

File "/home/timo/job/integreat/django/src/cms/rules.py" in can_edit_all_pages
  79.         if page.region not in user.profile.regions.all():

Exception Type: AttributeError at /augsburg/pages/de-de/
Exception Value: 'NoneType' object has no attribute 'region'

  
</details>

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cms/rules.py`
Content:
```
1 """
2 We use `django-rules <https://pypi.org/project/rules/>`_ to add custom permissions for specific pages.
3 
4 For a given user and page, the following permissions are added:
5 
6 * ``cms.edit_page`` if one of the following predicates return true:
7 
8     * :func:`~cms.rules.can_edit_all_pages`
9     * :func:`~cms.rules.is_page_editor`
10     * :func:`~cms.rules.can_publish_all_pages`
11     * :func:`~cms.rules.is_page_publisher`
12 
13 * ``cms.publish_page`` if one of the following predicates return true:
14 
15     * :func:`~cms.rules.can_publish_all_pages`
16     * :func:`~cms.rules.is_page_publisher`
17 
18 See the project's `README <https://github.com/dfunckt/django-rules/blob/master/README.rst>`_ to learn more.
19 """
20 from rules import add_perm, predicate
21 
22 
23 # Predicates
24 
25 
26 @predicate
27 def is_page_editor(user, page):
28     """
29     This predicate checks whether the given user is one of the editors of the given page.
30 
31     :param user: The user who's permission should be checked
32     :type user: ~django.contrib.auth.models.User
33 
34     :param page: The requested page
35     :type page: ~cms.models.pages.page.Page
36 
37     :return: Whether or not ``user`` is an editor of ``page``
38     :rtype: bool
39     """
40     if not page:
41         return False
42     return user in page.editors.all()
43 
44 
45 @predicate
46 def is_page_publisher(user, page):
47     """
48     This predicate checks whether the given user is one of the publishers of the given page.
49 
50     :param user: The user who's permission should be checked
51     :type user: ~django.contrib.auth.models.User
52 
53     :param page: The requested page
54     :type page: ~cms.models.pages.page.Page
55 
56     :return: Whether or not ``user`` is a publisher of ``page``
57     :rtype: bool
58     """
59     if not page:
60         return False
61     return user in page.publishers.all()
62 
63 
64 @predicate
65 def can_edit_all_pages(user, page):
66     """
67     This predicate checks whether the given user can edit all pages.
68 
69     :param user: The user who's permission should be checked
70     :type user: ~django.contrib.auth.models.User
71 
72     :param page: The page parameter is used for the region check
73     :type page: ~cms.models.pages.page.Page
74 
75     :return: Whether or not ``user`` can edit all pages
76     :rtype: bool
77     """
78     if not (user.is_superuser or user.is_staff):
79         if page.region not in user.profile.regions.all():
80             return False
81     return user.has_perm("cms.edit_pages")
82 
83 
84 @predicate
85 def can_publish_all_pages(user, page):
86     """
87     This predicate checks whether the given user can publish all pages.
88 
89     :param user: The user who's permission should be checked
90     :type user: ~django.contrib.auth.models.User
91 
92     :param page: The page parameter is used for the region check
93     :type page: ~cms.models.pages.page.Page
94 
95     :return: Whether or not ``user`` can publish all pages
96     :rtype: bool
97     """
98     if not (user.is_superuser or user.is_staff):
99         if page.region not in user.profile.regions.all():
100             return False
101     return user.has_perm("cms.publish_pages")
102 
103 
104 # Permissions
105 
106 add_perm(
107     "cms.edit_page",
108     can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher,
109 )
110 add_perm("cms.publish_page", can_publish_all_pages | is_page_publisher)
111
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cms/rules.py b/src/cms/rules.py
--- a/src/cms/rules.py
+++ b/src/cms/rules.py
@@ -76,7 +76,7 @@
     :rtype: bool
     """
     if not (user.is_superuser or user.is_staff):
-        if page.region not in user.profile.regions.all():
+        if page and page.region not in user.profile.regions.all():
             return False
     return user.has_perm("cms.edit_pages")
 
@@ -96,7 +96,7 @@
     :rtype: bool
     """
     if not (user.is_superuser or user.is_staff):
-        if page.region not in user.profile.regions.all():
+        if page and page.region not in user.profile.regions.all():
             return False
     return user.has_perm("cms.publish_pages")

{"golden_diff": "diff --git a/src/cms/rules.py b/src/cms/rules.py\n--- a/src/cms/rules.py\n+++ b/src/cms/rules.py\n@@ -76,7 +76,7 @@\n     :rtype: bool\n     \"\"\"\n     if not (user.is_superuser or user.is_staff):\n-        if page.region not in user.profile.regions.all():\n+        if page and page.region not in user.profile.regions.all():\n             return False\n     return user.has_perm(\"cms.edit_pages\")\n \n@@ -96,7 +96,7 @@\n     :rtype: bool\n     \"\"\"\n     if not (user.is_superuser or user.is_staff):\n-        if page.region not in user.profile.regions.all():\n+        if page and page.region not in user.profile.regions.all():\n             return False\n     return user.has_perm(\"cms.publish_pages\")\n", "issue": "Permission edit_page not working for region users\n### Describe the Bug\r\n<!-- A clear and concise description of what the bug is. -->\r\nThe permission `edit_page` throws an error for region users when called on a non-existing page\r\n\r\n### Steps to Reproduce\r\n\r\n1. Login as region user (not superadmin or staff)\r\n2. Click on Pages\r\n4. See error\r\n\r\n### Expected Behavior\r\n<!-- A clear and concise description of what you expected to happen. -->\r\nThe page tree should appear\r\n\r\n### Actual Behavior\r\n<!-- A clear and concise description of what actually happened. -->\r\nThe following error appears:\r\n```\r\nAttributeError at /augsburg/pages/de-de/\r\n\r\n'NoneType' object has no attribute 'region'\r\n```\r\n\r\n### Additional Information\r\n<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->\r\nThe error arises because `page.region` is accessed, even if no page is supplied:\r\n```\r\nif page.region not in user.profile.regions.all():\r\n    return False\r\n```\r\nWe have two possibilities here:\r\n1. somehow inject the current region into the rule predicate and use this instead of `page.region`\r\n2. Rely on the fact that the region permissions are checked elsewhere. E.g. the user can't open a page form in another region than he belongs to (this is already checked by the `@method_decorator(region_permission_required, name=\"dispatch\")` in the page form) and a page form can only be used to edit pages of the current region (this is alredy checked by `page = region.pages.filter(id=kwargs.get(\"page_id\")).first()`). So in theory, the check might not be necessary altogether, or am I missing something?\r\n\r\n<details>\r\n  <summary>Debug Information</summary>\r\n  \r\nEnvironment:\r\n\r\n\r\nRequest Method: GET\r\nRequest URL: http://localhost:8000/augsburg/pages/de-de/\r\n\r\nDjango Version: 2.2.16\r\nPython Version: 3.7.9\r\nInstalled Applications:\r\n['cms.apps.CmsConfig',\r\n 'gvz_api.apps.GvzApiConfig',\r\n 'django.contrib.admin',\r\n 'django.contrib.auth',\r\n 'django.contrib.contenttypes',\r\n 'django.contrib.messages',\r\n 'django.contrib.sessions',\r\n 'django.contrib.sitemaps',\r\n 'django.contrib.staticfiles',\r\n 'compressor',\r\n 'compressor_toolkit',\r\n 'corsheaders',\r\n 'widget_tweaks',\r\n 'easy_thumbnails',\r\n 'filer',\r\n 'mptt',\r\n 'rules.apps.AutodiscoverRulesConfig']\r\nInstalled Middleware:\r\n['corsheaders.middleware.CorsMiddleware',\r\n 'django.middleware.security.SecurityMiddleware',\r\n 'django.contrib.sessions.middleware.SessionMiddleware',\r\n 'django.middleware.locale.LocaleMiddleware',\r\n 'django.middleware.common.CommonMiddleware',\r\n 'django.middleware.csrf.CsrfViewMiddleware',\r\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n 'django.contrib.messages.middleware.MessageMiddleware',\r\n 'django.middleware.clickjacking.XFrameOptionsMiddleware']\r\n\r\n\r\n\r\nTraceback:\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/exception.py\" in inner\r\n  34.             response = get_response(request)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/base.py\" in _get_response\r\n  115.                 response = self.process_exception_by_middleware(e, request)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/core/handlers/base.py\" in _get_response\r\n  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/views/generic/base.py\" in view\r\n  71.             return self.dispatch(request, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/utils/decorators.py\" in _wrapper\r\n  45.         return bound_method(*args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py\" in _wrapped_view\r\n  21.                 return view_func(request, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/utils/decorators.py\" in _wrapper\r\n  45.         return bound_method(*args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/src/cms/decorators.py\" in wrap\r\n  56.             return function(request, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/mixins.py\" in dispatch\r\n  85.         return super().dispatch(request, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/views/generic/base.py\" in dispatch\r\n  97.         return handler(request, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/src/cms/views/pages/page_tree_view.py\" in get\r\n  56.         if not request.user.has_perm(\"cms.edit_page\"):\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/models.py\" in has_perm\r\n  268.         return _user_has_perm(self, perm, obj)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/django/contrib/auth/models.py\" in _user_has_perm\r\n  182.             if backend.has_perm(user, perm, obj):\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/permissions.py\" in has_perm\r\n  32.         return has_perm(perm, user, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/permissions.py\" in has_perm\r\n  24.     return permissions.test_rule(name, *args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/rulesets.py\" in test_rule\r\n  6.         return name in self and self[name].test(*args, **kwargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in test\r\n  154.             return bool(self._apply(*args))\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _apply\r\n  213.         result = self.fn(*callargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in OR\r\n  165.             return self._combine(other, operator.or_, args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _combine\r\n  184.         self_result = self._apply(*args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _apply\r\n  213.         result = self.fn(*callargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in OR\r\n  165.             return self._combine(other, operator.or_, args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _combine\r\n  184.         self_result = self._apply(*args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _apply\r\n  213.         result = self.fn(*callargs)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in OR\r\n  165.             return self._combine(other, operator.or_, args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _combine\r\n  184.         self_result = self._apply(*args)\r\n\r\nFile \"/home/timo/job/integreat/django/.venv/lib/python3.7/site-packages/rules/predicates.py\" in _apply\r\n  213.         result = self.fn(*callargs)\r\n\r\nFile \"/home/timo/job/integreat/django/src/cms/rules.py\" in can_edit_all_pages\r\n  79.         if page.region not in user.profile.regions.all():\r\n\r\nException Type: AttributeError at /augsburg/pages/de-de/\r\nException Value: 'NoneType' object has no attribute 'region'\r\n\r\n  \r\n</details>\n", "before_files": [{"content": "\"\"\"\nWe use `django-rules <https://pypi.org/project/rules/>`_ to add custom permissions for specific pages.\n\nFor a given user and page, the following permissions are added:\n\n* ``cms.edit_page`` if one of the following predicates return true:\n\n    * :func:`~cms.rules.can_edit_all_pages`\n    * :func:`~cms.rules.is_page_editor`\n    * :func:`~cms.rules.can_publish_all_pages`\n    * :func:`~cms.rules.is_page_publisher`\n\n* ``cms.publish_page`` if one of the following predicates return true:\n\n    * :func:`~cms.rules.can_publish_all_pages`\n    * :func:`~cms.rules.is_page_publisher`\n\nSee the project's `README <https://github.com/dfunckt/django-rules/blob/master/README.rst>`_ to learn more.\n\"\"\"\nfrom rules import add_perm, predicate\n\n\n# Predicates\n\n\n@predicate\ndef is_page_editor(user, page):\n    \"\"\"\n    This predicate checks whether the given user is one of the editors of the given page.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The requested page\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` is an editor of ``page``\n    :rtype: bool\n    \"\"\"\n    if not page:\n        return False\n    return user in page.editors.all()\n\n\n@predicate\ndef is_page_publisher(user, page):\n    \"\"\"\n    This predicate checks whether the given user is one of the publishers of the given page.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The requested page\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` is a publisher of ``page``\n    :rtype: bool\n    \"\"\"\n    if not page:\n        return False\n    return user in page.publishers.all()\n\n\n@predicate\ndef can_edit_all_pages(user, page):\n    \"\"\"\n    This predicate checks whether the given user can edit all pages.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The page parameter is used for the region check\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` can edit all pages\n    :rtype: bool\n    \"\"\"\n    if not (user.is_superuser or user.is_staff):\n        if page.region not in user.profile.regions.all():\n            return False\n    return user.has_perm(\"cms.edit_pages\")\n\n\n@predicate\ndef can_publish_all_pages(user, page):\n    \"\"\"\n    This predicate checks whether the given user can publish all pages.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The page parameter is used for the region check\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` can publish all pages\n    :rtype: bool\n    \"\"\"\n    if not (user.is_superuser or user.is_staff):\n        if page.region not in user.profile.regions.all():\n            return False\n    return user.has_perm(\"cms.publish_pages\")\n\n\n# Permissions\n\nadd_perm(\n    \"cms.edit_page\",\n    can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher,\n)\nadd_perm(\"cms.publish_page\", can_publish_all_pages | is_page_publisher)\n", "path": "src/cms/rules.py"}], "after_files": [{"content": "\"\"\"\nWe use `django-rules <https://pypi.org/project/rules/>`_ to add custom permissions for specific pages.\n\nFor a given user and page, the following permissions are added:\n\n* ``cms.edit_page`` if one of the following predicates return true:\n\n    * :func:`~cms.rules.can_edit_all_pages`\n    * :func:`~cms.rules.is_page_editor`\n    * :func:`~cms.rules.can_publish_all_pages`\n    * :func:`~cms.rules.is_page_publisher`\n\n* ``cms.publish_page`` if one of the following predicates return true:\n\n    * :func:`~cms.rules.can_publish_all_pages`\n    * :func:`~cms.rules.is_page_publisher`\n\nSee the project's `README <https://github.com/dfunckt/django-rules/blob/master/README.rst>`_ to learn more.\n\"\"\"\nfrom rules import add_perm, predicate\n\n\n# Predicates\n\n\n@predicate\ndef is_page_editor(user, page):\n    \"\"\"\n    This predicate checks whether the given user is one of the editors of the given page.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The requested page\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` is an editor of ``page``\n    :rtype: bool\n    \"\"\"\n    if not page:\n        return False\n    return user in page.editors.all()\n\n\n@predicate\ndef is_page_publisher(user, page):\n    \"\"\"\n    This predicate checks whether the given user is one of the publishers of the given page.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The requested page\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` is a publisher of ``page``\n    :rtype: bool\n    \"\"\"\n    if not page:\n        return False\n    return user in page.publishers.all()\n\n\n@predicate\ndef can_edit_all_pages(user, page):\n    \"\"\"\n    This predicate checks whether the given user can edit all pages.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The page parameter is used for the region check\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` can edit all pages\n    :rtype: bool\n    \"\"\"\n    if not (user.is_superuser or user.is_staff):\n        if page and page.region not in user.profile.regions.all():\n            return False\n    return user.has_perm(\"cms.edit_pages\")\n\n\n@predicate\ndef can_publish_all_pages(user, page):\n    \"\"\"\n    This predicate checks whether the given user can publish all pages.\n\n    :param user: The user who's permission should be checked\n    :type user: ~django.contrib.auth.models.User\n\n    :param page: The page parameter is used for the region check\n    :type page: ~cms.models.pages.page.Page\n\n    :return: Whether or not ``user`` can publish all pages\n    :rtype: bool\n    \"\"\"\n    if not (user.is_superuser or user.is_staff):\n        if page and page.region not in user.profile.regions.all():\n            return False\n    return user.has_perm(\"cms.publish_pages\")\n\n\n# Permissions\n\nadd_perm(\n    \"cms.edit_page\",\n    can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher,\n)\nadd_perm(\"cms.publish_page\", can_publish_all_pages | is_page_publisher)\n", "path": "src/cms/rules.py"}]}