Adding/removing permissions to sign a document

The script adds/removes permissions to sign a document type, not a specific document.

Context variables:

Document - variable of a Document type

User – user, who signs the document, User type

Namespaces:

using EleWise.ELMA.Documents.Metadata;
using EleWise.ELMA.Model.Metadata;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Security;
using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Documents;
using EleWise.ELMA.Services;
 

 

1)      Adding permissions to sign a document

Script:

//Load metadata
   var metadata = (DocumentMetadata)MetadataLoader.LoadMetadata(context. Document.TypeUid);
   var profile = DocumentMetadataProfileManager.Instance.LoadByDocumentType(metadata.ImplementationUid); 
//Add permissions to sign
   profile.Permissions.Add( new InstanceOf<IDmsObjectDefaultPermissions>
         {
          New =
          {
          DocumentMetadataProfile = profile,
          PermissionId = DocflowPermissionProvider.DocumentMetadataSignInstance.Id,
          TypeRoleId = CommonRoleTypes.User.Id,
          Assigned = context.User 
          }
         }.New);
  
    profile.Save();
 

As the result of the script execution, the user will get permissions to sign the document.

 

2)      Removing permissions to sign a document

Script:

//Load metadata
var metadata = (DocumentMetadata)MetadataLoader.LoadMetadata(context.Document.TypeUid);
   var profile = DocumentMetadataProfileManager.Instance.LoadByDocumentType(metadata.ImplementationUid);
//Set permissions to delete
   var permToDel = profile.Permissions.FirstOrDefault(p => p.DocumentMetadataProfile == profile && p.PermissionId == DocflowPermissionProvider.DocumentMetadataSignInstance.Id && p.TypeRoleId == CommonRoleTypes.User.Id && p.Assigned == context. Poljzovatelj);
//Remove permissions to sign
   profile.Permissions.Remove(permToDel); 
   profile.Save();
 

As the result of the script execution, permissions to sign the document will be removed from the user.