 hat           = require 'hat'
+async         = require 'async'
 JGroup        = require './group'
 JAccount      = require './account'
 jraphical     = require 'jraphical'
 KodingError   = require '../error'
 { permit }    = require './group/permissionset'
-{ daisy
-  secure
+{ secure
   ObjectId
   signature } = require 'bongo'
 


    { account, group } = data

    groupObj = null

    unless account and group


    queue = [

      (next) ->
        # validating data params
        unless account instanceof JAccount
          return next new KodingError 'account is not an instance of Jaccount!'

        JGroup.one { slug : group }, (err, group_) ->
          return next err                                 if err
          return next new KodingError 'group not found!'  unless group_

          unless !!group_.getAt 'isApiEnabled'
            return next new KodingError 'API usage is not enabled for this group.'

          groupObj = group_
          next()

      (next) ->
        limitError = "You can't have more than #{JGroup.API_TOKEN_LIMIT} api tokens"
        JApiToken.count { group : groupObj.slug }, (err, count) ->
          return next err                         if err
          return next new KodingError limitError  if count >= JGroup.API_TOKEN_LIMIT
          next()

      (next) ->
        # creating token
        token = new JApiToken
          code     : hat()
