def _DeserializeUsersByID(self, user_rows, dismissedcue_rows, linkedaccount_rows): """Convert database row tuples into User PBs. Args: user_rows: rows from the User DB table. dismissedcue_rows: rows from the DismissedCues DB table. linkedaccount_rows: rows from the LinkedAccount DB table. Returns: A dict {user_id: user_pb} for all the users referenced in user_rows. """ result_dict = {} # Make one User PB for each row in user_rows. for row in user_rows: (user_id, email, is_site_admin, notify_issue_change, notify_starred_issue_change, email_compact_subject, email_view_widget, notify_starred_ping, banned, after_issue_update, keep_people_perms_open, preview_on_hover, obscure_email, last_visit_timestamp, email_bounce_timestamp, vacation_message) = row user = user_pb2.MakeUser(user_id, email=email, obscure_email=obscure_email) user.is_site_admin = bool(is_site_admin) user.notify_issue_change = bool(notify_issue_change) user.notify_starred_issue_change = bool( notify_starred_issue_change) user.email_compact_subject = bool(email_compact_subject) user.email_view_widget = bool(email_view_widget) user.notify_starred_ping = bool(notify_starred_ping) if banned: user.banned = banned if after_issue_update: user.after_issue_update = user_pb2.IssueUpdateNav( after_issue_update.upper()) user.keep_people_perms_open = bool(keep_people_perms_open) user.preview_on_hover = bool(preview_on_hover) user.last_visit_timestamp = last_visit_timestamp or 0 user.email_bounce_timestamp = email_bounce_timestamp or 0 if vacation_message: user.vacation_message = vacation_message result_dict[user_id] = user # Build up a list of dismissed "cue card" help items for the users. for user_id, cue in dismissedcue_rows: if user_id not in result_dict: logging.error('Found dismissed cues for missing user %r', user_id) continue result_dict[user_id].dismissed_cues.append(cue) # Put in any linked accounts. for parent_id, child_id in linkedaccount_rows: if parent_id in result_dict: result_dict[parent_id].linked_child_ids.append(child_id) if child_id in result_dict: result_dict[child_id].linked_parent_id = parent_id return result_dict
def UpdateUserSettings(self, cnxn, user_id, user, notify=None, notify_starred=None, email_compact_subject=None, email_view_widget=None, notify_starred_ping=None, obscure_email=None, after_issue_update=None, is_site_admin=None, is_banned=None, banned_reason=None, dismissed_cues=None, keep_people_perms_open=None, preview_on_hover=None, vacation_message=None): """Update the preferences of the specified user. Args: cnxn: connection to SQL database. user_id: int user ID of the user whose settings we are updating. user: User PB of user before changes are applied. keyword args: dictionary of setting names mapped to new values. Returns: The user's new User PB. """ # notifications if notify is not None: user.notify_issue_change = notify if notify_starred is not None: user.notify_starred_issue_change = notify_starred if notify_starred_ping is not None: user.notify_starred_ping = notify_starred_ping if email_compact_subject is not None: user.email_compact_subject = email_compact_subject if email_view_widget is not None: user.email_view_widget = email_view_widget # display options if after_issue_update is not None: user.after_issue_update = user_pb2.IssueUpdateNav( after_issue_update) if preview_on_hover is not None: user.preview_on_hover = preview_on_hover if dismissed_cues: # Note, we never set it back to []. user.dismissed_cues = dismissed_cues if keep_people_perms_open is not None: user.keep_people_perms_open = keep_people_perms_open # misc if obscure_email is not None: user.obscure_email = obscure_email # admin if is_site_admin is not None: user.is_site_admin = is_site_admin if is_banned is not None: if is_banned: user.banned = banned_reason or 'No reason given' else: user.reset('banned') # user availability if vacation_message is not None: user.vacation_message = vacation_message # Write the user settings to the database. self.UpdateUser(cnxn, user_id, user)
def _DeserializeUsersByID(self, user_rows, actionlimit_rows, dismissedcue_rows): """Convert database row tuples into User PBs. Args: user_rows: rows from the User DB table. actionlimit_rows: rows from the ActionLimit DB table. dismissedcue_rows: rows from the DismissedCues DB table. Returns: A dict {user_id: user_pb} for all the users referenced in user_rows. """ result_dict = {} # Make one User PB for each row in user_rows. for row in user_rows: (user_id, email, is_site_admin, notify_issue_change, notify_starred_issue_change, email_compact_subject, email_view_widget, notify_starred_ping, banned, after_issue_update, keep_people_perms_open, preview_on_hover, ignore_action_limits, obscure_email, last_visit_timestamp, email_bounce_timestamp, vacation_message) = row user = user_pb2.MakeUser(user_id, email=email, obscure_email=obscure_email) user.is_site_admin = bool(is_site_admin) user.notify_issue_change = bool(notify_issue_change) user.notify_starred_issue_change = bool( notify_starred_issue_change) user.email_compact_subject = bool(email_compact_subject) user.email_view_widget = bool(email_view_widget) user.notify_starred_ping = bool(notify_starred_ping) if banned: user.banned = banned if after_issue_update: user.after_issue_update = user_pb2.IssueUpdateNav( after_issue_update.upper()) user.keep_people_perms_open = bool(keep_people_perms_open) user.preview_on_hover = bool(preview_on_hover) user.ignore_action_limits = bool(ignore_action_limits) user.last_visit_timestamp = last_visit_timestamp or 0 user.email_bounce_timestamp = email_bounce_timestamp or 0 if vacation_message: user.vacation_message = vacation_message result_dict[user_id] = user # Make an ActionLimit for each actionlimit row and attach it to a User PB. for row in actionlimit_rows: (user_id, action_type_name, recent_count, reset_timestamp, lifetime_count, lifetime_limit, period_soft_limit, period_hard_limit) = row if user_id not in result_dict: logging.error('Found action limits for missing user %r', user_id) continue user = result_dict[user_id] action_type = actionlimit.ACTION_TYPE_NAMES[action_type_name] al = actionlimit.GetLimitPB(user, action_type) al.recent_count = recent_count al.reset_timestamp = reset_timestamp al.lifetime_count = lifetime_count al.lifetime_limit = lifetime_limit al.period_soft_limit = period_soft_limit al.period_hard_limit = period_hard_limit # Build up a list of dismissed "cue card" help items for the users. for user_id, cue in dismissedcue_rows: if user_id not in result_dict: logging.error('Found dismissed cues for missing user %r', user_id) continue result_dict[user_id].dismissed_cues.append(cue) return result_dict