Skip to content

Commit

Permalink
refactor(nextcloud): Drop use of XML data
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Nov 7, 2024
1 parent 6ff9435 commit 393f5b2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 46 deletions.
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/base/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def __str__(self):
"name",
"display_name",
"displayName",
"displayname",
"Display_Name",
"nickname",
],
Expand Down
2 changes: 1 addition & 1 deletion allauth/socialaccount/providers/nextcloud/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def extract_uid(self, data):
def extract_common_fields(self, data):
return dict(
username=data["displayname"],
email=data["email"],
email=data.get("email"),
)

def get_default_scope(self):
Expand Down
78 changes: 38 additions & 40 deletions allauth/socialaccount/providers/nextcloud/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,44 @@ def get_login_response_json(self, with_refresh_token=True):
def get_mocked_response(self):
return MockedResponse(
200,
"""<?xml version="1.0"?>
<ocs>
<meta>
<status>ok</status>
<statuscode>100</statuscode>
<message>OK</message>
<totalitems></totalitems>
<itemsperpage></itemsperpage>
</meta>
<data>
<enabled>1</enabled>
<id>batman</id>
<storageLocation>/var/www/html/data/batman</storageLocation>
<lastLogin>1553946472000</lastLogin>
<backend>Database</backend>
<subadmin/>
<quota>
<free>1455417655296</free>
<used>467191265</used>
<total>1455884846561</total>
<relative>0.03</relative>
<quota>-3</quota>
</quota>
<email>[email protected]</email>
<displayname>batman</displayname>
<phone>7351857301</phone>
<address>BatCave, Gotham City</address>
<website>https://batman.org</website>
<twitter>@the_batman</twitter>
<groups>
<element>admin</element>
</groups>
<language>fr</language>
<locale>fr_FR</locale>
<backendCapabilities>
<setDisplayName>1</setDisplayName>
<setPassword>1</setPassword>
</backendCapabilities>
</data>
</ocs>
"""
{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 100,
"message": "OK",
"totalitems": "",
"itemsperpage": ""
},
"data": {
"enabled": true,
"storageLocation": "\\/var\\/www\\/html\\/data\\/pennersr",
"id": "pennersr",
"lastLogin": 1730973409000,
"backend": "Database",
"subadmin": [],
"quota": {
"free": 9159623057408,
"used": 1585107741,
"total": 9161208165149,
"relative": 0.02,
"quota": -3
},
"email": "[email protected]",
"displayname": "pennersr",
"phone": "",
"address": "",
"website": "",
"twitter": "",
"groups": [
"admin"
],
"language": "nl",
"locale": ""
}
}
}
""",
)

Expand Down
8 changes: 3 additions & 5 deletions allauth/socialaccount/providers/nextcloud/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import xml.etree.ElementTree as ET

from allauth.core import context
from allauth.socialaccount import app_settings
from allauth.socialaccount.adapter import get_adapter
Expand Down Expand Up @@ -44,11 +42,11 @@ def get_user_info(self, token: SocialToken, user_id):
resp = (
get_adapter()
.get_requests_session()
.get(self.profile_url + user_id, headers=headers)
.get(self.profile_url + user_id, params={"format": "json"}, headers=headers)
)
resp.raise_for_status()
data = ET.fromstring(resp.content.decode())[1]
return {d.tag: d.text.strip() for d in data if d.text is not None}
data = resp.json()["ocs"]["data"]
return data


oauth2_login = OAuth2LoginView.adapter_view(NextCloudOAuth2Adapter)
Expand Down

0 comments on commit 393f5b2

Please sign in to comment.