Exemple #1
0
 def post(self):
     '''
         Create (ORG)
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True if struct and not struct.get('errors') else False)
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON': format_pass})
         return
     # request query arguments
     query_args = self.request.arguments
     # get account from new org struct
     account = struct.get('account', None)
     # get the current frontend username from token
     username = self.get_username_token()
     # if the user don't provide an account we use the username
     account = (query_args.get('account', [username])[0]
                if not account else account)
     # execute new org struct
     org_uuid = yield self.new_org(struct)
     # add_org to user -> the struct['account'] here is the org_account
     new_org = yield self.add_org(struct['created_by'], struct['account'],
                                  org_uuid)
     # complete message with receive uuid.
     message = {'uuid': org_uuid}
     if 'error' in message['uuid']:
         scheme = 'org'
         reason = {'duplicates': [(scheme, 'account'), (scheme, 'uuid')]}
         message = yield self.let_it_crash(struct, scheme, message['uuid'],
                                           reason)
         self.set_status(400)
     else:
         self.set_status(201)
     self.finish(message)
Exemple #2
0
 def patch(self, org_uuid):
     '''
         Modify (ORG)
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True
                    if not dict(struct).get('errors', False) else False)
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON': format_pass})
         return
     account = self.request.arguments.get('account', [None])[0]
     if not account:
         # if not account we try to get the account from struct
         account = struct.get('account', None)
     # remove query string flag
     remove = self.request.arguments.get('remove', False)
     if not remove:
         result = self.cache.delete('org:{0}'.format(org_uuid))
         result = yield self.modify_account(account, org_uuid, struct)
     else:
         result = self.cache.delete('org:{0}'.format(org_uuid))
         result = yield self.modify_remove(account, org_uuid, struct)
     if not result:
         self.set_status(400)
         system_error = errors.Error('missing')
         error = system_error.missing('org', org_uuid)
         self.finish(error)
         return
     self.set_status(200)
     self.finish({'message': 'update completed successfully'})
Exemple #3
0
 def patch(self, org_uuid):
     '''
         Modify (ORG)
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True if not dict(struct).get('errors', False) else False)
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON':format_pass})
         return
     account = self.request.arguments.get('account', [None])[0]
     if not account:
         # if not account we try to get the account from struct
         account = struct.get('account', None)
     # remove query string flag
     remove = self.request.arguments.get('remove', False)
     if not remove :
         result = self.cache.delete('org:{0}'.format(org_uuid))
         result = yield self.modify_account(account, org_uuid, struct)
     else:
         result = self.cache.delete('org:{0}'.format(org_uuid))
         result = yield self.modify_remove(account, org_uuid, struct)
     if not result:
         self.set_status(400)
         system_error = errors.Error('missing')
         error = system_error.missing('org', org_uuid)
         self.finish(error)
         return
     self.set_status(200)
     self.finish({'message': 'update completed successfully'})
Exemple #4
0
 def post(self):
     '''
         Create (ORG)
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True if struct and not struct.get('errors') else False)
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON':format_pass})
         return
     # request query arguments
     query_args = self.request.arguments
     # get account from new org struct
     account = struct.get('account', None)
     # get the current frontend username from token
     username = self.get_username_token()
     # if the user don't provide an account we use the username
     account = (query_args.get('account', [username])[0] if not account else account)
     # execute new org struct
     org_uuid = yield self.new_org(struct)
     # add_org to user -> the struct['account'] here is the org_account
     new_org = yield self.add_org(struct['created_by'], struct['account'], org_uuid)
     # complete message with receive uuid.
     message = {'uuid':org_uuid}
     if 'error' in message['uuid']:
         scheme = 'org'
         reason = {'duplicates': [
             (scheme, 'account'),
             (scheme, 'uuid')
         ]}
         message = yield self.let_it_crash(struct, scheme, message['uuid'], reason)
         self.set_status(400)
     else:
         self.set_status(201)
     self.finish(message)
Exemple #5
0
    def patch(self, task_uuid):
        '''
            Modify task
        '''
        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.request.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True if not dict(struct).get('errors', False) else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        account = self.request.arguments.get('account', [None])[0]

        logging.info('account {0} uuid {1} struct {2}'.format(account, task_uuid, struct))

        result = yield self.modify_task(account, task_uuid, struct)

        if not result:
            self.set_status(400)
            system_error = errors.Error('missing')
            error = system_error.missing('task', task_uuid)
            self.finish(error)
            return

        self.set_status(200)
        self.finish({'message': 'update completed successfully'})
