Ejemplo n.º 1
0
 def delete(self, id=None):
     log.debug('delete')
     """ deletes a single user db record """
     """ check to see if there is a User ID """
     if not id:
         message = {
             'status':  404,
             'title':   'Error Deleting User',
             'message': 'No ID given.'
         }
         return message
     """ attempt to delete User """
     try:
         userId     = int(id)
         userObject = User().getById(userId)
         userName   = userObject.userName
         userObject.deleteObject()
         self._log_version(userObject.userName, 'userDelete', "{'id': 0, 'group': [ ]}", json.dumps(self._user_to_json(userObject)))
         db.commit()
         message = {
             'status':  200,
             'title':   'Successfully Deleted User',
             'message': 'User %s successfully deleted.'%userName
         }
     except InvalidRequestError, e:
         message = {
             'status':  404,
             'title':   'Error Deleting User',
             'message': e.message
         }
Ejemplo n.º 2
0
 def update(self, id=None):
     log.debug('update')
     """ updates a single user db record """
     params = request.params
     log.debug(params)
     """ check to see if there is a User ID """
     if not id:
         message = {
             'status':  404,
             'title':   'Error Updating User',
             'message': 'No ID given.'
         }
         return message
     """ attempt to update User """
     try:
         userId     = int(id)
         userObject = User().getById(userId)
         previous   = json.dumps(self._user_to_json(userObject))
         userObject.setUserData(params, getUser('id'))
         userObject.setGroupData(params)
         self._log_version(userObject.userName, 'userUpdate', json.dumps(self._user_to_json(userObject)), previous)
         db.commit()
         message = {
             'status':  200,
             'userId':  userObject.id,
             'title':   'Successfully Updated User',
             'message': 'User %s successfully updated.'%userObject.userName
         }
     except InvalidRequestError, e:
         message = {
             'status':  404,
             'title':   'Error Updating User',
             'message': e.message
         }
Ejemplo n.º 3
0
 def new(self):
     log.debug('new')
     """ create a single user db record """
     params = request.params
     log.debug(params)
     try:
         """ attempt to create a new user """
         userObject = User()
         userObject.addObject()
         userObject.setUserData(params, getUser('id'))
         userObject.setGroupData(params)
         self._log_version(userObject.userName, 'userCreate', json.dumps(self._user_to_json(userObject)), "{'id': 0, 'group': [ ]}")
         db.commit()
         message = {
             'status':  200,
             'userId':  userObject.id,
             'title':   'Successfully Created User',
             'message': 'User %s successfully created.'%userObject.userName
         }
     except InvalidRequestError, e:
         log.error(e.message)
         message = {
             'status':  404,
             'title':   'Error Creating User',
             'message': e.message
         }
Ejemplo n.º 4
0
    def setby(self):
        log.debug('setby')
        """ sets the smart pricing factor for atoms """
        params = request.params
        log.debug(params)
        qFactor = QualityFactor()
        try:
            categories = params.getall('category_id')
            atoms      = params.getall('atom_id')
            for cid in categories:
                all_atoms = [ ]
                if cid in atoms and params.has_key('factor_' + cid):
#                    log.debug("By Atom: %s"%cid)
#                    log.debug("Atom: PublisherID: %s; Atom ID: %s; Factor: %s; Notes: %s; Country Code: %s;"%(params['publisher_id'], cid, params['factor_' + cid], params['notes_' + cid], params['country']))
                    qFactor.set(params['publisher_id'], cid, params['factor_' + cid], params['notes_' + cid], getUser('id'))
                else:
                    category  = TaxiiCategory(int(cid), None, params['country'])
                    all_atoms = self._all_atoms(category, all_atoms)
#                    log.debug("By Category: %s"%cid)
#                    log.debug("CID: %d; Label: %s"%(category.id(), category.label()))
                    for atomId in all_atoms:
                        if atomId in atoms and params.has_key('factor_' + atomId):
                            continue
#                        log.debug("CID Atoms: PublisherID: %s; Atom ID: %s; Factor: %s; Notes: %s; Country Code: %s;"%(params['publisher_id'], atomId, params['factor_' + cid], params['notes_' + cid], params['country']))
                        qFactor.set(params['publisher_id'], atomId, params['factor_' + cid], params['notes_' + cid], getUser('id'))
            db.commit()
            flash("Categories Updated for Publisher ID: %s"%params['publisher_id'])
        except Exception, e:
            log.debug(e)
            flash("Failed to update Categories")
Ejemplo n.º 5
0
    def details(self):
        log.debug('details')
        """ create a single user db record """
        params = request.params
        log.debug(params)
        try:
            """ attempt to create a new user """
#            self._log_version(userObject.userName, 'userCreate', json.dumps(self._user_to_json(userObject)), "{'id': 0, 'group': [ ]}")
            if params['form'] == 'monitor':
                if params['objectId']:
                    object = Monitor().getById(int(params['objectId']))
                else:
                    object = Monitor()
                    object.getMaxId()
                object.name     = params['objectName']
                object.endPoint = params['objectEndPoint']
            elif params['form'] == 'site':
                if params['objectId']:
                    object = Site().getById(int(params['objectId']))
                else:
                    object = Site()
                object.name        = params['objectName']
                object.endPoint    = params['objectEndPoint']
                object.countryCode = params['objectCountryCode']
                object.createdDate = date.datetime.today()
                object.setMonitorData(params)
                object.setHostData(params)
            if params['action'] == 'created':
                object.addObject()
            elif params['action'] == 'deleted':
                object.deleteObject()
            db.commit()
            message = {
                'status':  200,
                'form': params['form'],
                'title':   'Successfully Created User',
                'message': 'Object successfully %s.'%params['action']
            }
        except InvalidRequestError, e:
            log.error(e.message)
            message = {
                'status':  404,
                'form': params['form'],
                'title':   'Error Creating User',
                'message': e.message
            }
Ejemplo n.º 6
0
        except Exception, e:
            userObject = User()
        """ rollback User object """
        if object.action == 'userUpdate':
            userObject.setUserData(json_cmds, getUser('id'))
            action = object.action
        elif object.action == 'userDelete':
            userObject.setUserData(json_cmds, getUser('id'))
            action = 'userCreate'
        elif object.action == 'userCreate':
            userObject.deleteObject()
            action = 'userDelete'
        self._log_version(userObject.userName, action, object.previous, object.active)
        """ redirect to versions page """
        try:
            db.commit()
        except Exception, e:
            log.debug(e)
            abort(500)
        """ redirect to versions page """
        return redirect(url(action = 'versions'))


## these probably belong in a util class, 
## but methods prefixed with "_" are private and not exposed as controller actions
    def _str_to_date(self,strdate):
        """ return a datetime obj from a string """
        ruledate = None
        try:
            ruledate = date.datetime.strptime(strdate, "%Y-%m-%d")
        except ValueError: