16
16
* under the License.
17
17
*/
18
18
19
- import { Show } from "@wso2is/access-control" ;
19
+ import { Show , useRequiredScopes } from "@wso2is/access-control" ;
20
20
import {
21
21
AppConstants ,
22
- AppState ,
23
22
FeatureConfigInterface ,
24
23
UIConstants ,
25
24
getEmptyPlaceholderIllustrations ,
26
25
history
27
26
} from "@wso2is/admin.core.v1" ;
28
- import { hasRequiredScopes , isFeatureEnabled } from "@wso2is/core/helpers" ;
27
+ import { userstoresConfig } from "@wso2is/admin.extensions.v1" ;
28
+ import { isFeatureEnabled } from "@wso2is/core/helpers" ;
29
29
import { LoadableComponentInterface , SBACInterface , TestableComponentInterface } from "@wso2is/core/models" ;
30
30
import {
31
31
AnimatedAvatar ,
@@ -41,7 +41,6 @@ import {
41
41
import moment , { Moment } from "moment" ;
42
42
import React , { ReactElement , ReactNode , SyntheticEvent , useState } from "react" ;
43
43
import { useTranslation } from "react-i18next" ;
44
- import { useSelector } from "react-redux" ;
45
44
import { Header , Icon , Label , SemanticICONS } from "semantic-ui-react" ;
46
45
import { GroupConstants } from "../constants" ;
47
46
import { GroupsInterface } from "../models" ;
@@ -102,6 +101,14 @@ interface GroupListProps extends SBACInterface<FeatureConfigInterface>,
102
101
* Indicates whether the currently selected user store is read-only or not.
103
102
*/
104
103
isReadOnlyUserStore ?: boolean ;
104
+ /**
105
+ * Flag to show/hide the delete action in the userstore list.
106
+ */
107
+ isUserstoreDeleteDisabled ?: boolean ;
108
+ /**
109
+ * Flag to show/hide the add action in the userstore list.
110
+ */
111
+ isUserstoreAddDisabled ?: boolean ;
105
112
}
106
113
107
114
/**
@@ -128,16 +135,19 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
128
135
showListItemActions,
129
136
showMetaContent,
130
137
isReadOnlyUserStore,
138
+ isUserstoreAddDisabled,
139
+ isUserstoreDeleteDisabled,
131
140
[ "data-testid" ] : testId
132
141
} = props ;
133
142
134
143
const { t } = useTranslation ( ) ;
135
144
136
- const allowedScopes : string = useSelector ( ( state : AppState ) => state ?. auth ?. allowedScopes ) ;
137
-
138
145
const [ showGroupDeleteConfirmation , setShowDeleteConfirmationModal ] = useState < boolean > ( false ) ;
139
146
const [ currentDeletedGroup , setCurrentDeletedGroup ] = useState < GroupsInterface > ( ) ;
140
147
148
+ const hasGroupsUpdatePermission : boolean = useRequiredScopes ( featureConfig ?. groups ?. scopes ?. update ) ;
149
+ const hasGroupsDeletePermission : boolean = useRequiredScopes ( featureConfig ?. groups ?. scopes ?. delete ) ;
150
+
141
151
const handleGroupEdit = ( groupId : string ) : void => {
142
152
history . push ( AppConstants . getPaths ( ) . get ( "GROUP_EDIT" ) . replace ( ":id" , groupId ) ) ;
143
153
} ;
@@ -214,7 +224,7 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
214
224
return (
215
225
< EmptyPlaceholder
216
226
data-testid = { `${ testId } -empty-list-empty-placeholder` }
217
- action = { ! isReadOnlyUserStore && (
227
+ action = { ! isReadOnlyUserStore && ! isUserstoreAddDisabled && (
218
228
< Show
219
229
when = { featureConfig ?. groups ?. scopes ?. create }
220
230
>
@@ -231,14 +241,14 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
231
241
image = { getEmptyPlaceholderIllustrations ( ) . newList }
232
242
imageSize = "tiny"
233
243
title = {
234
- isReadOnlyUserStore
244
+ ( isReadOnlyUserStore || isUserstoreAddDisabled )
235
245
? t ( "roles:list.emptyPlaceholders.emptyRoleList.emptyRoles" ,
236
246
{ type : "groups" } )
237
247
: t ( "roles:list.emptyPlaceholders.emptyRoleList.title" ,
238
248
{ type : "group" } )
239
249
}
240
250
subtitle = {
241
- isReadOnlyUserStore
251
+ ( isReadOnlyUserStore || isUserstoreAddDisabled )
242
252
? [
243
253
t ( "roles:list.emptyPlaceholders.emptyRoleList.subtitles.0" ,
244
254
{ type : "groups" } )
@@ -341,11 +351,11 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
341
351
icon : ( group : GroupsInterface ) : SemanticICONS => {
342
352
const userStore : string = group ?. displayName ?. split ( "/" ) . length > 1
343
353
? group ?. displayName ?. split ( "/" ) [ 0 ]
344
- : "PRIMARY" ;
354
+ : userstoresConfig ?. primaryUserstoreName ;
345
355
346
356
return ! isFeatureEnabled ( featureConfig ?. groups ,
347
357
GroupConstants . FEATURE_DICTIONARY . get ( "GROUP_UPDATE" ) )
348
- || ! hasRequiredScopes ( featureConfig ?. groups , featureConfig ?. groups ?. scopes ?. update , allowedScopes )
358
+ || ! hasGroupsUpdatePermission
349
359
|| readOnlyUserStores ?. includes ( userStore . toString ( ) )
350
360
? "eye"
351
361
: "pencil alternate" ;
@@ -355,11 +365,11 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
355
365
popupText : ( group : GroupsInterface ) : string => {
356
366
const userStore : string = group ?. displayName ?. split ( "/" ) . length > 1
357
367
? group ?. displayName ?. split ( "/" ) [ 0 ]
358
- : "PRIMARY" ;
368
+ : userstoresConfig ?. primaryUserstoreName ;
359
369
360
370
return ! isFeatureEnabled ( featureConfig ?. groups ,
361
371
GroupConstants . FEATURE_DICTIONARY . get ( "GROUP_UPDATE" ) )
362
- || ! hasRequiredScopes ( featureConfig ?. groups , featureConfig ?. groups ?. scopes ?. update , allowedScopes )
372
+ || ! hasGroupsUpdatePermission
363
373
|| readOnlyUserStores ?. includes ( userStore . toString ( ) )
364
374
? t ( "common:view" )
365
375
: t ( "common:edit" ) ;
@@ -372,10 +382,12 @@ export const GroupList: React.FunctionComponent<GroupListProps> = (props: GroupL
372
382
hidden : ( group : GroupsInterface ) : boolean => {
373
383
const userStore : string = group ?. displayName ?. split ( "/" ) . length > 1
374
384
? group ?. displayName ?. split ( "/" ) [ 0 ]
375
- : "PRIMARY" ;
385
+ : userstoresConfig ?. primaryUserstoreName ;
376
386
377
- return ! hasRequiredScopes ( featureConfig ?. groups , featureConfig ?. groups ?. scopes ?. delete , allowedScopes )
378
- || readOnlyUserStores ?. includes ( userStore . toString ( ) ) ;
387
+ return ! hasGroupsDeletePermission
388
+ || readOnlyUserStores ?. includes ( userStore . toString ( ) )
389
+ || isReadOnlyUserStore
390
+ || isUserstoreDeleteDisabled ;
379
391
} ,
380
392
icon : ( ) : SemanticICONS => "trash alternate" ,
381
393
onClick : ( e : SyntheticEvent , group : GroupsInterface ) : void => {
0 commit comments