Exemple #1
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)
Exemple #2
0
 def wrap(self, *args, **kwargs):
     query = kwargs.get('query')
     if query:
         to_data = yield dbapi.db_find_one(self.table, query())
         if to_data:
             raises.Forbidden(message.exist(self.table, query()))
     ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
     raise gen.Return(ret)
Exemple #3
0
 def wrap(self, data, *args, **kwargs):
     db_keys = kwargs.pop('db_keys', [])
     query = self._update_query(db_keys, data)
     if query:
         to_data = yield dbapi.db_find_one(self.table, query)
         if to_data:
             raises.Forbidden(message.exist(self.table, query))
     ret = yield gen.coroutine(xstep)(self, data, *args, **kwargs)
     raise gen.Return(ret)
Exemple #4
0
 def wrap(self, *args, **kwargs):
     query = kwargs.get('query')
     if query:
         query_data = query()
         if self.table == 'pods':
             if query_data.get('name') is not None:
                 query_data['name'] = re.compile(
                     '\\b' + query_data.get('name') + '\\b', re.IGNORECASE)
         to_data = yield dbapi.db_find_one(self.table, query_data)
         if to_data:
             raises.Forbidden(message.exist(self.table, query()))
     ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
     raise gen.Return(ret)
Exemple #5
0
 def _update_requests_add_projects(self, version):
     exists = list()
     malformat = list()
     for n in self.body:
         try:
             f_n = models.ScenarioProject.from_dict_with_raise(n)
             if not any(o.project == f_n.project for o in version.projects):
                 version.projects.append(f_n)
             else:
                 exists.append(n['project'])
         except Exception as e:
             malformat.append(e.message)
     if malformat:
         raises.BadRequest(message.bad_format(malformat))
     elif exists:
         raises.Conflict(message.exist('projects', exists))
 def _update_with_body(self, clazz, field, withs):
     exists = list()
     malformat = list()
     for new in self.body:
         try:
             format_new = clazz.from_dict_with_raise(new)
             new_name = getattr(format_new, field)
             if not any(getattr(o, field) == new_name for o in withs):
                 withs.append(format_new)
             else:
                 exists.append(new_name)
         except Exception as error:
             malformat.append(error.message)
     if malformat:
         raises.BadRequest(message.bad_format(malformat))
     elif exists:
         raises.Conflict(message.exist('{}s'.format(field), exists))
     return withs
Exemple #7
0
 def _update_requests_update_projects(self, version):
     exists = list()
     malformat = list()
     projects = list()
     for n in self.body:
         try:
             f_n = models.ScenarioProject.from_dict_with_raise(n)
             if not any(o.project == f_n.project for o in projects):
                 projects.append(models.ScenarioProject.from_dict(n))
             else:
                 exists.append(n['project'])
         except:
             malformat.append(n)
     if malformat:
         raises.BadRequest(message.bad_format(malformat))
     elif exists:
         raises.Forbidden(message.exist('projects', exists))
     version.projects = projects
Exemple #8
0
 def error(data):
     return httplib.FORBIDDEN, message.exist('project', data.name)
Exemple #9
0
 def tc_error(data):
     return httplib.FORBIDDEN, message.exist('testcase', data.name)
Exemple #10
0
 def error(data):
     return httplib.FORBIDDEN, message.exist('scenario', data.name)