Table of Contents

Access rights management by template example

Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher

Restricting access to private resources is a very important feature of Service solutions. The flexible access system allows you to restrict or grant rights to each resource separately, specifying the range of people who can access it.

Getting started

You will need the following tools and facilities:

  1. Know how to use API key in Service solutions.

    This article will skip over additional information on authentication and authorization.

  2. .NET SDK.

  3. C# code editor or text editor, e.g., Visual Studio Code.

  4. Report template.

    To learn how to upload a report template, see the Upload new template article.

  5. Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.

  6. Internet access.

Important! These guides assume that you already know how to develop your application in the C# programming language.

Note. The items above describe recommended tools.

Instruction

  1. To view the current rights to the resource, use the following method GetPermissionsAsync(string, CancellationToken).

    public async Task<FilePermissionCRUDVM> GetOwnerPermissions(HttpClient httpClient, string templateId)
    {
     ITemplatesClient templatesClient = new TemplatesClient(httpClient);
    
        FilePermissionsVM permissions = await 
            templatesClient.GetPermissionsAsync(templateId);
    
        return permissions.Permissions.Owner;
    }
    

    In this example, the method returns the permissions for the template owner.

    Important! FilePermissionsVM contains a full description of the access rights to the entity in the Permissions property — it is a FilePermissionsCRUDVM with the Owner, Groups, Other and Anon categories. Each category is a FilePermissionCRUDVM describing the rights of one category.

  2. To change the permissions, use the following method UpdatePermissionsAsync(string, UpdateFilePermissionsVM, CancellationToken).

    public async Task ShareTemplate(HttpClient httpClient, string templateId)
    {
        ITemplatesClient templatesClient = new TemplatesClient(httpClient);
    
        UpdateFilePermissionsVM viewModel = new UpdateFilePermissionsVM()
        {
            NewPermissions = new FilePermissionsCRUDVM() {
     	Anon = new FilePermissionCRUDVM() { Get = FileGet.Entity | FileGet.Download } 
            },
            Administrate = FileAdministrate.Anon 
        };
    
        await templatesClient.UpdatePermissionsAsync(templateId, viewModel);
    }
    

    In this example, the function allows anonymous users to view information about the template and download it.

    Important! In this example, we pass only the permissions we want to edit and specify them in the Administrate property.

    If you need to change several categories of rights at once, you can list them using the bitwise operator OR (|).

What next?