コード例 #1
0
 def unset_update(self, collection: str, field: str):
     try:
         ack = self._unset_update_many(collection, field)
     except (CMDBError, Exception) as err:
         LOGGER.error(err)
         raise ObjectManagerUpdateError(err)
     return ack.acknowledged
コード例 #2
0
    def update_object(self,
                      data: (dict, CmdbObject),
                      user: UserModel = None,
                      permission: AccessControlPermission = None) -> str:

        if isinstance(data, dict):
            update_object = CmdbObject(**data)
        elif isinstance(data, CmdbObject):
            update_object = data
        else:
            raise ObjectManagerUpdateError(
                'Wrong CmdbObject init format - expecting CmdbObject or dict')
        update_object.last_edit_time = datetime.utcnow()
        if user:
            update_object.editor_id = user.public_id

        type_ = self._type_manager.get(update_object.type_id)
        verify_access(type_, user, permission)

        ack = self._update(collection=CmdbObject.COLLECTION,
                           public_id=update_object.get_public_id(),
                           data=update_object.__dict__)
        # create cmdb.core.object.updated event
        if self._event_queue and user:
            event = Event(
                "cmdb.core.object.updated", {
                    "id": update_object.get_public_id(),
                    "type_id": update_object.get_type_id(),
                    "user_id": user.get_public_id()
                })
            self._event_queue.put(event)
        return ack.acknowledged
コード例 #3
0
 def update_category(self, category: CategoryModel):
     """Update a existing category into the database"""
     try:
         return self._update(collection=CategoryModel.COLLECTION,
                             public_id=category.get_public_id(),
                             data=CategoryModel.to_json(category))
     except Exception as err:
         raise ObjectManagerUpdateError(err=err)
コード例 #4
0
 def update_status(self, data):
     try:
         updated_status = CmdbStatus(**data)
         ack = self._update(CmdbStatus.COLLECTION,
                            updated_status.get_public_id(),
                            updated_status.to_database())
     except (CMDBError, Exception) as err:
         LOGGER.error(err)
         raise ObjectManagerUpdateError(err)
     return ack.acknowledged
コード例 #5
0
 def update_object(self, data: (dict, CmdbObject),
                   request_user: User) -> str:
     if isinstance(data, dict):
         update_object = CmdbObject(**data)
     elif isinstance(data, CmdbObject):
         update_object = data
     else:
         raise ObjectManagerUpdateError(
             'Wrong CmdbObject init format - expecting CmdbObject or dict')
     update_object.last_edit_time = datetime.utcnow()
     ack = self._update(collection=CmdbObject.COLLECTION,
                        public_id=update_object.get_public_id(),
                        data=update_object.to_database())
     # create cmdb.core.object.updated event
     if self._event_queue and request_user:
         event = Event(
             "cmdb.core.object.updated", {
                 "id": update_object.get_public_id(),
                 "type_id": update_object.get_type_id(),
                 "user_id": request_user.get_public_id()
             })
         self._event_queue.put(event)
     return ack.acknowledged
コード例 #6
0
    def update_object(self,
                      data: (dict, CmdbObject),
                      user: UserModel = None,
                      permission: AccessControlPermission = None) -> str:

        if isinstance(data, dict):
            update_object = CmdbObject(**data)
        elif isinstance(data, CmdbObject):
            update_object = data
        else:
            raise ObjectManagerUpdateError(
                'Wrong CmdbObject init format - expecting CmdbObject or dict')
        update_object.last_edit_time = datetime.now(timezone.utc)
        if user:
            update_object.editor_id = user.public_id

        type_ = self._type_manager.get(update_object.type_id)
        if not type_.active:
            raise AccessDeniedError(
                f'Objects cannot be updated because type `{type_.name}` is deactivated.'
            )
        verify_access(type_, user, permission)

        ack = self._update(collection=CmdbObject.COLLECTION,
                           public_id=update_object.get_public_id(),
                           data=update_object.__dict__)

        if self._event_queue and user:
            event = Event(
                "cmdb.core.object.updated", {
                    "id": update_object.get_public_id(),
                    "type_id": update_object.get_type_id(),
                    "user_id": user.get_public_id(),
                    'event': 'update'
                })
            self._event_queue.put(event)
        return ack.acknowledged