<commit_before>jraphical = require 'jraphical'
KodingError = require '../../error'

module.exports = class JProxyFilter extends jraphical.Module

  {secure, ObjectId} = require 'bongo'
  {Relationship}     = jraphical
  {permit}           = require '../group/permissionset'
  JProxyRestriction  = require './restriction'

  @trait __dirname, '../../traits/protected'

  @share()

  @set
    softDelete      : yes

    permissions     :
      'create filters'     : ['member']
      'edit filters'       : ['member']
      'edit own filters'   : ['member']
      'delete filters'     : ['member']
      'delete own filters' : ['member']
      'list filters'       : ['member']
      'list own filters'   : ['member']

    sharedMethods   :
      instance      : []
      static        : ['createFilter', 'fetchFiltersByContext', 'remove']

    indexes         :
      name          : 'unique'

    schema          :
      name          :
        type        : String
        required    : yes
      match         :
        type        : String
        required    : yes
      type          :
        type        : String
        required    : yes
      owner         : ObjectId

      createdAt     :
        type        : Date
        default     : -> new Date
      modifiedAt    :
        type        : Date
        default     : -> new Date

  @createFilter : permit 'create filters',
    success : (client, params, callback)->
      {delegate}   = client.connection
      params.owner = delegate.getId()
      newFilter    = new JProxyFilter params
      newFilter.save (err)->
        return callback err if err

        delegate.addProxyFilter newFilter, (err)->
          return callback err if err
          callback null, newFilter

  @fetchFiltersByContext: permit 'list filters',
    success: (client, callback)->
      {delegate} = client.connection
      @some {owner:delegate.getId()}, {name:1, match:1},  (err, filters)->
        return callback err if err
        callback err, filters

  @remove$: permit 'delete filters',
    success: (client, selector, callback)->
      {delegate} = client.connection
      selector.owner = delegate.getId()

      @one selector, {}, (err, filter)=>
        return callback err if err

        @remove selector, (err)->
          return callback err if err

        match = filter.match 

        JProxyRestriction.update
          "ruleList.match": match
        , {$pull: {"ruleList": {match}}}
        , (err)->
          return callback err if err

        callback null

  



<commit_msg>proxy: add signature annotations<commit_after>jraphical = require 'jraphical'
KodingError = require '../../error'

module.exports = class JProxyFilter extends jraphical.Module

  {secure, ObjectId, signature} = require 'bongo'
  {Relationship}     = jraphical
  {permit}           = require '../group/permissionset'
  JProxyRestriction  = require './restriction'

  @trait __dirname, '../../traits/protected'

  @share()

  @set
    softDelete      : yes

    permissions     :
      'create filters'     : ['member']
      'edit filters'       : ['member']
      'edit own filters'   : ['member']
      'delete filters'     : ['member']
      'delete own filters' : ['member']
      'list filters'       : ['member']
      'list own filters'   : ['member']

    sharedMethods   :
      static        :
        createFilter:
          (signature Object, Function)
        fetchFiltersByContext:
          (signature Function)
        remove:
          (signature Object, Function)
    indexes         :
      name          : 'unique'

    schema          :
      name          :
        type        : String
        required    : yes
      match         :
        type        : String
        required    : yes
      type          :
        type        : String
        required    : yes
      owner         : ObjectId

      createdAt     :
        type        : Date
        default     : -> new Date
      modifiedAt    :
        type        : Date
        default     : -> new Date

  @createFilter : permit 'create filters',
    success : (client, params, callback)->
      {delegate}   = client.connection
      params.owner = delegate.getId()
      newFilter    = new JProxyFilter params
      newFilter.save (err)->
        return callback err if err

        delegate.addProxyFilter newFilter, (err)->
          return callback err if err
          callback null, newFilter

  @fetchFiltersByContext: permit 'list filters',
    success: (client, callback)->
      {delegate} = client.connection
      @some {owner:delegate.getId()}, {name:1, match:1},  (err, filters)->
        return callback err if err
        callback err, filters

  @remove$: permit 'delete filters',
    success: (client, selector, callback)->
      {delegate} = client.connection
      selector.owner = delegate.getId()

      @one selector, {}, (err, filter)=>
        return callback err if err

        @remove selector, (err)->
          return callback err if err

        match = filter.match 

        JProxyRestriction.update
          "ruleList.match": match
        , {$pull: {"ruleList": {match}}}
        , (err)->
          return callback err if err

        callback null

  




{'fraction_non_alphanumeric': 0.10643185298621746, 'fraction_numerical': 0.0007656967840735069, 'mean_word_length': 1.741343126967471, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 25, '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': '7654613', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1360, 'n_words': 403}