This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to prevent user from changing files of a document

We have a workflow where users can import receipts in M-Files and they are approved by several persons depending on the metadata. Changes of the files should not be allowed, but information is filled in the metadata during the workflow. The only solution I have found to prevent changes of the document files, is to check with a script in the AfterCheckInChanges event handler. The script checks if the files of the document have changed since the last version.
Dim objFiles: Set objFiles = Vault.ObjectFileOperations.GetFiles(ObjVer)
' During the creation of the object no test is necessary
if ObjVer.Version > 1 then
' Getting files of previous version
Dim ObjVerOld: Set ObjVerOld = ObjVer.Clone()
ObjVerOld.Version = ObjVerOld.Version-1
Dim objFilesOld: Set objFilesOld = Vault.ObjectFileOperations.GetFiles(ObjVerOld)

' If count of files differ then raise exception
if objFiles.Count <> objFilesOld.count then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien hinzugef?gt oder entfernt werden!"
end if

Dim found
For index = 1 To objFiles.Count
' If a file has a version greater 1 then it was changed => raise exception
if objFiles.Item(index).FileVer.Version <> 1 then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien ver?ndert werden!"
end if

' If the GUID of the file has changed then the file was replaced => raise exception
found = false
For indexOld = 1 To objFilesOld.Count
if objFiles.Item(index).FileGUID = objFilesOld.Item(indexOld).FileGUID then
found = true
Exit for
end if
Next
if found = false then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien ausgestauscht werden!"
end if
Next
end if

Is this the recommended solution or is there a simpler way to achive this behaviour?
Thanks for the help.
Parents
  • Hi,

    Not quite sure if I understood: you want to move document through workflow but you don't want that anyone change document's content. I think you could make read-only access on document for all involved users. Still you could enable state transitions for specific users so they can move it through workflow states. You could calculate needed properties on the server side. I think with that approach you could keep content not editable. It would not work in case you want your users manually change metadata as unfortunately access is on whole document (metadata + files).
    Another approach if you use document collection, you enable read-only access on all documents inside but collection is still editable, users can change metadata, move it through transition but can not edit documents and their metadata. Not quite sure if they could add new documents into document collection, this must be verified if possible to be prevented.

    D.
Reply
  • Hi,

    Not quite sure if I understood: you want to move document through workflow but you don't want that anyone change document's content. I think you could make read-only access on document for all involved users. Still you could enable state transitions for specific users so they can move it through workflow states. You could calculate needed properties on the server side. I think with that approach you could keep content not editable. It would not work in case you want your users manually change metadata as unfortunately access is on whole document (metadata + files).
    Another approach if you use document collection, you enable read-only access on all documents inside but collection is still editable, users can change metadata, move it through transition but can not edit documents and their metadata. Not quite sure if they could add new documents into document collection, this must be verified if possible to be prevented.

    D.
Children
No Data