Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 42423b08 authored by Mario Đanić's avatar Mario Đanić Committed by GitHub
Browse files

Merge pull request #110 from nextcloud/bugfix/109

Fixes #109: Use correct field name when extracting user info fields
parents 91605141 355bcae8
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class UserInfo {
    public String email;
    public String phone;
    public String address;
    public String webpage;
    public String website;
    public String twitter;
    public Quota quota;

@@ -41,14 +41,14 @@ public class UserInfo {
    }

    public UserInfo(String id, Boolean enabled, String displayName, String email, String phone, String address,
                    String webpage, String twitter, Quota quota) {
                    String website, String twitter, Quota quota) {
        this.id = id;
        this.enabled = enabled;
        this.displayName = displayName;
        this.email = email;
        this.phone = phone;
        this.address = address;
        this.webpage = webpage;
        this.website = website;
        this.twitter = twitter;
        this.quota = quota;
    }
@@ -93,12 +93,12 @@ public class UserInfo {
        this.address = address;
    }

    public String getWebpage() {
        return webpage;
    public String getWebsite() {
        return website;
    }

    public void setWebpage(String webpage) {
        this.webpage = webpage;
    public void setWebsite(String website) {
        this.website = website;
    }

    public String getTwitter() {
+15 −15
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
    private static final String NODE_ENABLED = "enabled";
    private static final String NODE_PHONE = "phone";
    private static final String NODE_ADDRESS = "address";
    private static final String NODE_WEBSITE = "website";
    private static final String NODE_WEBPAGE = "webpage";
    private static final String NODE_TWITTER = "twitter";

@@ -164,8 +165,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
                    userInfo.setDisplayName(respData.getString(NODE_DISPLAY_NAME_ALT));
                }

                if (respData.has(NODE_EMAIL) && !respData.isNull(NODE_EMAIL) &&
                        !TextUtils.isEmpty(respData.getString(NODE_EMAIL))) {
                if (hasData(respData, NODE_EMAIL)) {
                    userInfo.setEmail(respData.getString(NODE_EMAIL));
                }

@@ -187,25 +187,20 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
                    userInfo.setQuota(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative, quotaValue));
                }

                if (respData.has(NODE_PHONE) && !respData.isNull(NODE_PHONE) &&
                        !TextUtils.isEmpty(respData.getString(NODE_PHONE))) {
                if (hasData(respData, NODE_PHONE))
                    userInfo.setPhone(respData.getString(NODE_PHONE));
                }

                if (respData.has(NODE_ADDRESS) && !respData.isNull(NODE_ADDRESS) &&
                        !TextUtils.isEmpty(respData.getString(NODE_ADDRESS))) {
                if (hasData(respData, NODE_ADDRESS))
                    userInfo.setAddress(respData.getString(NODE_ADDRESS));
                }

                if (respData.has(NODE_WEBPAGE) && !respData.isNull(NODE_WEBPAGE) &&
                        !TextUtils.isEmpty(respData.getString(NODE_WEBPAGE))) {
                    userInfo.setWebpage(respData.getString(NODE_WEBPAGE));
                }
                // webpage is a field name pre NC12
                if (hasData(respData, NODE_WEBSITE))
                    userInfo.setWebsite(respData.getString(NODE_WEBSITE));
                else if (hasData(respData, NODE_WEBPAGE))
                    userInfo.setWebsite(respData.getString(NODE_WEBPAGE));

                if (respData.has(NODE_TWITTER) && !respData.isNull(NODE_TWITTER) &&
                        !TextUtils.isEmpty(respData.getString(NODE_TWITTER))) {
                if (hasData(respData, NODE_TWITTER))
                    userInfo.setTwitter(respData.getString(NODE_TWITTER));
                }

                if (respData.has(NODE_ENABLED)) {
                    userInfo.setEnabled(respData.getBoolean(NODE_ENABLED));
@@ -238,6 +233,11 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
        return result;
    }

    private boolean hasData(JSONObject respData, String objectName) throws JSONException {
        return respData.has(objectName) && !respData.isNull(objectName) &&
                !TextUtils.isEmpty(respData.getString(objectName));
    }

    private boolean isSuccess(int status) {
        return (status == HttpStatus.SC_OK);
    }