logo

Additional file permission check

In this article, we offer an example of creating an additional file permission check. If a user does not have access permissions to a file, they will receive a corresponding notification when trying to download the file from the object, as shown in fig.1. If the user has access permissions to the file, they will be able to download the file or preview it, as shown in fig. 2.

Example of data display

Fig. 1. Notification shown when there are not enough permissions to access a file

Fig. 1. Notification shown when there are not enough permissions to access a file

Fig. 2. Pop-up window that appears when there are enough permissions

Fig. 2. Pop-up window that appears when there are enough permissions

Extension (interface) methods

IExtendedFilePermissionValidator extension point (interface) uses the following methods:

/// <summary>
/// Whether there are enough permissions to access the file
/// </summary>
/// <param name="file">File</param>
/// <returns><c>true</c> if there are enough permissions</returns>
bool HasPermission(BinaryFile file, out string errorMessage);

Example of extension point class

[Component]
public class VersionExtendedFilePermission : IExtendedFilePermissionValidator
{
    public bool HasPermission(BinaryFile file, out string errorMessage)
    {
        errorMessage = string.Empty;
        var res = Locator.GetServiceNotNull<ISecurityService>().HasPermission(CommonPermissions.AdminPermission);
        if (!res)
            errorMessage = SR.T("Not enough permissions to access the file version");
        return res;
    }
}

In this example, a user with administrator privileges has access to download/view the file.

Links to API elements

IExtendedFilePermissionValidator