@gen.coroutine
  def _Check(self):
    """Gathers pre-mutation information:
       1. Queries for existing followers and viewpoint.
       2. Checkpoints list of followers that need to be revived.

       Validates the following:
       1. Permission to update viewpoint metadata.
    """
    # Get the viewpoint to be modified, along with the follower that is adding the additional users.
    # This state will not be changed by add followers, and so doesn't need to be part of the checkpoint.
    self._viewpoint, self._follower = yield gen.Task(Viewpoint.QueryWithFollower,
                                                     self._client,
                                                     self._user_id,
                                                     self._viewpoint_id)

    if self._viewpoint is None:
      raise InvalidRequestError('Viewpoint "%s" does not exist and so cannot be updated.' %
                                (self._viewpoint_id))

    if self._follower is None or not self._follower.CanContribute():
      raise PermissionError('User %d does not have permission to update viewpoint "%s".' %
                            (self._user_id, self._viewpoint_id))

    # Get all existing followers.
    self._followers, _ = yield gen.Task(Viewpoint.QueryFollowers,
                                        self._client,
                                        self._viewpoint_id,
                                        limit=Viewpoint.MAX_FOLLOWERS)

    # Check that cover photo exists in this viewpoint.
    cover_photo = self._vp_dict.get('cover_photo', None)
    if cover_photo is not None:
      if self._viewpoint.IsDefault():
        # cover_photo isn't supported creating default viewpoint.
        raise InvalidRequestError('A cover photo cannot be set on your library.')

      cover_photo_episode, cover_photo_post = yield [gen.Task(Episode.Query,
                                                              self._client,
                                                              cover_photo['episode_id'],
                                                              None,
                                                              must_exist=False),
                                                     gen.Task(Post.Query,
                                                              self._client,
                                                              cover_photo['episode_id'],
                                                              cover_photo['photo_id'],
                                                              None,
                                                              must_exist=False)]

      if cover_photo_post is None:
        raise InvalidRequestError('The requested cover photo does not exist.')

      if cover_photo_post.IsUnshared():
        raise PermissionError('The requested cover photo has been unshared.')

      if cover_photo_episode.viewpoint_id != self._viewpoint_id:
        raise InvalidRequestError('The requested cover photo is not in viewpoint "%s".' % self._viewpoint_id)

    # Start populating the checkpoint if this the first time the operation has been run.
    if self._op.checkpoint is None:
      # Get list of followers which have removed themselves from the viewpoint and will need to be revived.
      self._revive_follower_ids = self._GetRevivableFollowers(self._followers)

      # Get previous values of title and cover_photo, if they are being updated.
      self._prev_values = {}
      if 'title' in self._vp_dict:
        util.SetIfNotNone(self._prev_values, 'prev_title', self._viewpoint.title)
      if 'cover_photo' in self._vp_dict:
        util.SetIfNotNone(self._prev_values, 'prev_cover_photo', self._viewpoint.cover_photo)

      # Set checkpoint.
      # Followers to revive need to be check-pointed because they are changed in the UPDATE phase.
      # If we fail after UPDATE, but before NOTIFY, we would not send correct notifications on retry.
      checkpoint = {'revive': self._revive_follower_ids}
      util.SetIfNotEmpty(checkpoint, 'prev', self._prev_values)
      yield self._op.SetCheckpoint(self._client, checkpoint)
    else:
      # Restore state from checkpoint.
      self._revive_follower_ids = self._op.checkpoint['revive']
      self._prev_values = self._op.checkpoint.get('prev', {})
dataset/ETHPy150Open viewfinderco/viewfinder/backend/op/update_viewpoint_op.py/UpdateViewpointOperation._Check/original