Skip to content

Commit 26d9e03

Browse files
committed
SecurityTrimmedControl documentation
1 parent ea2eee6 commit 26d9e03

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## 1.4.0
4+
5+
**New Controls**
6+
7+
- `SecurityTrimmedControl` control got added [#74](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/74)
8+
39
## 1.3.0
410

511
**New Controls**

docs/documentation/docs/about/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## 1.4.0
4+
5+
**New Controls**
6+
7+
- `SecurityTrimmedControl` control got added [#74](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/74)
8+
39
## 1.3.0
410

511
**New Controls**
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
# SecurityTrimmedControl
22

3-
This control is intended to be used when you want to show or hide components based on the user its permissions. The control can be used to check the user’s permissions on the current site / list were the solution is loaded, or on a remote site / list.
3+
This control is intended to be used when you want to show or hide components based on the user its permissions. The control can be used to check the user’s permissions on the current site / list were the solution is loaded, or on a remote site / list.
44

5-
## Usage
6-
### Checking permissions on the current site
5+
## How to use this control in your solutions
6+
7+
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../#getting-started) page for more information about installing the dependency.
8+
- Import the following modules to your component:
9+
10+
```TypeScript
11+
import { SecurityTrimmedControl } from "@pnp/spfx-controls-react/lib/SecurityTrimmedControl";
712
```
13+
14+
- You can use the `SecurityTrimmedControl` as follows in your solutions:
15+
16+
**Checking permissions on the current site**
17+
18+
```jsx
819
<SecurityTrimmedControl context={this.props.context}
920
level={PermissionLevel.currentWeb}
1021
permissions={[SPPermission.viewPages]}>
1122
{/* Specify the components to load when user has the required permissions */}
1223
</SecurityTrimmedControl>
1324
```
1425

15-
### Checking permissions on the current list
16-
```
26+
**Checking permissions on the current list**
27+
28+
```jsx
1729
<SecurityTrimmedControl context={this.props.context}
1830
level={PermissionLevel.currentList}
1931
permissions={[SPPermission.addListItems]}>
2032
{/* Specify the components to load when user has the required permissions */}
2133
</SecurityTrimmedControl>
2234
```
2335

24-
### Checking permissions on remote site
25-
```
36+
**Checking permissions on remote site**
37+
38+
```jsx
2639
<SecurityTrimmedControl context={this.props.context}
2740
level={PermissionLevel.remoteWeb}
2841
remoteSiteUrl="https://<tenant>.sharepoint.com/sites/<siteName>"
@@ -31,8 +44,9 @@ This control is intended to be used when you want to show or hide components bas
3144
</SecurityTrimmedControl>
3245
```
3346

34-
### Checking permissions on remote list / library
35-
```
47+
**Checking permissions on remote list / library**
48+
49+
```jsx
3650
<SecurityTrimmedControl context={this.props.context}
3751
level={PermissionLevel.remoteListOrLib}
3852
remoteSiteUrl="https://<tenant>.sharepoint.com/sites/<siteName>"
@@ -41,3 +55,18 @@ This control is intended to be used when you want to show or hide components bas
4155
{/* Specify the components to load when user has the required permissions */}
4256
</SecurityTrimmedControl>
4357
```
58+
59+
## Implementation
60+
61+
The `SecurityTrimmedControl` can be configured with the following properties:
62+
63+
| Property | Type | Required | Description |
64+
| ---- | ---- | ---- | ---- |
65+
| context | WebPartContext or ApplicationCustomizerContext or FieldCustomizerContext or ListViewCommandSetContext | yes | Context of the web part, application customizer, field customizer, or list view command set. |
66+
| permissions | SPPermission[] | yes | The permissions to check for the user. |
67+
| level | PermissionLevel | yes | Specify where to check the user permissions: current site or list / remote site or list. |
68+
| remoteSiteUrl | string | no | The URL of the remote site. Required when you want to check permissions on remote site or list. |
69+
| relativeLibOrListUrl | string | no | The relative URL of the list or library. Required when you want to check permissions on remote list. |
70+
71+
72+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/SecurityTrimmedControl)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pnp/spfx-controls-react",
33
"description": "Reusable React controls for SharePoint Framework solutions",
4-
"version": "1.3.0",
4+
"version": "1.4.0",
55
"engines": {
66
"node": ">=0.10.0"
77
},

src/controls/securityTrimmedControl/ISecurityTrimmedControlProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { PermissionLevel } from '.';
66

77
export interface ISecurityTrimmedControlProps {
88
/**
9-
* Context of the web part, application customizer, field customizer, or list view command set
9+
* Context of the web part, application customizer, field customizer, or list view command set.
1010
*/
1111
context: WebPartContext | ApplicationCustomizerContext | FieldCustomizerContext | ListViewCommandSetContext;
1212
/**
13-
* The permissions to check for the user
13+
* The permissions to check for the user.
1414
*/
1515
permissions: SPPermission[];
1616
/**

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { TaxonomyPicker, IPickerTerms } from '../../../TaxonomyPicker';
1515
import { ListPicker } from '../../../ListPicker';
1616
import { IFrameDialog } from '../../../IFrameDialog';
1717
import { Environment, EnvironmentType } from '@microsoft/sp-core-library';
18+
import { SecurityTrimmedControl, PermissionLevel } from '../../../SecurityTrimmedControl';
19+
import { SPPermission } from '@microsoft/sp-page-context';
1820

1921
/**
2022
* Component that can be used to test out the React controls from this project
@@ -177,6 +179,10 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
177179
<div className="ms-Grid-col ms-lg10 ms-xl8 ms-xlPush2 ms-lgPush1">
178180
<span className="ms-font-xl">Controls testing</span>
179181

182+
<SecurityTrimmedControl context={this.props.context} level={PermissionLevel.currentWeb} permissions={[SPPermission.viewListItems]}>
183+
<p>You have permissions to view list items.</p>
184+
</SecurityTrimmedControl>
185+
180186
<p className="ms-font-l">
181187
File type icon control
182188
</p>

0 commit comments

Comments
 (0)