Esempio n. 1
0
    def patch(self, action_uuid, patch):
        """Update an existing action.

        :param action_uuid: UUID of a action.
        :param patch: a json PATCH document to apply to this action.
        """
        # FIXME: blueprint edit-action-plan-flow
        raise exception.OperationNotPermitted(
            _("Cannot modify an action directly"))

        if self.from_actions:
            raise exception.OperationNotPermitted

        action_to_update = objects.Action.get_by_uuid(pecan.request.context,
                                                      action_uuid)
        try:
            action_dict = action_to_update.as_dict()
            action = Action(**api_utils.apply_jsonpatch(action_dict, patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Action.fields:
            try:
                patch_val = getattr(action, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if action_to_update[field] != patch_val:
                action_to_update[field] = patch_val

        action_to_update.save()
        return Action.convert_with_links(action_to_update)
Esempio n. 2
0
 def validate(patch):
     if patch.path == "/goal" and patch.op != "remove":
         AuditTemplatePatchType._validate_goal(patch)
     elif patch.path == "/goal" and patch.op == "remove":
         raise exception.OperationNotPermitted(
             _("Cannot remove 'goal' attribute "
               "from an audit template"))
     if patch.path == "/strategy":
         AuditTemplatePatchType._validate_strategy(patch)
     return types.JsonPatchType.validate(patch)
Esempio n. 3
0
    def delete(self, action_uuid):
        """Delete a action.

        :param action_uuid: UUID of a action.
        """
        # FIXME: blueprint edit-action-plan-flow
        raise exception.OperationNotPermitted(
            _("Cannot delete an action directly"))

        action_to_delete = objects.Action.get_by_uuid(pecan.request.context,
                                                      action_uuid)
        action_to_delete.soft_delete()
Esempio n. 4
0
    def post(self, action):
        """Create a new action.

        :param action: a action within the request body.
        """
        # FIXME: blueprint edit-action-plan-flow
        raise exception.OperationNotPermitted(
            _("Cannot create an action directly"))

        if self.from_actions:
            raise exception.OperationNotPermitted

        action_dict = action.as_dict()
        context = pecan.request.context
        new_action = objects.Action(context, **action_dict)
        new_action.create()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('actions', new_action.uuid)
        return Action.convert_with_links(new_action)