Manage access permissions for a template
Restricting access to private resources is a very important part of FastReport Corporate Server. A flexible access system allows you to set a restriction or grant permission to each resource separately, specifying the persons who can access the resource.
Getting started
You will need the following tools and features:
Knowledge on how to use API key in FastReport Corporate Server.
This article does not include the information about authentication and authorization.
A C# code editor or a text editor like Visual Studio Code.
A report template.
How to upload a report template can be found in the article Upload a new template.
Active subscription for FastReport Corporate Server.
Internet access.
Please, note: This tutorial assumes that you already know how to develop your application with the C# programming language.
Please, note: The descriptions above are provided for the recommended tools.
Instructions
To view the current resource access permissions, use the <xref:FastReport.Cloud.ITemplatesClient.GetPermissionsAsync(System.String)> method.
public async Task<FilePermission> GetOwnerPermissions(HttpClient httpClient, string templateId) { ITemplatesClient templatesClient = new TemplatesClient(httpClient); FilePermissions permissions = await templatesClient.GetPermissionsAsync(templateId); return permissions.Owner; }
In this example, the method returns the access permissions for the template.
Please, note: The classes <xref:FastReport.Cloud.FilePermissions> and <xref:FastReport.Cloud.FilePermission> differ by the letter
s
at the end; the first one contains a full description of the access permissions to the entity, and the second one only contains the description for one of the categories.To add a new permissions, use the <xref:FastReport.Cloud.ITemplatesClient.AddPermissionAsync(System.String,FastReport.Cloud.FilePermissionsVM)> method.
public async Task<FilePermission> AllowOtherGetTempalte(HttpClient httpClient, string templateId) { ITemplatesClient templatesClient = new TemplatesClient(httpClient); FilePermissionsVM viewModel = new FilePermissionsVM() { PermissionType = FilePermissionsVMPermissionType.Other, Permission = new FilePermission() { Get = FilePermissionGet.All } }; var result = await templatesClient.AddPermissionAsync(templateId, viewModel); return result.Other; }
In this example, the function allows all users of the subscription to receive information about the template.
To remove some of the permissions, use the <xref:FastReport.Cloud.ITemplatesClient.RevokePermissionAsync(System.String,FastReport.Cloud.FilePermissionsVM)> method.
public async Task<FilePermission> RevokeOtherDownloadTemplate(HttpClient httpClient, string templateId) { ITemplatesClient templatesClient = new TemplatesClient(httpClient); FilePermissionsVM viewModel = new FilePermissionsVM() { PermissionType = FilePermissionsVMPermissionType.Other, Permission = new FilePermission() { Get = FilePermissionGet.Download } }; var result = await templatesClient.RevokePermissionAsync(templateId, viewModel); return result.Other; }
In this example, the function bans all subscription users from downloading a template from FastReport Corporate Server, while they still can access other information about the file.
Please, note: The response contains the information about the access permissions of the subscription members
result.Other.Get == -5
, since the information about the permissions is stored compactly in the bit flags.public enum FilePermissionGet { All = -1, None = 0, Entity = 1, Count = 2, Download = 4, Permission = 8 }
In the case above, all new permissions will be available to all users of the subscription. To avoid this situation, assign permissions without
All
.public async Task<FilePermission> AllowOtherGetTempalteWithoutDownload(HttpClient httpClient, string templateId) { ITemplatesClient templatesClient = new TemplatesClient(httpClient); FilePermissionsVM revokeAllViewModel = new FilePermissionsVM() { PermissionType = FilePermissionsVMPermissionType.Other, Permission = new FilePermission() { Get = FilePermissionGet.All } }; await templatesClient.RevokePermissionAsync(templateId, revokeAllViewModel); FilePermissionsVM allowAllWithoutDownloadViewModel = new FilePermissionsVM() { PermissionType = FilePermissionsVMPermissionType.Other, Permission = new FilePermission() { Get = FilePermissionGet.Count | FilePermissionGet.Entity | FilePermissionGet.Permission } }; var result = await templatesClient.AddPermissionAsync( templateId,allowAllWithoutDownloadViewModel); return result.Other; }
In this example, to grant a specific set of permissions,
All
permissions were removed and then specific permissions were granted.