Repository: liberapay/liberapay.com

Issue:
Changing organization type doesn't work
In identity tab, when I change the organization type to set Organization instead of Business, my changes are not saved. 



Discussion:

Resolving patch:
diff --git a/liberapay/security/authentication.py b/liberapay/security/authentication.py
--- a/liberapay/security/authentication.py
+++ b/liberapay/security/authentication.py
@@ -44,6 +44,8 @@ def sign_in_with_form_data(body, state):
             k, 'password',
             id, body.pop('log-in.password')
         )
+        if not p:
+            state['sign-in.error'] = _("Bad username or password.")
         if p and p.status == 'closed':
             p.update_status('active')
 


Test patch:
diff --git a/tests/py/fixtures/TestPages.yml b/tests/py/fixtures/TestPages.yml
--- a/tests/py/fixtures/TestPages.yml
+++ b/tests/py/fixtures/TestPages.yml
@@ -195,6 +195,94 @@ interactions:
       transfer-encoding: [chunked]
       vary: [Accept, Accept-Encoding]
     status: {code: 200, message: OK}
+- request:
+    body: '{"CountryOfResidence": "US", "FirstName": "Kathryn", "LastName": "Janeway",
+      "Birthday": 790214400.0, "Nationality": "IS", "Email": "janeway@example.org"}'
+    headers: {}
+    method: POST
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/natural
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"IS","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989590","Tag":null,"CreationDate":1455993241}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
+- request:
+    body: null
+    headers: {}
+    method: GET
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/10989590
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"IS","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989590","Tag":null,"CreationDate":1455993241}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
+- request:
+    body: '{"CountryOfResidence": "US", "FirstName": "Kathryn", "LastName": "Janeway",
+      "Birthday": 790214400.0, "Nationality": "US", "Email": "janeway@example.org"}'
+    headers: {}
+    method: PUT
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/natural/10989590
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"US","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989590","Tag":null,"CreationDate":1455993241}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
+- request:
+    body: '{"CountryOfResidence": "US", "FirstName": "Kathryn", "LastName": "Janeway",
+      "Birthday": 790214400.0, "Nationality": "IS", "Email": "janeway@example.org"}'
+    headers: {}
+    method: POST
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/natural
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"IS","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989591","Tag":null,"CreationDate":1455993243}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
+- request:
+    body: null
+    headers: {}
+    method: GET
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/10989591
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"IS","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989591","Tag":null,"CreationDate":1455993243}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
+- request:
+    body: '{"CountryOfResidence": "US", "FirstName": "Kathryn", "LastName": "Janeway",
+      "Birthday": 790214400.0, "Nationality": "US", "Email": "janeway@example.org"}'
+    headers: {}
+    method: PUT
+    uri: https://api.sandbox.mangopay.com:443/v2.01/liberapay-dev/users/natural/10989591
+  response:
+    body: {string: !!python/unicode '{"Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null},"FirstName":"Kathryn","LastName":"Janeway","Birthday":790214400,"Nationality":"US","CountryOfResidence":"US","Occupation":null,"IncomeRange":null,"ProofOfIdentity":null,"ProofOfAddress":null,"PersonType":"NATURAL","Email":"janeway@example.org","KYCLevel":"LIGHT","Id":"10989591","Tag":null,"CreationDate":1455993243}'}
+    headers:
+      cache-control: [no-cache]
+      content-length: ['428']
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
 - request:
     body: null
     headers: {}
diff --git a/tests/py/test_pages.py b/tests/py/test_pages.py
--- a/tests/py/test_pages.py
+++ b/tests/py/test_pages.py
@@ -168,3 +168,45 @@ def test_can_see_payout_success_page(self):
                             auth_as=self.david)
         assert r.code == 200
         assert '€19' in r.body.decode('utf8')
+
+    def test_identity_form(self):
+        janeway = self.make_participant(
+            'janeway', email='janeway@example.org', mangopay_user_id=None,
+            mangopay_wallet_id=None,
+        )
+        assert janeway.mangopay_user_id is None
+
+        # Create a mangopay NaturalUser
+        data = {
+            'FirstName': 'Kathryn',
+            'LastName': 'Janeway',
+            'CountryOfResidence': 'US',
+            'Nationality': 'IS',
+            'Birthday': '1995-01-16',
+            'terms': 'agree',
+        }
+        kw = dict(auth_as=janeway, raise_immediately=False, xhr=True)
+        r = self.client.POST('/janeway/identity', data, **kw)
+        assert r.code == 200, r.text
+        janeway = janeway.refetch()
+        assert janeway.mangopay_user_id
+
+        # Edit NaturalUser
+        data2 = dict(data, Nationality='US')
+        r = self.client.POST('/janeway/identity', data2, **kw)
+        assert r.code == 200, r.text
+        janeway2 = janeway.refetch()
+        assert janeway2.mangopay_user_id == janeway.mangopay_user_id
+
+        # Create a mangopay LegalUser
+        self.db.run("UPDATE participants SET mangopay_user_id = mangopay_wallet_id = NULL")
+        r = self.client.POST('/janeway/identity', data, **kw)
+        assert r.code == 200, r.text
+        janeway = janeway.refetch()
+        assert janeway.mangopay_user_id
+
+        # Edit LegalUser
+        r = self.client.POST('/janeway/identity', data2, **kw)
+        assert r.code == 200, r.text
+        janeway2 = janeway.refetch()
+        assert janeway2.mangopay_user_id == janeway.mangopay_user_id