We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix capabilities bug
At the moment the button "Create Page" disapears for every role except the superuser.
![image](https://user-images.githubusercontent.com/15608678/84593767-1dde2000-ae4e-11ea-858b-be5d7bf4dded.png)

Fix capabilities bug
At the moment the button "Create Page" disapears for every role except the superuser.
![image](https://user-images.githubusercontent.com/15608678/84593767-1dde2000-ae4e-11ea-858b-be5d7bf4dded.png)


--- 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/views/pages/page_view.py`
Content:
```
1 """
2 
3 Returns:
4     [type]: [description]
5 """
6 import logging
7 
8 from django.contrib import messages
9 from django.contrib.auth.decorators import login_required
10 from django.contrib.auth.mixins import PermissionRequiredMixin
11 from django.core.exceptions import PermissionDenied
12 from django.shortcuts import render, redirect
13 from django.utils.decorators import method_decorator
14 from django.utils.translation import ugettext as _
15 from django.views.generic import TemplateView
16 
17 from ...constants import status
18 from ...decorators import region_permission_required
19 from ...forms.pages import PageForm, PageTranslationForm
20 from ...models import Page, PageTranslation, Region, Language
21 
22 logger = logging.getLogger(__name__)
23 
24 
25 @method_decorator(login_required, name='dispatch')
26 @method_decorator(region_permission_required, name='dispatch')
27 class PageView(PermissionRequiredMixin, TemplateView):
28     permission_required = 'cms.view_pages'
29     raise_exception = True
30 
31     template_name = 'pages/page_form.html'
32     base_context = {
33         'current_menu_item': 'pages',
34         'PUBLIC': status.PUBLIC
35     }
36 
37     def get(self, request, *args, **kwargs):
38 
39         region = Region.objects.get(slug=kwargs.get('region_slug'))
40 
41         language = Language.objects.get(code=kwargs.get('language_code'))
42 
43         # get page and translation objects if they exist
44         page = Page.objects.filter(id=kwargs.get('page_id')).first()
45         page_translation = PageTranslation.objects.filter(
46             page=page,
47             language=language,
48         ).first()
49 
50         # Make form disabled if user has no permission to edit the page
51         if not request.user.has_perm('cms.edit_page', page):
52             disabled = True
53             messages.warning(request, _("You don't have the permission to edit this page."))
54         elif page and page.archived:
55             disabled = True
56             messages.warning(request, _("You cannot edit this page because it is archived."))
57         else:
58             disabled = False
59 
60         page_form = PageForm(
61             instance=page,
62             region=region,
63             language=language,
64             disabled=disabled
65         )
66         page_translation_form = PageTranslationForm(
67             instance=page_translation,
68             disabled=disabled
69         )
70 
71         return render(request, self.template_name, {
72             **self.base_context,
73             'page_form': page_form,
74             'page_translation_form': page_translation_form,
75             'page': page,
76             'language': language,
77             # Languages for tab view
78             'languages': region.languages if page else [language],
79         })
80 
81     # pylint: disable=too-many-branches,unused-argument
82     def post(self, request, *args, **kwargs):
83 
84         region = Region.objects.get(slug=kwargs.get('region_slug'))
85         language = Language.objects.get(code=kwargs.get('language_code'))
86 
87         page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()
88         page_translation_instance = PageTranslation.objects.filter(
89             page=page_instance,
90             language=language,
91         ).first()
92 
93         if not request.user.has_perm('cms.edit_page', page_instance):
94             raise PermissionDenied
95 
96         page_form = PageForm(
97             request.POST,
98             instance=page_instance,
99             region=region,
100             language=language,
101         )
102         page_translation_form = PageTranslationForm(
103             request.POST,
104             instance=page_translation_instance,
105             region=region,
106             language=language,
107         )
108 
109         if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:
110             if not request.user.has_perm('cms.publish_page', page_instance):
111                 raise PermissionDenied
112 
113         # TODO: error handling
114         if not page_form.is_valid() or not page_translation_form.is_valid():
115             messages.error(request, _('Errors have occurred.'))
116             return render(request, self.template_name, {
117                 **self.base_context,
118                 'page_form': page_form,
119                 'page_translation_form': page_translation_form,
120                 'page': page_instance,
121                 'language': language,
122                 # Languages for tab view
123                 'languages': region.languages if page_instance else [language],
124             })
125 
126         if not page_form.has_changed() and not page_translation_form.has_changed():
127             messages.info(request, _('No changes detected.'))
128             return render(request, self.template_name, {
129                 **self.base_context,
130                 'page_form': page_form,
131                 'page_translation_form': page_translation_form,
132                 'page': page_instance,
133                 'language': language,
134                 # Languages for tab view
135                 'languages': region.languages if page_instance else [language],
136             })
137 
138         page = page_form.save()
139         page_translation = page_translation_form.save(
140             page=page,
141             user=request.user,
142         )
143 
144         published = page_translation.status == status.PUBLIC
145         if not page_instance:
146             if published:
147                 messages.success(request, _('Page was successfully created and published.'))
148             else:
149                 messages.success(request, _('Page was successfully created.'))
150         elif not page_translation_instance:
151             if published:
152                 messages.success(request, _('Translation was successfully created and published.'))
153             else:
154                 messages.success(request, _('Translation was successfully created.'))
155         else:
156             if published:
157                 messages.success(request, _('Translation was successfully published.'))
158             else:
159                 messages.success(request, _('Translation was successfully saved.'))
160 
161         return redirect('edit_page', **{
162             'page_id': page.id,
163             'region_slug': region.slug,
164             'language_code': language.code,
165         })
166
```

Path: `src/cms/rules.py`
Content:
```
1 from rules import add_perm, predicate
2 
3 
4 # Predicates
5 
6 @predicate
7 def is_page_editor(user, page):
8     if not page:
9         return False
10     return user in page.editors.all()
11 
12 @predicate
13 def is_page_publisher(user, page):
14     if not page:
15         return False
16     return user in page.publishers.all()
17 
18 @predicate
19 # pylint: disable=unused-argument
20 def can_edit_all_pages(user, page):
21     return user.has_perm('edit_pages')
22 
23 @predicate
24 # pylint: disable=unused-argument
25 def can_publish_all_pages(user, page):
26     return user.has_perm('publish_pages')
27 
28 
29 # Permissions
30 
31 add_perm('cms.edit_page', can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher)
32 add_perm('cms.publish_page', can_publish_all_pages | is_page_publisher)
33
```
--- 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
@@ -18,12 +18,12 @@
 @predicate
 # pylint: disable=unused-argument
 def can_edit_all_pages(user, page):
-    return user.has_perm('edit_pages')
+    return user.has_perm('cms.edit_pages')
 
 @predicate
 # pylint: disable=unused-argument
 def can_publish_all_pages(user, page):
-    return user.has_perm('publish_pages')
+    return user.has_perm('cms.publish_pages')
 
 
 # Permissions
diff --git a/src/cms/views/pages/page_view.py b/src/cms/views/pages/page_view.py
--- a/src/cms/views/pages/page_view.py
+++ b/src/cms/views/pages/page_view.py
@@ -48,14 +48,17 @@
         ).first()
 
         # Make form disabled if user has no permission to edit the page
-        if not request.user.has_perm('cms.edit_page', page):
-            disabled = True
-            messages.warning(request, _("You don't have the permission to edit this page."))
-        elif page and page.archived:
-            disabled = True
-            messages.warning(request, _("You cannot edit this page because it is archived."))
+        disabled = False
+        if page:
+            if page.archived:
+                disabled = True
+                messages.warning(request, _("You cannot edit this page because it is archived."))
+            elif not request.user.has_perm('cms.edit_page', page):
+                disabled = True
+                messages.warning(request, _("You don't have the permission to edit this page, but you can propose changes and submit them for review instead."))
         else:
-            disabled = False
+            if not request.user.has_perm('cms.edit_pages'):
+                raise PermissionDenied
 
         page_form = PageForm(
             instance=page,

{"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@@ -18,12 +18,12 @@\n @predicate\n # pylint: disable=unused-argument\n def can_edit_all_pages(user, page):\n-    return user.has_perm('edit_pages')\n+    return user.has_perm('cms.edit_pages')\n \n @predicate\n # pylint: disable=unused-argument\n def can_publish_all_pages(user, page):\n-    return user.has_perm('publish_pages')\n+    return user.has_perm('cms.publish_pages')\n \n \n # Permissions\ndiff --git a/src/cms/views/pages/page_view.py b/src/cms/views/pages/page_view.py\n--- a/src/cms/views/pages/page_view.py\n+++ b/src/cms/views/pages/page_view.py\n@@ -48,14 +48,17 @@\n         ).first()\n \n         # Make form disabled if user has no permission to edit the page\n-        if not request.user.has_perm('cms.edit_page', page):\n-            disabled = True\n-            messages.warning(request, _(\"You don't have the permission to edit this page.\"))\n-        elif page and page.archived:\n-            disabled = True\n-            messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n+        disabled = False\n+        if page:\n+            if page.archived:\n+                disabled = True\n+                messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n+            elif not request.user.has_perm('cms.edit_page', page):\n+                disabled = True\n+                messages.warning(request, _(\"You don't have the permission to edit this page, but you can propose changes and submit them for review instead.\"))\n         else:\n-            disabled = False\n+            if not request.user.has_perm('cms.edit_pages'):\n+                raise PermissionDenied\n \n         page_form = PageForm(\n             instance=page,\n", "issue": "Fix capabilities bug\nAt the moment the button \"Create Page\" disapears for every role except the superuser.\r\n![image](https://user-images.githubusercontent.com/15608678/84593767-1dde2000-ae4e-11ea-858b-be5d7bf4dded.png)\r\n\nFix capabilities bug\nAt the moment the button \"Create Page\" disapears for every role except the superuser.\r\n![image](https://user-images.githubusercontent.com/15608678/84593767-1dde2000-ae4e-11ea-858b-be5d7bf4dded.png)\r\n\n", "before_files": [{"content": "\"\"\"\n\nReturns:\n    [type]: [description]\n\"\"\"\nimport logging\n\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\nfrom ...constants import status\nfrom ...decorators import region_permission_required\nfrom ...forms.pages import PageForm, PageTranslationForm\nfrom ...models import Page, PageTranslation, Region, Language\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(login_required, name='dispatch')\n@method_decorator(region_permission_required, name='dispatch')\nclass PageView(PermissionRequiredMixin, TemplateView):\n    permission_required = 'cms.view_pages'\n    raise_exception = True\n\n    template_name = 'pages/page_form.html'\n    base_context = {\n        'current_menu_item': 'pages',\n        'PUBLIC': status.PUBLIC\n    }\n\n    def get(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        # get page and translation objects if they exist\n        page = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation = PageTranslation.objects.filter(\n            page=page,\n            language=language,\n        ).first()\n\n        # Make form disabled if user has no permission to edit the page\n        if not request.user.has_perm('cms.edit_page', page):\n            disabled = True\n            messages.warning(request, _(\"You don't have the permission to edit this page.\"))\n        elif page and page.archived:\n            disabled = True\n            messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n        else:\n            disabled = False\n\n        page_form = PageForm(\n            instance=page,\n            region=region,\n            language=language,\n            disabled=disabled\n        )\n        page_translation_form = PageTranslationForm(\n            instance=page_translation,\n            disabled=disabled\n        )\n\n        return render(request, self.template_name, {\n            **self.base_context,\n            'page_form': page_form,\n            'page_translation_form': page_translation_form,\n            'page': page,\n            'language': language,\n            # Languages for tab view\n            'languages': region.languages if page else [language],\n        })\n\n    # pylint: disable=too-many-branches,unused-argument\n    def post(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation_instance = PageTranslation.objects.filter(\n            page=page_instance,\n            language=language,\n        ).first()\n\n        if not request.user.has_perm('cms.edit_page', page_instance):\n            raise PermissionDenied\n\n        page_form = PageForm(\n            request.POST,\n            instance=page_instance,\n            region=region,\n            language=language,\n        )\n        page_translation_form = PageTranslationForm(\n            request.POST,\n            instance=page_translation_instance,\n            region=region,\n            language=language,\n        )\n\n        if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:\n            if not request.user.has_perm('cms.publish_page', page_instance):\n                raise PermissionDenied\n\n        # TODO: error handling\n        if not page_form.is_valid() or not page_translation_form.is_valid():\n            messages.error(request, _('Errors have occurred.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        if not page_form.has_changed() and not page_translation_form.has_changed():\n            messages.info(request, _('No changes detected.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        page = page_form.save()\n        page_translation = page_translation_form.save(\n            page=page,\n            user=request.user,\n        )\n\n        published = page_translation.status == status.PUBLIC\n        if not page_instance:\n            if published:\n                messages.success(request, _('Page was successfully created and published.'))\n            else:\n                messages.success(request, _('Page was successfully created.'))\n        elif not page_translation_instance:\n            if published:\n                messages.success(request, _('Translation was successfully created and published.'))\n            else:\n                messages.success(request, _('Translation was successfully created.'))\n        else:\n            if published:\n                messages.success(request, _('Translation was successfully published.'))\n            else:\n                messages.success(request, _('Translation was successfully saved.'))\n\n        return redirect('edit_page', **{\n            'page_id': page.id,\n            'region_slug': region.slug,\n            'language_code': language.code,\n        })\n", "path": "src/cms/views/pages/page_view.py"}, {"content": "from rules import add_perm, predicate\n\n\n# Predicates\n\n@predicate\ndef is_page_editor(user, page):\n    if not page:\n        return False\n    return user in page.editors.all()\n\n@predicate\ndef is_page_publisher(user, page):\n    if not page:\n        return False\n    return user in page.publishers.all()\n\n@predicate\n# pylint: disable=unused-argument\ndef can_edit_all_pages(user, page):\n    return user.has_perm('edit_pages')\n\n@predicate\n# pylint: disable=unused-argument\ndef can_publish_all_pages(user, page):\n    return user.has_perm('publish_pages')\n\n\n# Permissions\n\nadd_perm('cms.edit_page', can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher)\nadd_perm('cms.publish_page', can_publish_all_pages | is_page_publisher)\n", "path": "src/cms/rules.py"}], "after_files": [{"content": "\"\"\"\n\nReturns:\n    [type]: [description]\n\"\"\"\nimport logging\n\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\nfrom ...constants import status\nfrom ...decorators import region_permission_required\nfrom ...forms.pages import PageForm, PageTranslationForm\nfrom ...models import Page, PageTranslation, Region, Language\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(login_required, name='dispatch')\n@method_decorator(region_permission_required, name='dispatch')\nclass PageView(PermissionRequiredMixin, TemplateView):\n    permission_required = 'cms.view_pages'\n    raise_exception = True\n\n    template_name = 'pages/page_form.html'\n    base_context = {\n        'current_menu_item': 'pages',\n        'PUBLIC': status.PUBLIC\n    }\n\n    def get(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        # get page and translation objects if they exist\n        page = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation = PageTranslation.objects.filter(\n            page=page,\n            language=language,\n        ).first()\n\n        # Make form disabled if user has no permission to edit the page\n        disabled = False\n        if page:\n            if page.archived:\n                disabled = True\n                messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n            elif not request.user.has_perm('cms.edit_page', page):\n                disabled = True\n                messages.warning(request, _(\"You don't have the permission to edit this page, but you can propose changes and submit them for review instead.\"))\n        else:\n            if not request.user.has_perm('cms.edit_pages'):\n                raise PermissionDenied\n\n        page_form = PageForm(\n            instance=page,\n            region=region,\n            language=language,\n            disabled=disabled\n        )\n        page_translation_form = PageTranslationForm(\n            instance=page_translation,\n            disabled=disabled\n        )\n\n        return render(request, self.template_name, {\n            **self.base_context,\n            'page_form': page_form,\n            'page_translation_form': page_translation_form,\n            'page': page,\n            'language': language,\n            # Languages for tab view\n            'languages': region.languages if page else [language],\n        })\n\n    # pylint: disable=too-many-branches,unused-argument\n    def post(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation_instance = PageTranslation.objects.filter(\n            page=page_instance,\n            language=language,\n        ).first()\n\n        if not request.user.has_perm('cms.edit_page', page_instance):\n            raise PermissionDenied\n\n        page_form = PageForm(\n            request.POST,\n            instance=page_instance,\n            region=region,\n            language=language,\n        )\n        page_translation_form = PageTranslationForm(\n            request.POST,\n            instance=page_translation_instance,\n            region=region,\n            language=language,\n        )\n\n        if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:\n            if not request.user.has_perm('cms.publish_page', page_instance):\n                raise PermissionDenied\n\n        # TODO: error handling\n        if not page_form.is_valid() or not page_translation_form.is_valid():\n            messages.error(request, _('Errors have occurred.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        if not page_form.has_changed() and not page_translation_form.has_changed():\n            messages.info(request, _('No changes detected.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        page = page_form.save()\n        page_translation = page_translation_form.save(\n            page=page,\n            user=request.user,\n        )\n\n        published = page_translation.status == status.PUBLIC\n        if not page_instance:\n            if published:\n                messages.success(request, _('Page was successfully created and published.'))\n            else:\n                messages.success(request, _('Page was successfully created.'))\n        elif not page_translation_instance:\n            if published:\n                messages.success(request, _('Translation was successfully created and published.'))\n            else:\n                messages.success(request, _('Translation was successfully created.'))\n        else:\n            if published:\n                messages.success(request, _('Translation was successfully published.'))\n            else:\n                messages.success(request, _('Translation was successfully saved.'))\n\n        return redirect('edit_page', **{\n            'page_id': page.id,\n            'region_slug': region.slug,\n            'language_code': language.code,\n        })\n", "path": "src/cms/views/pages/page_view.py"}, {"content": "from rules import add_perm, predicate\n\n\n# Predicates\n\n@predicate\ndef is_page_editor(user, page):\n    if not page:\n        return False\n    return user in page.editors.all()\n\n@predicate\ndef is_page_publisher(user, page):\n    if not page:\n        return False\n    return user in page.publishers.all()\n\n@predicate\n# pylint: disable=unused-argument\ndef can_edit_all_pages(user, page):\n    return user.has_perm('cms.edit_pages')\n\n@predicate\n# pylint: disable=unused-argument\ndef can_publish_all_pages(user, page):\n    return user.has_perm('cms.publish_pages')\n\n\n# Permissions\n\nadd_perm('cms.edit_page', can_edit_all_pages | is_page_editor | can_publish_all_pages | is_page_publisher)\nadd_perm('cms.publish_page', can_publish_all_pages | is_page_publisher)\n", "path": "src/cms/rules.py"}]}