Sanity Library Reference Docs
    Preparing search index...
    • Beta

      Defines a custom permission that roles can grant, in the shape of the Access API.

      definePermission({
      name: 'articles-only',
      permissionType: 'sanity.document.filter.mode',
      config: {filter: '_type == "article"'},
      })

      Parameters

      • parameters: BlueprintPermissionConfig

        The configuration of the permission

        Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.

        Configuration for a custom permission resource. This feature is subject to breaking changes.

        • Betaconfig: { filter: string }

          The configuration of the permission.

          • filter: string

            A GROQ filter that selects the documents that the permission applies to, e.g. _type == "article".

        • Optional Betadescription?: string

          A description of the permission. Defaults to an empty string.

        • Betaname: string

          The name of the permission.

          Lowercase letters, numbers, hyphens, and underscores only. Must not start with sanity or res-.

        • BetapermissionType: BlueprintPermissionType

          The type of the permission. It cannot change after the permission is created.

          Manage creates content resources as sanity.document.filter.mode, and lists only custom permissions of that type.

        • Optional Betaproject?: string

          The project ID of the project that contains the permission.

          The project attribute must be defined if your blueprint is scoped to an organization and the stack has no default project.

        • Optional Betatitle?: string

          A human-readable title. Defaults to name.

      Returns BlueprintPermissionResource

      The permission resource

      definePermission({
      name: 'articles-only',
      title: 'Articles only',
      description: 'Access to article documents',
      permissionType: 'sanity.document.filter',
      config: {filter: '_type == "article"'},
      })

      defineRole({
      name: 'article-editor',
      title: 'Article editor',
      appliesToUsers: true,
      appliesToRobots: false,
      permissions: [
      {name: 'sanity-project', action: 'read'},
      {name: '$.resources.articles-only', action: 'read'},
      {name: '$.resources.articles-only', action: 'update'},
      ],
      })