<commit_before>import { loadIds } from '../../server/utils/get-ids';

const allMethods = ['__count__', '__get__', '__create__', '__delete__', '__destroyById__',
  '__findById__', '__getById__', '__updateById__'];

function disableRemoteRelationship(model, relationship) {
  for (let method of allMethods) {
    model.disableRemoteMethod(method + relationship, false);
  }
}

export default function(app) {
  var User = app.models.User;

  User.settings.plural = 'users';
  User.settings.http = { path: 'user' };

  app.models.User.settings.mongodb = { collection: 'users' };
  app.models.AccessToken.settings.mongodb = { collection: 'accessTokens' };
  app.models.UserCredential.settings.mongodb = { collection: 'userCredentials' };
  app.models.UserIdentity.settings.mongodb = { collection: 'userIdentities' };

  User.mixin('Timestamp', {
    createdAt: 'created',
    updatedAt: 'lastUpdated',
    required: false
  });

  User.mixin('IPs', {
    createdByIp: 'createdIp',
    updatedByIp: 'lastUpdatedIp',
    required: false
  });

  User.defineProperty('fullName', { type: 'string' });
  User.defineProperty('language', { type: 'string' });

  User.hasMany(app.models.Account, { as: 'personalAccount' });

  User.settings.hidden = [
    'password',
    'emailVerified',
    'verificationToken',
    'accessTokens',
    'credentials',
    'challenges',
    'identities',
    'realm',
    'status'
  ];

  User.disableRemoteMethod('count', true);
  User.disableRemoteMethod('find', true);
  User.disableRemoteMethod('findOne', true);
  User.disableRemoteMethod('deleteById', true);

  disableRemoteRelationship(User, 'accessTokens');
  disableRemoteRelationship(User, 'credentials');
  disableRemoteRelationship(User, 'identities');
  disableRemoteRelationship(User, 'personalAccount');

  User.settings.acls = [
    {
      property: 'login',
      principalType: 'ROLE',
      principalId: '$unauthenticated',
      permission: 'ALLOW'
    },
    {
      accessType: '*',
      principalType: 'ROLE',
      principalId: '$unauthenticated',
      permission: 'DENY'
    },
    {
      accessType: '*',
      principalType: 'ROLE',
      principalId: '$owner',
      permission: 'ALLOW'
    }
  ];

  // TODO add here too the accounts that the user has read access
  User.afterRemote('*', (ctx, user, next) =>
    loadIds(ctx.result, 'accountIds', app.models.Account, 'ownerIds')
      .then(next)<commit_msg>Use default ACLs for User<commit_after>import { loadIds } from '../../server/utils/get-ids';

const allMethods = ['__count__', '__get__', '__create__', '__delete__', '__destroyById__',
  '__findById__', '__getById__', '__updateById__'];

function disableRemoteRelationship(model, relationship) {
  for (let method of allMethods) {
    model.disableRemoteMethod(method + relationship, false);
  }
}

export default function(app) {
  var User = app.models.User;

  User.settings.plural = 'users';
  User.settings.http = { path: 'user' };

  app.models.User.settings.mongodb = { collection: 'users' };
  app.models.AccessToken.settings.mongodb = { collection: 'accessTokens' };
  app.models.UserCredential.settings.mongodb = { collection: 'userCredentials' };
  app.models.UserIdentity.settings.mongodb = { collection: 'userIdentities' };

  User.mixin('Timestamp', {
    createdAt: 'created',
    updatedAt: 'lastUpdated',
    required: false
  });

  User.mixin('IPs', {
    createdByIp: 'createdIp',
    updatedByIp: 'lastUpdatedIp',
    required: false
  });

  User.defineProperty('fullName', { type: 'string' });
  User.defineProperty('language', { type: 'string' });

  User.hasMany(app.models.Account, { as: 'personalAccount' });

  User.settings.hidden = [
    'password',
    'emailVerified',
    'verificationToken',
    'accessTokens',
    'credentials',
    'challenges',
    'identities',
    'realm',
    'status'
  ];

  User.disableRemoteMethod('count', true);
  User.disableRemoteMethod('find', true);
  User.disableRemoteMethod('findOne', true);
  User.disableRemoteMethod('deleteById', true);

  disableRemoteRelationship(User, 'accessTokens');
  disableRemoteRelationship(User, 'credentials');
  disableRemoteRelationship(User, 'identities');
  disableRemoteRelationship(User, 'personalAccount');

  // TODO add here too the accounts that the user has read access
  User.afterRemote('*', (ctx, user, next) =>
    loadIds(ctx.result, 'accountIds', app.models.Account, 'ownerIds')
      .then(next)
{'fraction_non_alphanumeric': 0.15450643776824036, 'fraction_numerical': 0.0, 'mean_word_length': 4.197183098591549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5425213', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1373, 'n_words': 262}