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

Preventing document checkout if not needed

Hi M-Files and community,

We have specific case where some power users in last workflow step can change certain metadata before doing workflow transition. This works well through validation so we kind of force users to do transition if they change certain metadata.

However, as those users have edit rights, they can also checkout document. To be able to prevent content changes, I have used Utilities File Version concept and server side validation to check if someone changed content in that workflow step. This also works well and users are confronted with server side error wrapped in M-Files plugin window if they try to change content.

The question which arises why they are able to check the document in the first place. Server side validation is generally not very user friendly and annoys users with stack trace details.

So the question, is there any option to prevent checkout in certain workflow steps through some general configuration? I am not aware but perhaps I miss something.

Best regards,

Dejan

Parents
  • Hello,

    I added a validation on before checkout to check if the user is admin can edit a file, if not it gives an error to end user that they cannot modify the file.

    probably you can do the same using state as trigger.

    I can give you pieces of code on Monday if you need .

  • Hi Radu, 

    Thanks again for this suggestion. Generally, I created OnCheckout event and I am verifying workflow state.

    It seems though when I come to that Published state through normal creation, M-Files checks out document and now I prevent check out of document during that original transition. My use case is actually that when I am on that state, some power users can edit some metadata but can not check out document for changes.

    I was thinking: if I check previous state, I could potentially prevent by checking previous state, but this would not work when I am then really on that workflow state. The check would fail as the previous state is the same one.

    I tried checking workflow transition as this would be what I need but this does not work.

    Do you have an idea,  how could I figure out from where I am coming (from previous state or I am already on that state after transition)?

    Thanks.

    Dejan

  • Hey,

    This in an old script, but it might help you in your case:

    You need to test it, because I am not sure if it works. This is a VB script, in AfterCheckout Event Handler

    If ObjVer.Type = 112 Then
    	Dim userID : userID = CurrentUserID
    	'Err.Raise MFScriptCancel, userID
    
        Dim groups : Set groups = vault.UserGroupOperations.GetGroupsOfUserOrGroup(userID, true)
    	
    	Dim check : check = false
    
        For Each group In groups
    	'Err.Raise MFScriptCancel, group.Name
    		if group.Name = "Secretary" Then
    			check = true
    		End If
    	
    	Next
    
    		If userID = 24 or userID = 192 Then 
    		check = true
    	End If
    	'Err.Raise MFScriptCancel, check
    	If check = false Then
    
    		Dim sObjVersions
    		Set sObjVersions = CreateObject("MfilesAPI.ObjectVersions")
    		Set sObjVersions = Vault.ObjectOperations.GetHistory(ObjVer.ObjID)
    		dim versionnum
    		i=1
    		Dim oFilesold: Set oFilesold = vault.ObjectFileOperations.GetFiles(sObjVersions(2).ObjVer)
    		Dim oFilesnew: Set oFilesnew = vault.ObjectFileOperations.GetFiles(ObjVer)
    		dim check1
    		for i=1 to oFilesold.count
    		if (oFilesold(i).FileVer.Version <> oFilesnew(i).FileVer.Version ) Then
    		check1 = true
    		End if
    		Next
    		if check1 = true then
    		vault.ObjectOperations.ForceUndoCheckout(ObjVer)
    		Err.Raise MFScriptCancel, "This files cannot be modified!" & vbcrlf & "Open file in Read-Only mode!" 
    		End If
    	End If
    End If

    This is a VAF code for blocking editing of templates, but with a little work, you can use it in your use case (maybe a combination of the above script and this one:

    [EventHandler(MFEventHandlerType.MFEventHandlerBeforeCheckOut)]
            private void DoNotEditTemplates(EventHandlerEnvironment env)
            {
                if (env.ObjVerEx.Type == (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument && env.ObjVerEx.IsTemplate && env.CurrentUserID > 0)
                {
                    UserAccount useredit = env.Vault.UserOperations.GetUserAccount(env.CurrentUserID);
    
    
    
                    if (useredit.VaultRoles.ToString() != "3079") //3079 - Full Control of Vault
                    {
                        throw new Exception("You do not have permissions to edit Templates.");
                    }
                }
    
            }

  • thanks Radu. I appreciate a feedback.

    My problem is though that document gets automatically checked out during transitions and I would like to ignore somehow transition case. I want just to prohibit checkout on specific workflow step, not in case someone select transition and click save. Obviously in this case document is also checkout and I can not figure out how to find that transition is selected ...

    Tried following:  if (env.Vault.ObjectOperations.GetLatestObjectVersionAndProperties(env.ObjVer.ObjID, true)
    .Properties.IndexOf(env.GetWorkflowStateTransitionPropertyDefID()) == -1) but it seems that state transition is always -1

    Don't understand how can check transition in before checkout event or how to differentiate this case ...

    But thanks for scripts they brought me to some ideas

  • Well first script allows you to edit metadata, and use transitions, just does not let you edit the document.

  • But you need to use File Version from Compliance Kit.

  • Hey Radu, 

    the problem starts occurring from exactly using File Version. We have found cases when it does not work right. When users checkout document in certain workflow steps and then try to check-in, it works well. But when they checkout document and also select transition in parallel and then try to check in, they are able to make transition happened all together with changes in a document. This should not be the case.

    This is how I came to idea to try to prevent checkout in first place.

    The major problem seems to be that when they select transition and click on save and afterwards try to check in document, the current workflow step seems to be the next one as if transition already happend.

    Really strange.

    Still no clue how to prevent this.

    Dejan

Reply
  • Hey Radu, 

    the problem starts occurring from exactly using File Version. We have found cases when it does not work right. When users checkout document in certain workflow steps and then try to check-in, it works well. But when they checkout document and also select transition in parallel and then try to check in, they are able to make transition happened all together with changes in a document. This should not be the case.

    This is how I came to idea to try to prevent checkout in first place.

    The major problem seems to be that when they select transition and click on save and afterwards try to check in document, the current workflow step seems to be the next one as if transition already happend.

    Really strange.

    Still no clue how to prevent this.

    Dejan

Children
No Data