danmunn / redmine_dmsf

Fork of svn repository for redmine_dmsf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loss of workflow on new revision

CtrlMajSup opened this issue · comments

Hello,

I'd like to know if it's possible to update a file via the API while keeping the validation workflow.

Let me explain. I create a file and assign a workflow to it. Later, the file is updated by another application. On this other application, I follow the steps below:

  1. Create a new revision
  2. Download the contents of the file (Upload)
  3. Commit

However, the problem is that my file in the DMSF loses its assignment each time a new revision is created via the API.

To create this new revision, I use the following: https://github.com/danmunn/redmine_dmsf/wiki/REST-API

The other option would be to create a revision and assign a workflow to a specific step via API, but I haven't found an endpoint for that.

Thank you for any help.

You can assign an approval workflow when creating a new revision via REST API by adding dmsf_workflow_id parameter:

<?xml version="1.0" encoding="utf-8" ?>
<dmsf_file_revision>
        <title>test</title>
        <name>test.sql</name>
        <description>SQL script</description>
        <comment>REST API</comment>
        <custom_field_values>
                <custom_field_value1>Validation</custom_field_value1>
        </custom_field_values>
</dmsf_file_revision>
<dmsf_workflow_id>your_approval_workflow_id</dmsf_workflow_id>

I haven't tested it, but it should be this way.

Good morning,

Either I've misunderstood how to use it or it doesn't work.

I got around the problem by intercepting the revision after it has been created. If the revision has a custom field with a certain value, then you can assign a workflow to it.

  • my_plugin/lib/revision_workflow.rb
module RevisionWorkflow
    module DmsfFileRevisionPatch
      extend ActiveSupport::Concern
  
      included do
        after_create :assign_workflow_formulaire
      end
  
      private
  
    def assign_workflow_formulaire
        self.custom_field_values.each do |custom_field_value|
            # Vérifier si l'ID du champ personnalisé correspond à 1
            if custom_field_value.custom_field.id == 1
              # Afficher la valeur du champ personnalisé
              Rails.logger.info("La valeur du champ personnalisé 1 est : #{custom_field_value.value}")
              if custom_field_value.value.to_i == 1
                Rails.logger.info("Ajout du workflow")
                self.set_workflow(1, 'assign')
                self.assign_workflow(1)
                self.save!
              else
                Rails.logger.info("cette révision n'est pas un rendu")
              end
            end
        end
    end
end
end
  
  # Appliquer le patch
  DmsfFileRevision.send(:include, RevisionWorkflow::DmsfFileRevisionPatch)

In any case, thank you for replying

Adding a revision is described in chapter 4. - https://github.com/danmunn/redmine_dmsf/wiki/REST-API#4-create-a-new-revision
To create a revision you need a XML file with the new revision's attributes. If you add dmsf_workflow_id, it assigns that workflow to the revision.