Repository: inveniosoftware/invenio-communities (language: python)

Issue:
communities: cannot change visibility restriction
1. create a new community, restricted
2. go to settings, change to public and save

There is also a missing padding between the error banner and the title.

A `validation` error is displayed.

<img width="789" alt="Screenshot 2022-05-12 at 20 16 09" src="https://user-images.githubusercontent.com/2089455/168142019-87390fd1-3aac-4056-8cd3-035179aab201.png">

```
Traceback (most recent call last):
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/resources.py", line 65, in view
    return view_meth()
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/content_negotiation.py", line 116, in inner_content_negotiation
    return f(*args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/parsers/decorators.py", line 51, in inner
    return f(self, *args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/parsers/decorators.py", line 51, in inner
    return f(self, *args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/parsers/decorators.py", line 51, in inner
    return f(self, *args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/parsers/decorators.py", line 90, in inner
    return f(self, *args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/flask_resources/responses.py", line 39, in inner
    res = f(*args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/invenio_records_resources/resources/records/resource.py", line 120, in update
    item = self.service.update(
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/invenio_records_resources/services/uow.py", line 326, in inner
    res = f(self, *args, **kwargs)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/invenio_records_resources/services/records/service.py", line 412, in update
    data, _ = self.schema.load(
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/invenio_records_resources/services/records/schema.py", line 81, in load
    valid_data = self.schema(context=context, **schema_args).load(data)
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/marshmallow/schema.py", line 717, in load
    return self._do_load(
  File "/Users/nico/.local/share/virtualenvs/my-site-5PKhBfd9-python/lib/python3.8/site-packages/marshmallow/schema.py", line 900, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'metadata': {'type': {'title': ['Unknown field.']}}}
```


Discussion / hints:

Fix patch:
diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/community/new.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/community/new.js
index 01b333cbc..0c202c7d8 100644
--- a/invenio_communities/assets/semantic-ui/js/invenio_communities/community/new.js
+++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/community/new.js
@@ -123,7 +123,7 @@ class CommunityCreateForm extends Component {
             <Message
               hidden={error === ""}
               negative
-              className="flashed top attached"
+              className="flashed"
             >
               <Grid container>
                 <Grid.Column width={15} textAlign="left">
diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges.js
index 70a1af28a..ea6ef9d5d 100644
--- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges.js
+++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges.js
@@ -84,7 +84,7 @@ class CommunityPrivilegesForm extends Component {
             <Message
               hidden={error === ""}
               negative
-              className="flashed top attached"
+              className="flashed"
             >
               <Grid container>
                 <Grid.Column width={15} textAlign="left">
diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js
index 69343279f..5b8e6704c 100644
--- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js
+++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js
@@ -467,7 +467,7 @@ class CommunityProfileForm extends Component {
             <Message
               hidden={this.state.error === ""}
               negative
-              className="flashed top attached"
+              className="flashed"
             >
               <Grid container>
                 <Grid.Column width={15} textAlign="left">
diff --git a/invenio_communities/communities/schema.py b/invenio_communities/communities/schema.py
index ed8111bd2..5502c4ac2 100644
--- a/invenio_communities/communities/schema.py
+++ b/invenio_communities/communities/schema.py
@@ -16,7 +16,8 @@
 from invenio_vocabularies.contrib.affiliations.schema import \
     AffiliationRelationSchema
 from invenio_vocabularies.contrib.awards.schema import FundingRelationSchema
-from marshmallow import Schema, fields, post_load, validate, ValidationError
+from marshmallow import Schema, fields, post_load, validate, ValidationError, \
+    pre_load
 from marshmallow_utils.fields import NestedAttribute, SanitizedHTML, \
     SanitizedUnicode
 
@@ -61,12 +62,24 @@ class CommunityAccessSchema(Schema):
 
 # TODO this schema is duplicated from invenio-rdm-records, can't be imported
 # TODO in this module. Might need to be moved to invenio-vocabularies.
+# TODO move clean method to reusable non-record schema class
 class VocabularySchema(Schema):
     """Invenio Vocabulary schema."""
 
     id = SanitizedUnicode(required=True)
     title = fields.Dict(dump_only=True)
 
+    @pre_load
+    def clean(self, data, **kwargs):
+        """Removes dump_only fields.
+        Why: We want to allow the output of a Schema dump, to be a valid input
+             to a Schema load without causing strange issues.
+        """
+        for name, field in self.fields.items():
+            if field.dump_only:
+                data.pop(name, None)
+        return data
+
 
 class CommunityMetadataSchema(Schema):
     """Community metadata schema."""


Test patch:
diff --git a/tests/communities/test_resources.py b/tests/communities/test_resources.py
index f0afa8704..df165f973 100644
--- a/tests/communities/test_resources.py
+++ b/tests/communities/test_resources.py
@@ -175,7 +175,7 @@ def test_post_schema_validation(
 
     # Assert required enums
     data = copy.deepcopy(minimal_community)
-    data['metadata']['type'] = 'foobar'
+    data['metadata']['type'] = {'id': 'foobar', 'title': 'foobar'}
     res = client.post('/communities', headers=headers, json=data)
     assert res.status_code == 400