forked from strapi/strapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: soupette <cyril.lpz@gmail.com> Signed-off-by: Garrett Fritz <garrettfritz@garretts-mbp.home>
- Loading branch information
Showing
5 changed files
with
120 additions
and
32 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
23 changes: 23 additions & 0 deletions
23
...in/src/containers/EditViewDataManagerProvider/utils/getFieldsActionMatchingPermissions.js
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,23 @@ | ||
import { uniq, flatMap } from 'lodash'; | ||
import { findMatchingPermissions } from 'strapi-helper-plugin'; | ||
|
||
const getFieldsActionMatchingPermissions = (userPermissions, slug) => { | ||
const getMatchingPermissions = action => { | ||
const matched = findMatchingPermissions(userPermissions, [ | ||
{ | ||
action: `plugins::content-manager.explorer.${action}`, | ||
subject: slug, | ||
}, | ||
]); | ||
|
||
return uniq(flatMap(matched, 'fields')); | ||
}; | ||
|
||
return { | ||
createActionAllowedFields: getMatchingPermissions('create'), | ||
readActionAllowedFields: getMatchingPermissions('read'), | ||
updateActionAllowedFields: getMatchingPermissions('update'), | ||
}; | ||
}; | ||
|
||
export default getFieldsActionMatchingPermissions; |
1 change: 1 addition & 0 deletions
1
...pi-plugin-content-manager/admin/src/containers/EditViewDataManagerProvider/utils/index.js
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
16 changes: 16 additions & 0 deletions
16
...ainers/EditViewDataManagerProvider/utils/tests/getFieldsActionMatchingPermissions.test.js
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,16 @@ | ||
import getFieldsActionMatchingPermissions from '../getFieldsActionMatchingPermissions'; | ||
import { permissions } from './testData'; | ||
|
||
describe('CONTENT MANAGER | CONTAINERS | EditViewDataManager | utils | getFieldsActionMatchingPermissions', () => { | ||
it('should return an object with all the allowed action for the fields', () => { | ||
const expected = { | ||
createActionAllowedFields: [], | ||
readActionAllowedFields: ['name', 'description', 'test'], | ||
updateActionAllowedFields: ['name', 'description'], | ||
}; | ||
|
||
expect(getFieldsActionMatchingPermissions(permissions, 'application::article.article')).toEqual( | ||
expected | ||
); | ||
}); | ||
}); |
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