text: /*!
   * Copyright 2014 Apereo Foundation (AF) Licensed under the
   * Educational Community License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License. You may
   * obtain a copy of the License at
   *
   *     http://opensource.org/licenses/ECL-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an "AS IS"
   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
   * or implied. See the License for the specific language governing
   * permissions and limitations under the License.
   */
  
  import * as AuthzPermissions from 'oae-authz/lib/permissions';
  
  /**
   * Determine if the current user in context is allowed to see the followers list of the provided user.
   *
   * @param  {Context}    ctx                 Standard context object containing the current user and the current tenant
   * @param  {User}       user                The user whose followers are being requested
   * @param  {Function}   callback            Standard callback function
   * @param  {Object}     callback.err        An error that occurred, if any
   */
  const canViewFollowers = function(ctx, user, callback) {
    if (user.deleted) {
      return callback({ code: 404, msg: 'The user could not be found' });
    }
  
    return AuthzPermissions.canView(ctx, user, callback);
  };
  
  /**
   * Determine if the current user in context is allowed to see the followering list of the provided user.
   *
   * @param  {Context}    ctx                 Standard context object containing the current user and the current tenant
   * @param  {User}       user                The user whose followees are being requested
   * @param  {Function}   callback            Standard callback function
   * @param  {Object}     callback.err        An error that occurred, if any
   */
  const canViewFollowing = function(ctx, user, callback) {
    if (user.deleted) {
      return callback({ code: 404, msg: 'The user could not be found' });
    }
  
    return AuthzPermissions.canView(ctx, user, callback);
  };
  
  /**
   * Determine whether or not the current user in context is allowed to follow the provided user
   *
   * @param  {Context}    ctx                 Standard context object containing the current user and the current tenant
   * @param  {User}       followerUser        The user whose follower list is being updated
   * @param  {User}       followedUser        The user who is to be followed
   * @param  {Function}   callback            Standard callback function
   * @param  {Object}     callback.err        An error that occurred, if any
   */
  const canFollow = function(ctx, user, callback) {
    if (ctx.user() && ctx.user().id === user.id) {
      return callback({ code: 400, msg: 'A user cannot follow themselves' });
    }
  
    if (user.deleted) {
      return callback({ code: 404, msg: 'The user could not be found' });
    }
  
    return AuthzPermissions.canInteract(ctx, user, callback);
  };
  
  export { canFollow, canViewFollowing, canViewFollowers };
  