@@ -1641,8 +1641,8 @@ define([
16411641 }
16421642
16431643 helpers . canUser = function ( a , adminOverride ) {
1644- var role = window . trudeskSessionService . getUser ( ) . role
1645- var roles = window . trudeskSessionService . getRoles ( )
1644+ let role = window . trudeskSessionService . getUser ( ) . role
1645+ const roles = window . trudeskSessionService . getRoles ( )
16461646
16471647 if ( adminOverride === true && role . isAdmin ) return true
16481648
@@ -1677,8 +1677,8 @@ define([
16771677 }
16781678
16791679 helpers . hasHierarchyEnabled = function ( roleId ) {
1680- var roles = window . trudeskSessionService . getRoles ( )
1681- var role = _ . find ( roles , function ( o ) {
1680+ const roles = window . trudeskSessionService . getRoles ( )
1681+ const role = _ . find ( roles , function ( o ) {
16821682 return o . _id . toString ( ) === roleId . toString ( )
16831683 } )
16841684 if ( _ . isUndefined ( role ) || _ . isUndefined ( role . hierarchy ) ) throw new Error ( 'Invalid Role: ' + roleId )
@@ -1755,6 +1755,7 @@ define([
17551755 helpers . hasPermOverRole = function ( ownerRole , extRole , action , adminOverride ) {
17561756 if ( action && ! helpers . canUser ( action , adminOverride ) ) return false
17571757 if ( ! extRole ) extRole = window . trudeskSessionService . getUser ( ) . role
1758+
17581759 if ( ! _ . isObject ( ownerRole ) || ! _ . isObject ( extRole ) ) {
17591760 console . log ( 'Invalid Role Sent to helpers.hasPermOverRole. [Must be role obj]' )
17601761 console . log ( 'Owner: ' + ownerRole )
@@ -1775,20 +1776,27 @@ define([
17751776 if ( extRole && extRole . isAdmin ) {
17761777 return true
17771778 } else {
1778- var r = window . trudeskSessionService . getRoles ( )
1779- var role = _ . find ( r , function ( _role ) {
1779+ const r = window . trudeskSessionService . getRoles ( )
1780+ const role = _ . find ( r , function ( _role ) {
17801781 return _role . _id . toString ( ) === extRole . _id . toString ( )
17811782 } )
17821783 if ( ! _ . isUndefined ( role ) && role . isAdmin ) return true
17831784 }
17841785 }
17851786
1786- var roles = helpers . parseRoleHierarchy ( extRole . _id )
1787+ if ( ! helpers . hasHierarchyEnabled ( extRole . _id ) ) {
1788+ return ownerRole . _id === extRole . _id
1789+ }
17871790
1788- var i = _ . find ( roles , function ( o ) {
1789- return o . toString ( ) === ownerRole . toString ( )
1791+ const roles = helpers . parseRoleHierarchy ( extRole . _id )
1792+ // console.log('My Role ID: ', extRole._id)
1793+ // console.log('Hierarchy: ', roles)
1794+ const i = _ . find ( roles , function ( o ) {
1795+ return o . toString ( ) === ownerRole . _id . toString ( )
17901796 } )
17911797
1798+ // console.log('Found in Hierarchy: ', i)
1799+
17921800 return ! _ . isUndefined ( i )
17931801 }
17941802
0 commit comments