Exemple #6
0
    def post(self, account):
        '''
            Post records handler
        '''
        struct = yield check_json(self.request.body)
        db = self.settings['db']

        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return
        
        if account == self.get_current_user():
            struct['account'] = account
        
        # check if ORGs follows same pattern.
        
        else:
            self.set_status(404)
            self.finish({'WARNING':'Pre-Access patterns research'})
            return
        
        record = yield self.new_detail_record(struct)

        if not record:
            model = 'Records'
            error = {'record':False}
            reason = {'duplicates':[('Record', 'uniqueid'), (model, 'uuid')]}

            message = yield self.let_it_crash(struct, model, error, reason)

            self.set_status(400)
            self.finish(message)
            return

        # -- handle this out-of-band.

        resource = {
            'account': account,
            'resource': 'records',
            'uuid': record
        }

        update = yield new_resource(db, resource)

        # logging new resource update
        logging.info('update %s' % update)

        if not update:
            logging.warning(
                'account: %s new_resource record: %s update.' % (account, record)
            )

        self.set_status(201)
        self.finish({'uuid':record})
Exemple #7
0
    def post(self):
        '''
            Post records handler
        '''
        struct = yield check_json(self.request.body)
        db = self.settings['db']
        
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        record = yield self.new_detail_record(struct)
 
        if not record:
            model = 'Records'
            error = {'record':False}
            reason = {'duplicates':[('Record', 'uniqueid'), (model, 'uuid')]}

            message = yield self.let_it_crash(struct, model, error, reason)

            self.set_status(400)
            self.finish(message)
            return
        
        if 'accountcode' in struct:

            account = struct.get('accountcode')

            resource = {
                'account': account,
                'resource':'records',
                'uuid':record
            }

            exist = yield self.check_exist(account)

            logging.info('check if exist %s ' % exist)

            if exist:
                update = yield new_resource(db, resource)

                logging.info('update %s' % update)

                flag = yield self.set_assigned_flag(account, record)

        logging.info('new spawned record %s ' % record)

        self.set_status(201)
        self.finish({'uuid':record})
Exemple #8
0
 def post(self):
     '''
         Create user account
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True if struct and not struct.get('errors') else False)
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON': format_pass})
         return
     # create new user struct
     user_uuid = yield self.new_user(struct)
     # complete message with receive uuid.
     message = {'uuid': user_uuid}
     self.set_status(201)
     self.finish(message)
Exemple #9
0
    def post(self, account):
        '''
            Create new record billing route
        '''
        
        struct = yield check_json(self.request.body)
        
        # where is the error msg?

        if not struct:
            self.set_status(400)
            self.finish(error)
            return
        
        struct['account'] = account

        logging.info('routes handler struct? %s' % (struct))
                
        result = yield self.new_route(struct)

        self.finish()
Exemple #10
0
    def post(self):
        '''
            Create user account
        '''
        struct = yield check_json(self.request.body)
        
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new account structure %s' % str(struct))

        result = yield self.new_account(struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return


        # -- handle SIP account creation out-of-band

        # postgresql insert sip account
        if result:
            sip_account = yield self.new_sip_account(struct)


        self.set_status(201)
        self.finish({'uuid':result})
Exemple #11
0
    def patch(self, account):
        '''
            Update user account
        '''

        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.result.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new update on account structure %s' % str(struct))

        result = yield self.modify_account(account, struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid':result})
Exemple #12
0
 def patch(self, user_uuid):
     '''
         Modify user
     '''
     struct = yield check_json(self.request.body)
     format_pass = (True if struct and not struct.get('errors') else False)
     message = {'message': 'not found'}
     if not format_pass:
         self.set_status(400)
         self.finish({'JSON': format_pass})
         return
     account = self.request.arguments.get('account', [None])[0]
     if not account:
         # if not account we try to get the account from struct
         account = struct.get('account', None)
     result = yield self.modify_user(account, user_uuid, struct)
     if not result:
         self.set_status(400)
         self.finish(message)
         return
     self.set_status(400)
     message = {'message': 'update completed successfully'}
     self.finish(message)
Exemple #13
0
    def post(self, account):
        '''
            Create organization accounts
        '''
        logging.info('hola hola hola hola')
        logging.info(account)
        struct = yield check_json(self.request.body)
        struct['account_type'] = 'org'

        org = struct['account']
        
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        # logging new contact structure
        logging.info('new contact structure {0}'.format(str(struct)))

        # logging request query arguments
        logging.info(self.request.arguments)

        # request query arguments
        query_args = self.request.arguments

        # get owner account from new org struct
        owner_user = struct.get('owner', None)

        # get the current frontend logged username
        username = self.get_current_username()

        # last but not least, we check query_args for owner
        owner_user = (query_args.get('owner', [username])[0] if not owner_user else owner_user)
        
        # we use the front-end username as last resort
        #if not struct.get('owner'):
        #    struct['owner'] = owner_user

        new_org = yield self.new_account(struct)
        
        if 'error' in new_org:
            scheme = 'org'
            reason = {'duplicates':[
                (scheme, 'account'),
                (scheme, 'email')
            ]}
            message = yield self.let_it_crash(struct, scheme, new_org, reason)
            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        team = {
            'name': 'owners',
            'permission': 'admin',
            'members': [owner_user]
        }

        check_member, check_team = yield [
            self.new_member(org, owner_user),
            self.new_team(org, team)
        ]

        self.set_status(201)
        self.finish({'uuid':new_org})