Пример #1
0
    def _delete(self, query):
        data = yield self._eval_db_find_one(query)
        if data is None:
            raises.NotFound(message.not_found(self.table, query))

        yield self._eval_db(self.table, 'remove', query)
        self.finish_request()
Пример #2
0
    def _update(self, query, db_keys):
        if self.json_args is None:
            raises.BadRequest(message.no_body())

        # check old data exist
        from_data = yield self._eval_db_find_one(query)
        if from_data is None:
            raises.NotFound(message.not_found(self.table, query))

        data = self.table_cls.from_dict(from_data)
        # check new data exist
        equal, new_query = self._update_query(db_keys, data)
        if not equal:
            to_data = yield self._eval_db_find_one(new_query)
            if to_data is not None:
                raises.Forbidden(message.exist(self.table, new_query))

        # we merge the whole document """
        edit_request = self._update_requests(data)
        """ Updating the DB """
        yield self._eval_db(self.table,
                            'update',
                            query,
                            edit_request,
                            check_keys=False)
        edit_request['_id'] = str(data._id)
        self.finish_request(edit_request)
Пример #3
0
 def wrap(self, *args, **kwargs):
     query = kwargs.get('query')
     data = yield dbapi.db_find_one(self.table, query)
     if not data:
         raises.NotFound(message.not_found(self.table, query))
     ret = yield gen.coroutine(xstep)(self, data, *args, **kwargs)
     raise gen.Return(ret)
Пример #4
0
    def put(self):
        db_keys = []
        openid = self.get_secure_cookie(auth_const.OPENID)

        if openid:
            query = {'openid': openid}
            user = yield dbapi.db_find_one(self.table, query)
            if not user:
                raises.NotFound(message.not_found(self.table, query))

            self._update(query=query, db_keys=db_keys)
        else:
            raises.Unauthorized(message.no_auth())
Пример #5
0
    def get(self, test_id):
        query = dict()
        query["_id"] = objectid.ObjectId(test_id)

        data = yield dbapi.db_find_one(self.table, query)
        if not data:
            raises.NotFound(message.not_found(self.table, query))

        validation = yield self._check_api_response_validation(data['id'])

        data.update({'validation': validation})

        self.finish_request(self.format_data(data))
Пример #6
0
    def get(self, test_id):
        query = dict()
        query["_id"] = objectid.ObjectId(test_id)

        data = yield dbapi.db_find_one(self.table, query)
        if not data:
            raises.NotFound(message.not_found(self.table, query))

        # only do this when it's nfvi not vnf
        if 'is_onap' not in data.keys() or data['is_onap'] != 'true':
            validation = yield self._check_api_response_validation(data['id'])
            data.update({'validation': validation})

        self.finish_request(self.format_data(data))
Пример #7
0
 def delete(self, result_id):
     curr_user = self.get_secure_cookie(auth_const.OPENID)
     curr_user_role = self.get_secure_cookie(auth_const.ROLE)
     if curr_user is not None:
         query = {'_id': objectid.ObjectId(result_id)}
         test_data = yield dbapi.db_find_one(self.table, query)
         if not test_data:
             raises.NotFound(message.not_found(self.table, query))
         if curr_user == test_data['owner'] or \
            curr_user_role.find('administrator') != -1:
             self._delete(query=query)
         else:
             raises.Forbidden(message.no_auth())
     else:
         raises.Unauthorized(message.no_auth())
Пример #8
0
 def _get_one(self, query):
     data = yield self._eval_db_find_one(query)
     if data is None:
         raises.NotFound(message.not_found(self.table, query))
     self.finish_request(self.format_data(data))