Repository: Kinto/kinto

Issue:
HTTP 500 while fetching the permission endpoint using the account plugin.
Error while fetching the permissions endpoint using the account plugin.

```
  File "~/kinto/venv/lib/python3.6/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/core/resource/__init__.py", line 290, in collection_get
    include_deleted=include_deleted)
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/views/permissions.py", line 84, in get_records
    from_settings = allowed_from_settings(self.request.registry.settings, principals)
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/views/permissions.py", line 46, in allowed_from_settings
    'record': 'collection'}[resource_name]
KeyError: 'account'
```
HTTP 500 while fetching the permission endpoint using the account plugin.
Error while fetching the permissions endpoint using the account plugin.

```
  File "~/kinto/venv/lib/python3.6/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/core/resource/__init__.py", line 290, in collection_get
    include_deleted=include_deleted)
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/views/permissions.py", line 84, in get_records
    from_settings = allowed_from_settings(self.request.registry.settings, principals)
  File "~/kinto/venv/lib/python3.6/site-packages/kinto/views/permissions.py", line 46, in allowed_from_settings
    'record': 'collection'}[resource_name]
KeyError: 'account'
```


Discussion:

Resolving patch:
diff --git a/kinto/views/permissions.py b/kinto/views/permissions.py
--- a/kinto/views/permissions.py
+++ b/kinto/views/permissions.py
@@ -40,10 +40,9 @@ def allowed_from_settings(settings, principals):
                 resource_name=resource_name,
                 permission=permission)
             resource_name = {  # resource parents.
-                'bucket': '',
                 'collection': 'bucket',
                 'group': 'bucket',
-                'record': 'collection'}[resource_name]
+                'record': 'collection'}.get(resource_name, '')
         # Store them in a convenient way.
         from_settings.setdefault(resource_name, set()).add(permission)
     return from_settings


Test patch:
diff --git a/tests/plugins/test_accounts.py b/tests/plugins/test_accounts.py
--- a/tests/plugins/test_accounts.py
+++ b/tests/plugins/test_accounts.py
@@ -182,6 +182,29 @@ def test_cannot_obtain_unknown_account(self):
                      status=403)
 
 
+class PermissionsEndpointTest(AccountsWebTest):
+    @classmethod
+    def get_app_settings(cls, extras=None):
+        settings = super().get_app_settings(extras)
+        settings['experimental_permissions_endpoint'] = 'True'
+        return settings
+
+    def setUp(self):
+        self.app.put_json('/accounts/alice', {'data': {'password': '123456'}}, status=201)
+        self.headers = get_user_headers('alice', '123456')
+        self.app.put('/buckets/a', headers=self.headers)
+        self.app.put('/buckets/a/collections/b', headers=self.headers)
+        self.app.put('/buckets/a/collections/b/records/c', headers=self.headers)
+
+    def test_permissions_endpoint_is_compatible_with_accounts_plugin(self):
+        resp = self.app.get('/permissions', headers=self.headers)
+        uris = [r["uri"] for r in resp.json["data"]]
+        assert uris == ['/buckets/a/collections/b/records/c',
+                        '/buckets/a/collections/b',
+                        '/buckets/a',
+                        '/accounts/alice']
+
+
 class AdminTest(AccountsWebTest):
 
     @classmethod