diff --git a/packages/@sanity/vision/README.md b/packages/@sanity/vision/README.md index 36d49a0d252..969cb9093f2 100644 --- a/packages/@sanity/vision/README.md +++ b/packages/@sanity/vision/README.md @@ -2,16 +2,16 @@ Vision is a plugin for Sanity Studio for testing GROQ queries. It features: -- GROQ syntax highlighting so that the query is easier to read. -- Parsed response that's more convenient to navigate and explore. -- Switch between datasets +- GROQ syntax highlighting so that the query is easier to read +- Parsed response that's more convenient to navigate and explore +- Switching between datasets - Listening for real-time updates ![Screenshot](assets/screenshot.png) ## Installation -`npm install --save-exact @sanity/vision@dev-preview` +`npm install --save-exact @sanity/vision` ### Configuring @@ -34,7 +34,7 @@ export default defineConfig({ ### Only enabling it for development -If you only want the tool available in development (eg not in deployed studios), you can import and use the `isDev` constant from the `sanity` package: +If you only want the Vision tool available in development (e.g., not in deployed studios), you can import and use the `isDev` constant from the `sanity` package: ```ts // `sanity.config.ts` / `sanity.config.js`: @@ -52,6 +52,31 @@ export default defineConfig({ }) ``` +### Only enabling it for administrators + +If you only want the Vision tool available to administrators, you can use the [Tool API](https://www.sanity.io/docs/studio-tools) to filter out the tool based on role: + +```ts +// `sanity.config.ts` / `sanity.config.js`: +import {defineConfig} from 'sanity' +import {visionTool} from '@sanity/vision' + +export default defineConfig({ + // ... name, title, projectId, dataset, etc. + plugins: [ + // ... your other plugins here ... + visionTool(), + ], + tools: (prev, {currentUser}) => { + const isAdmin = currentUser?.roles.some(role => role.name === 'administrator'); + + // If the user has the administrator role, return all tools. + // If the user does not have the administrator role, filter out the vision tool. + return isAdmin ? prev : prev.filter(tool => tool.name !== 'vision'); + }, +}) +``` + ## License MIT-licensed. See LICENSE.