#529 Address private fields in FAS
Merged 6 years ago by abompard. Opened 6 years ago by shaily.
shaily/fedora-hubs develop  into  develop

@@ -12,41 +12,51 @@ 

      return (

        <div className="UserContact">

          <ul className="fa-ul">

-           <li>

-             <i className="fa fa-li fa-map-marker" aria-hidden="true"></i>

-             <span className="ml-2">

+           { this.props.hub.config.country &&

+             <li>

+               <i className="fa fa-li fa-map-marker" aria-hidden="true"></i>

+               <span className="ml-2">

                  {this.props.hub.config.country}

              </span>

-           </li>

-           <li>

-             <i className="fa fa-li fa-clock-o" aria-hidden="true"></i>

-             <span className="ml-2 mr-1">Current Time:</span>

-             <CurrentTime offset={this.props.hub.config.timezone_offset} />

-           </li>

-           <li>

-             <i className="fa fa-li fa-envelope-o" aria-hidden="true"></i>

-             <span className="ml-2">

+             </li>

+           }

+           { this.props.hub.config.timezone_offset &&

+             <li>

+               <i className="fa fa-li fa-clock-o" aria-hidden="true"></i>

+               <span className="ml-2 mr-1">Current Time:</span>

+               <CurrentTime offset={this.props.hub.config.timezone_offset}/>

+             </li>

+           }

+           { this.props.hub.config.email &&

+             <li>

+               <i className="fa fa-li fa-envelope-o" aria-hidden="true"></i>

+               <span className="ml-2">

                {this.props.hub.config.email}

              </span>

-           </li>

-           <li>

-             <i className="fa fa-li fa-comment-o" aria-hidden="true"></i>

-             <span className="ml-2">

+             </li>

+           }

+           { this.props.hub.config.chat_nickname &&

+             <li>

+               <i className="fa fa-li fa-comment-o" aria-hidden="true"></i>

+               <span className="ml-2">

                {this.props.hub.config.chat_nickname}

              </span>

-           </li>

+             </li>

+           }

          </ul>

-         <div className="text-center">

-           <i className="fa fa-certificate" aria-hidden="true"></i>

-           <span className="ml-2 mr-1">

+         { this.props.hub.config.creation_date &&

+           <div className="text-center">

+             <i className="fa fa-certificate" aria-hidden="true"></i>

+             <span className="ml-2 mr-1">

              Member Since

            </span>

-           <FormattedDate

-             value={Date.parse(this.props.hub.config.creation_date)}

-             month="short"

-             year="numeric"

+             <FormattedDate

+               value={Date.parse(this.props.hub.config.creation_date)}

+               month="short"

+               year="numeric"

              />

-         </div>

+           </div>

+         }

        </div>

      );

    }

file modified
+8 -7
@@ -120,13 +120,14 @@ 

              if fas_user[fas_attr] is None:

                  continue

              hub.config[hub_attr] = fas_user[fas_attr]

-         country = pycountry.countries.get(alpha_2=fas_user["country_code"])

-         hub.config["country"] = country.name

-         # Timezone

-         now = datetime.datetime.now()  # does not really matter, legacy API

-         tz_offset = timezone(fas_user["timezone"]).utcoffset(now)

-         hub.config["timezone_offset"] = (

-             tz_offset.days * 86400 + tz_offset.seconds)

+         if fas_user.get("country_code") is not None:

+             country = pycountry.countries.get(alpha_2=fas_user["country_code"])

+             hub.config["country"] = country.name

+         if fas_user.get("timezone") is not None:

+             now = datetime.datetime.now()  # does not really matter, legacy API

+             tz_offset = timezone(fas_user["timezone"]).utcoffset(now)

+             hub.config["timezone_offset"] = (

+                 tz_offset.days * 86400 + tz_offset.seconds)

          return fas_user

  

      def sync_user_roles(self, user, hub=None):

Thanks for the PR! So did you find any case where that information was missing in FAS?

I would recommend using fas_user.get("country_code") to avoid a KeyError if the key is absent.

I would recommend using .get() here too.

I couldn't test it in action because the FAS client was using my credentials to retrieve the details. This made my privacy setting irrelevant because the FAS server uses another mode of retrieval called self over privacy, which includes all fields.

However, I was getting KeyErrors on the country field for some sync_user calls, which stopped after this, proving that private fields were indeed not returned by FAS.

I've checked against the FAS server's source, so this information should be accurate.

1 new commit added

  • FAS private fields: Changes from review
6 years ago

rebased onto 2a35549

6 years ago

Pull-Request has been merged by abompard

6 years ago