示例#1
0
 def validate(self):
     try:
         self.restore_state.validate_state()
     except InvalidSyncLogException, e:
         if LOOSE_SYNC_TOKEN_VALIDATION.enabled(self.domain):
             # This exception will get caught by the view and a 412 will be returned to the phone for resync
             raise RestoreException(e)
         else:
             # This exception will fail hard and we'll get a 500 error message
             raise
示例#2
0
    def validate_state(self):
        check_version(self.params.version)
        if self.last_sync_log:
            if (self._case_sync == CLEAN_OWNERS and
                    self.last_sync_log.log_format == LOG_FORMAT_LIVEQUERY):
                raise RestoreException("clean_owners sync after livequery sync")
            if self.params.state_hash:
                parsed_hash = CaseStateHash.parse(self.params.state_hash)
                computed_hash = self.last_sync_log.get_state_hash()
                if computed_hash != parsed_hash:
                    # log state error on the sync log
                    self.last_sync_log.had_state_error = True
                    self.last_sync_log.error_date = datetime.utcnow()
                    self.last_sync_log.error_hash = str(parsed_hash)
                    self.last_sync_log.save()

                    raise BadStateException(
                        server_hash=computed_hash,
                        phone_hash=parsed_hash,
                        case_ids=self.last_sync_log.get_footprint_of_cases_on_phone()
                    )
示例#3
0
 def validate(self):
     try:
         self.restore_state.validate_state()
     except InvalidSyncLogException as e:
         # This exception will get caught by the view and a 412 will be returned to the phone for resync
         raise RestoreException(e)