Exemplo n.º 1
0
  private void checkCreationInvariants(Viewpoint viewpoint, Block block)
      throws BlockNotVisibleException {
    UserViewpoint userview = null;
    if (viewpoint instanceof UserViewpoint) userview = (UserViewpoint) viewpoint;

    if (block.getInclusion() == StackInclusion.ONLY_WHEN_VIEWING_SELF) {
      User user = identitySpider.lookupUser(block.getData1AsGuid());
      if (userview == null || !userview.getViewer().equals(user)) {
        // FIXME should this be a RuntimeException? logger.warn is here so we can investigate
        // that if the exception ever really happens
        logger.warn(
            "Trying to view an ONLY_WHEN_VIEWING_SELF block from a different viewpoint: {} block={}",
            userview,
            block);
        throw new BlockNotVisibleException(
            "ONLY_WHEN_VIEWING_SELF block is not visible to non-self viewpoint");
      }
    }
  }
Exemplo n.º 2
0
  private Set<User> getUsersWhoCareAboutData1User(Block block, User user) {
    Set<User> peopleWhoCare = null;

    switch (block.getInclusion()) {
      case IN_ALL_STACKS:
      case ONLY_WHEN_VIEWED_BY_OTHERS:
        peopleWhoCare =
            identitySpider.getUsersWhoHaveUserAsContact(SystemViewpoint.getInstance(), user);

        // we also show each block to its "owner" when it is IN_ALL_STACKS;
        // we include the "owner" for the ONLY_WHEN_VIEWED_BY_OTHERS block, so
        // that the block is displayed in the owner's mugshot when it is viewed
        // by another person
        peopleWhoCare.add(user);
        return peopleWhoCare;
      case ONLY_WHEN_VIEWING_SELF:
        peopleWhoCare = Collections.singleton(user);
        return peopleWhoCare;
        // no default, it hides bugs
    }

    throw new RuntimeException("invalid inclusion " + block);
  }