 
 module.exports = class JApiToken extends jraphical.Module
 
+  Validators = require './group/validators'
+
+  PERMISSION_EDIT_GROUPS = [
+    { permission: 'edit groups',     superadmin: yes }
+    { permission: 'edit own groups', validateWith: Validators.group.admin }
+  ]
+
+
   @share()
 
   @set
-    sharedEvents     :
-      static         : []
-      instance       : []
-    permissions      :
-      'create token' : ['admin']
-      'remove token' : ['admin']
-    indexes          :
-      code           : 'unique'
-    sharedMethods    :
+    sharedEvents       :
+      static           : []
+      instance         : []
+    permissions        :
+      'edit groups'    : ['moderator']
+      'edit own groups': ['member', 'moderator']
+    indexes            :
+      code             : 'unique'
+    sharedMethods      :
       static:
         create: [
           (signature Function)

      instance:
        remove:
          (signature Function)
    schema           :
      code           :
        type         : String
        required     : yes
        default      : hat
      group          :
        type         : String
        required     : yes
      originId       :
        type         : ObjectId
        required     : yes
      createdAt      :
        type         : Date
        default      : -> new Date
      modifiedAt     :
        type         : Date
        default      : -> new Date


  @create: (data, callback) ->

      JApiToken.create data, callback


  remove$: permit
    advanced: PERMISSION_EDIT_GROUPS
    success: (client, callback) ->
      @remove callback

