@@ -3,13 +3,15 @@ import { ISecurityTrimmedControlProps, ISecurityTrimmedControlState, PermissionL
3
3
import { SPHttpClient } from '@microsoft/sp-http' ;
4
4
import { SPPermission } from '@microsoft/sp-page-context' ;
5
5
import * as telemetry from '../../common/telemetry' ;
6
+ import { Spinner } from 'office-ui-fabric-react/lib/Spinner' ;
6
7
7
8
export class SecurityTrimmedControl extends React . Component < ISecurityTrimmedControlProps , ISecurityTrimmedControlState > {
8
9
constructor ( props : ISecurityTrimmedControlProps ) {
9
10
super ( props ) ;
10
11
11
12
this . state = {
12
- allowRender : false
13
+ allowRender : false ,
14
+ loading : true
13
15
} ;
14
16
15
17
telemetry . track ( 'ReactPlaceholder' , { } ) ;
@@ -49,11 +51,13 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
49
51
// Check the user its permissions
50
52
if ( permissions . hasAllPermissions ( ...this . props . permissions ) ) {
51
53
this . setState ( {
52
- allowRender : true
54
+ allowRender : true ,
55
+ loading : false
53
56
} ) ;
54
57
} else {
55
58
this . setState ( {
56
- allowRender : false
59
+ allowRender : false ,
60
+ loading : false
57
61
} ) ;
58
62
}
59
63
} else if ( level === PermissionLevel . remoteWeb ) {
@@ -84,21 +88,24 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
84
88
if ( result . error ) {
85
89
// Do not allow rendering when there was an error
86
90
this . setState ( {
87
- allowRender : false
91
+ allowRender : false ,
92
+ loading : false
88
93
} ) ;
89
94
console . error ( `Error retrieved while checking user's remote site permissions.` ) ;
90
95
return ;
91
96
}
92
97
// Check the result value
93
98
if ( typeof result . value !== "undefined" && result . value === false ) {
94
99
this . setState ( {
95
- allowRender : false
100
+ allowRender : false ,
101
+ loading : false
96
102
} ) ;
97
103
return ;
98
104
}
99
105
} else {
100
106
this . setState ( {
101
- allowRender : false
107
+ allowRender : false ,
108
+ loading : false
102
109
} ) ;
103
110
console . error ( `No result value was retrieved when checking the user's remote site permissions.` ) ;
104
111
return ;
@@ -107,7 +114,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
107
114
108
115
// Render the controls when the permissions were OK for the user
109
116
this . setState ( {
110
- allowRender : true
117
+ allowRender : true ,
118
+ loading : false
111
119
} ) ;
112
120
}
113
121
}
@@ -122,7 +130,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
122
130
const apiUrl = `${ remoteSiteUrl } /_api/web/GetList(@listUrl)/EffectiveBasePermissions?@listUrl='${ encodeURIComponent ( relativeLibOrListUrl ) } '` ;
123
131
const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
124
132
this . setState ( {
125
- allowRender : hasPermissions
133
+ allowRender : hasPermissions ,
134
+ loading : false
126
135
} ) ;
127
136
}
128
137
}
@@ -137,7 +146,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
137
146
const apiUrl = `${ remoteSiteUrl } /_api/web/GetList(@listUrl)/Items(${ itemId } )/EffectiveBasePermissions?@listUrl='${ encodeURIComponent ( relativeLibOrListUrl ) } '` ;
138
147
const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
139
148
this . setState ( {
140
- allowRender : hasPermissions
149
+ allowRender : hasPermissions ,
150
+ loading : false
141
151
} ) ;
142
152
}
143
153
}
@@ -153,7 +163,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
153
163
const apiUrl = `${ remoteSiteUrl } /_api/web/GetFolderByServerRelativeUrl(@folderByServerRelativeUrl)/ListItemAllFields/EffectiveBasePermissions?@folderByServerRelativeUrl='${ folderByServerRelativeUrl } '` ;
154
164
const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
155
165
this . setState ( {
156
- allowRender : hasPermissions
166
+ allowRender : hasPermissions ,
167
+ loading : false
157
168
} ) ;
158
169
}
159
170
}
@@ -194,10 +205,15 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
194
205
*/
195
206
public render ( ) : React . ReactElement < ISecurityTrimmedControlProps > {
196
207
const { className } = this . props ;
197
- return (
198
- this . state . allowRender ? (
199
- < div className = { className ? className : "" } > { this . props . children } </ div >
200
- ) : null
201
- ) ;
208
+ if ( this . state . loading && this . props . showLoadingAnimation ) {
209
+ return < Spinner /> ;
210
+ }
211
+ if ( this . state . allowRender ) {
212
+ return < div className = { className ? className : "" } > { this . props . children } </ div > ;
213
+ }
214
+ else if ( this . props . noPermissionsControl ) {
215
+ return this . props . noPermissionsControl ;
216
+ }
217
+ return null ;
202
218
}
203
219
}
0 commit comments