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. Curl tool.

    Any other REST client will work, but the examples will be built for curl.

  3. Report template.

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

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

  5. Internet access.

Instruction

  1. To view the current rights to the resource, execute the GET request to {host_name}/api/rp/v1/Templates/File/{id}/permissions, where the template ID should be used instead of {id}.

    Example request:

    curl -X GET "{host_name}/api/rp/v1/Templates/File/5fc9ece6b792c90001d94b13/permissions" -H "accept: text/plain"
    

    Example answer:

    {
      "permissions": {
        "ownerId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491",
        "owner": {
          "create": "All",
          "delete": "All",
          "execute": "All",
          "get": "All",
          "update": "All",
          "administrate": "All"
        },
        "groups": null,
        "other": {
          "create": "All",
          "delete": "All",
          "execute": "All",
          "get": "All",
          "update": "All",
          "administrate": "All"
        },
        "anon": null
      }
    }
    

    In this example, the owner and other members of the workspace have full access to the report template.

  2. To change the permissions, execute the POST request to {host_name}/api/rp/v1/Templates/File/{id}/permissions, where the template ID should be used instead of {id}.

    Example model:

    {
      "newPermissions": {
        "ownerId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491",
        "owner": {
          "create": -1,
          "delete": -1,
          "execute": -1,
          "get": -1,
          "update": 0,
          "administrate": -1
        },
        "other": {
          "create": 0,
          "delete": 0,
          "execute": 0,
          "get": 0,
          "update": 0,
          "administrate": 0
        }
      },
      "administrate": "Owner,Other"
    }
    

    Important! In the request to update the rights in the administrate property, the values Owner and Other were passed in, in this case, only the specified rights categories, i.e., other and owner will be updated, and the categories anon and groups will not be changed.

    Example request that restricts the owner’s right to update the report (e.g., editing in the online designer), as well as all workspace participants’ rights to the file:

    curl -X POST "{host_name}/api/rp/v1/Templates/File/5fc9ece6b792c90001d94b13/permissions" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{ \"newPermissions\": { \"ownerId\": \"5af5a8dc-8cb0-40f9-ac99-ca2533fa4491\", \"owner\": { \"create\": -1, \"delete\": -1, \"execute\": -1, \"get\": -1, \"update\": 0, \"administrate\": -1 }, \"other\": { \"create\": 0, \"delete\": 0, \"execute\": 0, \"get\": 0, \"update\": 0, \"administrate\": 0 } }, \"administrate\": \"Owner,Other\"}
    

    Example answer:

    200 OK
    
  3. Now you can request the permissions again to make sure they are indeed updated.

    Example request:

    curl -X GET "{host_name}/api/rp/v1/Templates/File/5fc9ece6b792c90001d94b13/permissions" -H "accept: text/plain"
    

    Example answer:

    {
     "permissions": {
        "ownerId": "2df79f83-07f1-41ba-96b5-7757bbf377df",
     "owner": {
          "create": "All",
          "delete": "All",
          "execute": "All",
       "get": "All",
          "update": "None",
       "administrate": "All"
        },
        "groups": null,
        "other": {
          "create": "None",
          "delete": "None",
          "execute": "None",
          "get": "None",
          "update": "None",
          "administrate": "None"
        },
        "anon": null
      }
    }
    

What next?