prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Metadata on Groups
  Similarily to how you can store extra properties (metadata) on a collection, it would be useful to be able to do this with groups.
  
  In my applications, almost everything is dynamic. Users can create groups on the fly, rename them, etc., so I tend to use generated ID's for everything. It would be nice to be able to set a title and description on groups for UI presentation.
  
  Right now I have to create a collection for storing group metadata separately from the actual group.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `kinto/__init__.py`
  Content:
  ```
  1 import pkg_resources
  2 import logging
  3 
  4 import cliquet
  5 from pyramid.config import Configurator
  6 from pyramid.settings import asbool
  7 from pyramid.security import Authenticated
  8 
  9 from kinto.authorization import RouteFactory
  10 
  11 # Module version, as defined in PEP-0396.
  12 __version__ = pkg_resources.get_distribution(__package__).version
  13 
  14 # Implemented HTTP API Version
  15 HTTP_API_VERSION = '1.4'
  16 
  17 # Main kinto logger
  18 logger = logging.getLogger(__name__)
  19 
  20 
  21 DEFAULT_SETTINGS = {
  22     'retry_after_seconds': 3,
  23     'cache_backend': 'cliquet.cache.memory',
  24     'permission_backend': 'cliquet.permission.memory',
  25     'storage_backend': 'cliquet.storage.memory',
  26     'project_docs': 'https://kinto.readthedocs.org/',
  27     'bucket_create_principals': Authenticated,
  28     'multiauth.authorization_policy': (
  29         'kinto.authorization.AuthorizationPolicy'),
  30     'experimental_collection_schema_validation': 'False',
  31     'http_api_version': HTTP_API_VERSION
  32 }
  33 
  34 
  35 def main(global_config, config=None, **settings):
  36     if not config:
  37         config = Configurator(settings=settings, root_factory=RouteFactory)
  38 
  39     # Force project name, since it determines settings prefix.
  40     config.add_settings({'cliquet.project_name': 'kinto'})
  41 
  42     cliquet.initialize(config,
  43                        version=__version__,
  44                        default_settings=DEFAULT_SETTINGS)
  45 
  46     settings = config.get_settings()
  47 
  48     # Retro-compatibility with first Kinto clients.
  49     config.registry.public_settings.add('cliquet.batch_max_requests')
  50 
  51     # Expose capability
  52     schema_enabled = asbool(
  53         settings['experimental_collection_schema_validation']
  54     )
  55     if schema_enabled:
  56         config.add_api_capability(
  57             "schema",
  58             description="Validates collection records with JSON schemas.",
  59             url="http://kinto.readthedocs.org/en/latest/api/1.x/"
  60                 "collections.html#collection-json-schema")
  61 
  62     # Scan Kinto views.
  63     kwargs = {}
  64     flush_enabled = asbool(settings.get('flush_endpoint_enabled'))
  65 
  66     if flush_enabled:
  67         config.add_api_capability(
  68             "flush_endpoint",
  69             description="The __flush__ endpoint can be used to remove all "
  70                         "data from all backends.",
  71             url="http://kinto.readthedocs.org/en/latest/configuration/"
  72                 "settings.html#activating-the-flush-endpoint"
  73         )
  74     else:
  75         kwargs['ignore'] = 'kinto.views.flush'
  76     config.scan("kinto.views", **kwargs)
  77 
  78     app = config.make_wsgi_app()
  79 
  80     # Install middleware (idempotent if disabled)
  81     return cliquet.install_middlewares(app, settings)
  82
  ```
  
  Path: `kinto/views/groups.py`
  Content:
  ```
  1 import colander
  2 
  3 from cliquet import resource
  4 from cliquet.events import ResourceChanged, ACTIONS
  5 from pyramid.events import subscriber
  6 
  7 from kinto.views import NameGenerator
  8 
  9 
  10 class GroupSchema(resource.ResourceSchema):
  11     members = colander.SchemaNode(colander.Sequence(),
  12                                   colander.SchemaNode(colander.String()))
  13 
  14 
  15 @resource.register(name='group',
  16                    collection_path='/buckets/{{bucket_id}}/groups',
  17                    record_path='/buckets/{{bucket_id}}/groups/{{id}}')
  18 class Group(resource.ShareableResource):
  19 
  20     mapping = GroupSchema()
  21 
  22     def __init__(self, *args, **kwargs):
  23         super(Group, self).__init__(*args, **kwargs)
  24         self.model.id_generator = NameGenerator()
  25 
  26     def get_parent_id(self, request):
  27         bucket_id = request.matchdict['bucket_id']
  28         parent_id = '/buckets/%s' % bucket_id
  29         return parent_id
  30 
  31 
  32 @subscriber(ResourceChanged,
  33             for_resources=('group',),
  34             for_actions=(ACTIONS.DELETE,))
  35 def on_groups_deleted(event):
  36     """Some groups were deleted, remove them from users principals.
  37     """
  38     permission_backend = event.request.registry.permission
  39 
  40     for change in event.impacted_records:
  41         group = change['old']
  42         group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],
  43                                                               **event.payload)
  44         permission_backend.remove_principal(group_uri)
  45 
  46 
  47 @subscriber(ResourceChanged,
  48             for_resources=('group',),
  49             for_actions=(ACTIONS.CREATE, ACTIONS.UPDATE))
  50 def on_groups_changed(event):
  51     """Some groups were changed, update users principals.
  52     """
  53     permission_backend = event.request.registry.permission
  54 
  55     for change in event.impacted_records:
  56         if 'old' in change:
  57             existing_record_members = set(change['old'].get('members', []))
  58         else:
  59             existing_record_members = set()
  60 
  61         group = change['new']
  62         group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],
  63                                                               **event.payload)
  64         new_record_members = set(group.get('members', []))
  65         new_members = new_record_members - existing_record_members
  66         removed_members = existing_record_members - new_record_members
  67 
  68         for member in new_members:
  69             # Add the group to the member principal.
  70             permission_backend.add_user_principal(member, group_uri)
  71 
  72         for member in removed_members:
  73             # Remove the group from the member principal.
  74             permission_backend.remove_user_principal(member, group_uri)
  75
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/kinto/__init__.py b/kinto/__init__.py
  --- a/kinto/__init__.py
  +++ b/kinto/__init__.py
  @@ -12,7 +12,7 @@
   __version__ = pkg_resources.get_distribution(__package__).version
   
   # Implemented HTTP API Version
  -HTTP_API_VERSION = '1.4'
  +HTTP_API_VERSION = '1.5'
   
   # Main kinto logger
   logger = logging.getLogger(__name__)
  diff --git a/kinto/views/groups.py b/kinto/views/groups.py
  --- a/kinto/views/groups.py
  +++ b/kinto/views/groups.py
  @@ -11,6 +11,9 @@
       members = colander.SchemaNode(colander.Sequence(),
                                     colander.SchemaNode(colander.String()))
   
  +    class Options:
  +        preserve_unknown = True
  +
   
   @resource.register(name='group',
                      collection_path='/buckets/{{bucket_id}}/groups',
  
verification_info: {"golden_diff": "diff --git a/kinto/__init__.py b/kinto/__init__.py\n--- a/kinto/__init__.py\n+++ b/kinto/__init__.py\n@@ -12,7 +12,7 @@\n __version__ = pkg_resources.get_distribution(__package__).version\n \n # Implemented HTTP API Version\n-HTTP_API_VERSION = '1.4'\n+HTTP_API_VERSION = '1.5'\n \n # Main kinto logger\n logger = logging.getLogger(__name__)\ndiff --git a/kinto/views/groups.py b/kinto/views/groups.py\n--- a/kinto/views/groups.py\n+++ b/kinto/views/groups.py\n@@ -11,6 +11,9 @@\n     members = colander.SchemaNode(colander.Sequence(),\n                                   colander.SchemaNode(colander.String()))\n \n+    class Options:\n+        preserve_unknown = True\n+\n \n @resource.register(name='group',\n                    collection_path='/buckets/{{bucket_id}}/groups',\n", "issue": "Metadata on Groups\nSimilarily to how you can store extra properties (metadata) on a collection, it would be useful to be able to do this with groups.\n\nIn my applications, almost everything is dynamic. Users can create groups on the fly, rename them, etc., so I tend to use generated ID's for everything. It would be nice to be able to set a title and description on groups for UI presentation.\n\nRight now I have to create a collection for storing group metadata separately from the actual group.\n\n", "before_files": [{"content": "import pkg_resources\nimport logging\n\nimport cliquet\nfrom pyramid.config import Configurator\nfrom pyramid.settings import asbool\nfrom pyramid.security import Authenticated\n\nfrom kinto.authorization import RouteFactory\n\n# Module version, as defined in PEP-0396.\n__version__ = pkg_resources.get_distribution(__package__).version\n\n# Implemented HTTP API Version\nHTTP_API_VERSION = '1.4'\n\n# Main kinto logger\nlogger = logging.getLogger(__name__)\n\n\nDEFAULT_SETTINGS = {\n    'retry_after_seconds': 3,\n    'cache_backend': 'cliquet.cache.memory',\n    'permission_backend': 'cliquet.permission.memory',\n    'storage_backend': 'cliquet.storage.memory',\n    'project_docs': 'https://kinto.readthedocs.org/',\n    'bucket_create_principals': Authenticated,\n    'multiauth.authorization_policy': (\n        'kinto.authorization.AuthorizationPolicy'),\n    'experimental_collection_schema_validation': 'False',\n    'http_api_version': HTTP_API_VERSION\n}\n\n\ndef main(global_config, config=None, **settings):\n    if not config:\n        config = Configurator(settings=settings, root_factory=RouteFactory)\n\n    # Force project name, since it determines settings prefix.\n    config.add_settings({'cliquet.project_name': 'kinto'})\n\n    cliquet.initialize(config,\n                       version=__version__,\n                       default_settings=DEFAULT_SETTINGS)\n\n    settings = config.get_settings()\n\n    # Retro-compatibility with first Kinto clients.\n    config.registry.public_settings.add('cliquet.batch_max_requests')\n\n    # Expose capability\n    schema_enabled = asbool(\n        settings['experimental_collection_schema_validation']\n    )\n    if schema_enabled:\n        config.add_api_capability(\n            \"schema\",\n            description=\"Validates collection records with JSON schemas.\",\n            url=\"http://kinto.readthedocs.org/en/latest/api/1.x/\"\n                \"collections.html#collection-json-schema\")\n\n    # Scan Kinto views.\n    kwargs = {}\n    flush_enabled = asbool(settings.get('flush_endpoint_enabled'))\n\n    if flush_enabled:\n        config.add_api_capability(\n            \"flush_endpoint\",\n            description=\"The __flush__ endpoint can be used to remove all \"\n                        \"data from all backends.\",\n            url=\"http://kinto.readthedocs.org/en/latest/configuration/\"\n                \"settings.html#activating-the-flush-endpoint\"\n        )\n    else:\n        kwargs['ignore'] = 'kinto.views.flush'\n    config.scan(\"kinto.views\", **kwargs)\n\n    app = config.make_wsgi_app()\n\n    # Install middleware (idempotent if disabled)\n    return cliquet.install_middlewares(app, settings)\n", "path": "kinto/__init__.py"}, {"content": "import colander\n\nfrom cliquet import resource\nfrom cliquet.events import ResourceChanged, ACTIONS\nfrom pyramid.events import subscriber\n\nfrom kinto.views import NameGenerator\n\n\nclass GroupSchema(resource.ResourceSchema):\n    members = colander.SchemaNode(colander.Sequence(),\n                                  colander.SchemaNode(colander.String()))\n\n\n@resource.register(name='group',\n                   collection_path='/buckets/{{bucket_id}}/groups',\n                   record_path='/buckets/{{bucket_id}}/groups/{{id}}')\nclass Group(resource.ShareableResource):\n\n    mapping = GroupSchema()\n\n    def __init__(self, *args, **kwargs):\n        super(Group, self).__init__(*args, **kwargs)\n        self.model.id_generator = NameGenerator()\n\n    def get_parent_id(self, request):\n        bucket_id = request.matchdict['bucket_id']\n        parent_id = '/buckets/%s' % bucket_id\n        return parent_id\n\n\n@subscriber(ResourceChanged,\n            for_resources=('group',),\n            for_actions=(ACTIONS.DELETE,))\ndef on_groups_deleted(event):\n    \"\"\"Some groups were deleted, remove them from users principals.\n    \"\"\"\n    permission_backend = event.request.registry.permission\n\n    for change in event.impacted_records:\n        group = change['old']\n        group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],\n                                                              **event.payload)\n        permission_backend.remove_principal(group_uri)\n\n\n@subscriber(ResourceChanged,\n            for_resources=('group',),\n            for_actions=(ACTIONS.CREATE, ACTIONS.UPDATE))\ndef on_groups_changed(event):\n    \"\"\"Some groups were changed, update users principals.\n    \"\"\"\n    permission_backend = event.request.registry.permission\n\n    for change in event.impacted_records:\n        if 'old' in change:\n            existing_record_members = set(change['old'].get('members', []))\n        else:\n            existing_record_members = set()\n\n        group = change['new']\n        group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],\n                                                              **event.payload)\n        new_record_members = set(group.get('members', []))\n        new_members = new_record_members - existing_record_members\n        removed_members = existing_record_members - new_record_members\n\n        for member in new_members:\n            # Add the group to the member principal.\n            permission_backend.add_user_principal(member, group_uri)\n\n        for member in removed_members:\n            # Remove the group from the member principal.\n            permission_backend.remove_user_principal(member, group_uri)\n", "path": "kinto/views/groups.py"}], "after_files": [{"content": "import pkg_resources\nimport logging\n\nimport cliquet\nfrom pyramid.config import Configurator\nfrom pyramid.settings import asbool\nfrom pyramid.security import Authenticated\n\nfrom kinto.authorization import RouteFactory\n\n# Module version, as defined in PEP-0396.\n__version__ = pkg_resources.get_distribution(__package__).version\n\n# Implemented HTTP API Version\nHTTP_API_VERSION = '1.5'\n\n# Main kinto logger\nlogger = logging.getLogger(__name__)\n\n\nDEFAULT_SETTINGS = {\n    'retry_after_seconds': 3,\n    'cache_backend': 'cliquet.cache.memory',\n    'permission_backend': 'cliquet.permission.memory',\n    'storage_backend': 'cliquet.storage.memory',\n    'project_docs': 'https://kinto.readthedocs.org/',\n    'bucket_create_principals': Authenticated,\n    'multiauth.authorization_policy': (\n        'kinto.authorization.AuthorizationPolicy'),\n    'experimental_collection_schema_validation': 'False',\n    'http_api_version': HTTP_API_VERSION\n}\n\n\ndef main(global_config, config=None, **settings):\n    if not config:\n        config = Configurator(settings=settings, root_factory=RouteFactory)\n\n    # Force project name, since it determines settings prefix.\n    config.add_settings({'cliquet.project_name': 'kinto'})\n\n    cliquet.initialize(config,\n                       version=__version__,\n                       default_settings=DEFAULT_SETTINGS)\n\n    settings = config.get_settings()\n\n    # Retro-compatibility with first Kinto clients.\n    config.registry.public_settings.add('cliquet.batch_max_requests')\n\n    # Expose capability\n    schema_enabled = asbool(\n        settings['experimental_collection_schema_validation']\n    )\n    if schema_enabled:\n        config.add_api_capability(\n            \"schema\",\n            description=\"Validates collection records with JSON schemas.\",\n            url=\"http://kinto.readthedocs.org/en/latest/api/1.x/\"\n                \"collections.html#collection-json-schema\")\n\n    # Scan Kinto views.\n    kwargs = {}\n    flush_enabled = asbool(settings.get('flush_endpoint_enabled'))\n\n    if flush_enabled:\n        config.add_api_capability(\n            \"flush_endpoint\",\n            description=\"The __flush__ endpoint can be used to remove all \"\n                        \"data from all backends.\",\n            url=\"http://kinto.readthedocs.org/en/latest/configuration/\"\n                \"settings.html#activating-the-flush-endpoint\"\n        )\n    else:\n        kwargs['ignore'] = 'kinto.views.flush'\n    config.scan(\"kinto.views\", **kwargs)\n\n    app = config.make_wsgi_app()\n\n    # Install middleware (idempotent if disabled)\n    return cliquet.install_middlewares(app, settings)\n", "path": "kinto/__init__.py"}, {"content": "import colander\n\nfrom cliquet import resource\nfrom cliquet.events import ResourceChanged, ACTIONS\nfrom pyramid.events import subscriber\n\nfrom kinto.views import NameGenerator\n\n\nclass GroupSchema(resource.ResourceSchema):\n    members = colander.SchemaNode(colander.Sequence(),\n                                  colander.SchemaNode(colander.String()))\n\n    class Options:\n        preserve_unknown = True\n\n\n@resource.register(name='group',\n                   collection_path='/buckets/{{bucket_id}}/groups',\n                   record_path='/buckets/{{bucket_id}}/groups/{{id}}')\nclass Group(resource.ShareableResource):\n\n    mapping = GroupSchema()\n\n    def __init__(self, *args, **kwargs):\n        super(Group, self).__init__(*args, **kwargs)\n        self.model.id_generator = NameGenerator()\n\n    def get_parent_id(self, request):\n        bucket_id = request.matchdict['bucket_id']\n        parent_id = '/buckets/%s' % bucket_id\n        return parent_id\n\n\n@subscriber(ResourceChanged,\n            for_resources=('group',),\n            for_actions=(ACTIONS.DELETE,))\ndef on_groups_deleted(event):\n    \"\"\"Some groups were deleted, remove them from users principals.\n    \"\"\"\n    permission_backend = event.request.registry.permission\n\n    for change in event.impacted_records:\n        group = change['old']\n        group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],\n                                                              **event.payload)\n        permission_backend.remove_principal(group_uri)\n\n\n@subscriber(ResourceChanged,\n            for_resources=('group',),\n            for_actions=(ACTIONS.CREATE, ACTIONS.UPDATE))\ndef on_groups_changed(event):\n    \"\"\"Some groups were changed, update users principals.\n    \"\"\"\n    permission_backend = event.request.registry.permission\n\n    for change in event.impacted_records:\n        if 'old' in change:\n            existing_record_members = set(change['old'].get('members', []))\n        else:\n            existing_record_members = set()\n\n        group = change['new']\n        group_uri = '/buckets/{bucket_id}/groups/{id}'.format(id=group['id'],\n                                                              **event.payload)\n        new_record_members = set(group.get('members', []))\n        new_members = new_record_members - existing_record_members\n        removed_members = existing_record_members - new_record_members\n\n        for member in new_members:\n            # Add the group to the member principal.\n            permission_backend.add_user_principal(member, group_uri)\n\n        for member in removed_members:\n            # Remove the group from the member principal.\n            permission_backend.remove_user_principal(member, group_uri)\n", "path": "kinto/views/groups.py"}]}