def track_account_activity(db, device_id: str):
    """Use the device ID to find the account, update active timestamp and metrics."""
    account_repository = AccountRepository(db)
    account = account_repository.get_account_by_device_id(device_id)
    account_repository.update_last_activity_ts(account.id)
    account_activity_repository = AccountActivityRepository(db)
    account_activity_repository.increment_activity(account)
Exemplo n.º 2
0
    def _get_account(self, device_id: str):
        """Use the device ID to find the account.

        :param device_id: The database ID for the device that made this API call
        """
        account_repository = AccountRepository(self.db)
        return account_repository.get_account_by_device_id(device_id)
Exemplo n.º 3
0
    def _initialize_skill_settings(self, device_id):
        """Use default settings or copy from another device in same account."""
        _log.info('Initializing settings for skill ' + self.skill.skill_gid)
        account_repo = AccountRepository(self.db)
        account = account_repo.get_account_by_device_id(device_id)
        skill_settings_repo = SkillSettingRepository(self.db)
        skill_family = extract_family_from_global_id(self.skill.skill_gid)
        family_settings = skill_settings_repo.get_family_settings(
            account.id, skill_family)
        new_settings_values = self.default_settings
        if family_settings is not None:
            for settings in family_settings:
                if settings.settings_values is None:
                    continue
                if settings.settings_values != self.default_settings:
                    field_names = settings.settings_values.keys()
                    if field_names == self.default_settings.keys():
                        _log.info(
                            'Copying settings from another device for skill' +
                            self.skill.skill_gid)
                        new_settings_values = settings.settings_values
                        break
        else:
            _log.info('Using default skill settings for skill ' +
                      self.skill.skill_gid)

        return new_settings_values
Exemplo n.º 4
0
    def _get_account_skill_settings(self):
        """Get all the permutations of settings for a skill"""
        account_repo = AccountRepository(self.db)
        account = account_repo.get_account_by_device_id(self.device_id)
        skill_settings = (
            self.device_skill_repo.get_skill_settings_for_account(
                account.id, self.skill.id))

        return skill_settings
Exemplo n.º 5
0
 def _get_account(self):
     if self.device_id is not None:
         account_repo = AccountRepository(self.db)
         self.account = account_repo.get_account_by_device_id(
             self.device_id)
Exemplo n.º 6
0
def validate_account_last_activity(context):
    account_repo = AccountRepository(context.db)
    account = account_repo.get_account_by_device_id(context.device_login["uuid"])
    assert_that(account.last_activity, not_none())
    assert_that(account.last_activity.date(), equal_to(datetime.utcnow().date()))