-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out unnecessary options (#2946)
* Extract an `isPermitted` function that checks whether user abilities is contained in a list of permitted abilities * Add an `allowedActivities` function that returns relevant activities given a user's abilities * Render only relevant activities for user in Activity log page filters * Improve activity types list generation * Fix reference to users ability
- Loading branch information
1 parent
f657323
commit 68c14a4
Showing
7 changed files
with
151 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { abilityFactory } from '@lib/test-utils/factories/users'; | ||
import { difference } from 'lodash'; | ||
import { | ||
ACTIVITY_TYPES, | ||
allowedActivities, | ||
LOGIN_ATTEMPT, | ||
PROFILE_UPDATE, | ||
USER_CREATION, | ||
USER_DELETION, | ||
USER_MODIFICATION, | ||
} from './activityLog'; | ||
|
||
const nonUserManagementActivities = difference(ACTIVITY_TYPES, [ | ||
LOGIN_ATTEMPT, | ||
USER_CREATION, | ||
USER_MODIFICATION, | ||
USER_DELETION, | ||
PROFILE_UPDATE, | ||
]); | ||
|
||
describe('activityLog', () => { | ||
it.each` | ||
userAbilities | hasUserMgmtActivities | ||
${[]} | ${false} | ||
${[['all', 'all']]} | ${true} | ||
${[['all', 'users']]} | ${true} | ||
${[['all', 'all'], ['all', 'users']]} | ${true} | ||
${[['all', 'all'], ['foo', 'bar']]} | ${true} | ||
${[['all', 'users'], ['bar', 'baz']]} | ${true} | ||
${[['baz', 'qux'], ['bar', 'baz']]} | ${false} | ||
${[['baz', 'qux']]} | ${false} | ||
${[['qux', 'ber']]} | ${false} | ||
`( | ||
'should return relevant activities for the given user abilities', | ||
({ userAbilities, hasUserMgmtActivities }) => { | ||
const abilities = userAbilities.map(([name, resource]) => | ||
abilityFactory.build({ name, resource }) | ||
); | ||
|
||
const relevantActivities = allowedActivities(abilities).map( | ||
([key, _value]) => key | ||
); | ||
|
||
hasUserMgmtActivities | ||
? expect(relevantActivities).toEqual(ACTIVITY_TYPES) | ||
: expect(relevantActivities).toEqual(nonUserManagementActivities); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.