1- import includes from 'lodash/includes' ;
2- import intersection from 'lodash/intersection' ;
31import getScopesFromAuthInfo
42 from 'lib/services/auth/authInfoSelectors/getScopesFromAuthInfo' ;
53import getPublicOrgFilter from 'lib/services/auth/filters/getPublicOrgFilter' ;
@@ -15,22 +13,22 @@ import getModelsFilter,
1513
1614
1715export const shareableModelFilter = ( {
18- viewAllScope ,
19- viewPublicScope ,
20- editAllScope ,
21- editPublicScope
16+ viewAllScopes ,
17+ viewPublicScopes ,
18+ editAllScopes ,
19+ editPublicScopes ,
2220} ) => async ( { actionName, authInfo } ) => {
2321 const scopes = getScopesFromAuthInfo ( authInfo ) ;
2422
2523 switch ( actionName ) {
2624 case 'view' : {
27- const validAllScopes = intersection ( scopes , [ viewAllScope , editAllScope ] ) ;
28- if ( validAllScopes . length > 0 ) {
25+ const hasValidAllScopes = [ ... viewAllScopes , ... editAllScopes ] . some ( s => scopes . includes ( s ) ) ;
26+ if ( hasValidAllScopes ) {
2927 return getOrgFilter ( authInfo ) ;
3028 }
3129
32- const validPublicScopes = intersection ( scopes , [ viewPublicScope , editPublicScope ] ) ;
33- if ( validPublicScopes . length > 0 ) {
30+ const hasValidPublicScopes = [ ... viewPublicScopes , ... editPublicScopes ] . some ( s => scopes . includes ( s ) ) ;
31+ if ( hasValidPublicScopes ) {
3432 return getPublicOrgFilter ( authInfo ) ;
3533 }
3634
@@ -42,10 +40,10 @@ export const shareableModelFilter = ({
4240 return privateFilter ;
4341 }
4442 default : {
45- if ( includes ( scopes , editAllScope ) ) {
43+ if ( editAllScopes . some ( s => scopes . includes ( s ) ) ) {
4644 return getOrgFilter ( authInfo ) ;
4745 }
48- if ( includes ( scopes , editPublicScope ) ) {
46+ if ( editPublicScopes . some ( s => scopes . includes ( s ) ) ) {
4947 return getPublicOrgFilter ( authInfo ) ;
5048 }
5149 const privateFilter = getPrivateOrgFilter ( authInfo ) ;
0 commit comments