'Accept a list of encoded user_ids, validate them as users, and then
add or remove user shares in order to update the users_shared_with to
match the given list finally returning the new list of shares.'

def deserialize_users_shared_with(self, item, key, val, **context):

    unencoded_ids = [self.app.security.decode_id(id_) for id_ in val]
    new_users_shared_with = set(self.manager.user_manager.by_ids(unencoded_ids))
    current_shares = self.manager.get_share_assocs(item)
    currently_shared_with = set([share.user for share in current_shares])
    needs_adding = (new_users_shared_with - currently_shared_with)
    for user in needs_adding:
        current_shares.append(self.manager.share_with(item, user, flush=False))
    needs_removing = (currently_shared_with - new_users_shared_with)
    for user in needs_removing:
        current_shares.remove(self.manager.unshare_with(item, user, flush=False))
    self.manager.session().flush()
    return current_shares
