@@ -19,43 +19,6 @@ const registerAdminConditions = () => {
1919 } ) ;
2020} ;
2121
22- const cleanPermissionInDatabase = async ( ) => {
23- const { actionProvider } = strapi . admin . services . permission ;
24- const dbPermissions = await strapi . admin . services . permission . find ( ) ;
25- const allActionsMap = actionProvider . getAllByMap ( ) ;
26- const permissionsToRemoveIds = [ ] ;
27-
28- dbPermissions . forEach ( perm => {
29- if (
30- ! allActionsMap . has ( perm . action ) ||
31- ( allActionsMap . get ( perm . action ) . section === 'contentTypes' &&
32- ! allActionsMap . get ( perm . action ) . subjects . includes ( perm . subject ) )
33- ) {
34- permissionsToRemoveIds . push ( perm . id ) ;
35- }
36- } ) ;
37-
38- await strapi . admin . services . permission . deleteByIds ( permissionsToRemoveIds ) ;
39- } ;
40-
41- const getPermissionsWithNestedFields = ( actions , nestingLevel = 3 ) =>
42- actions . reduce ( ( perms , action ) => {
43- const newPerms = [ ] ;
44- action . subjects . forEach ( contentTypeUid => {
45- const fields = strapi . admin . services [ 'content-type' ] . getNestedFields ( contentTypeUid , {
46- components : { ...strapi . components , ...strapi . contentTypes } ,
47- nestingLevel,
48- } ) ;
49- newPerms . push ( {
50- action : action . actionId ,
51- subject : contentTypeUid ,
52- fields,
53- conditions : [ ] ,
54- } ) ;
55- } ) ;
56- return perms . concat ( newPerms ) ;
57- } , [ ] ) ;
58-
5922const createRolesIfNeeded = async ( ) => {
6023 const someRolesExist = await strapi . admin . services . role . exists ( ) ;
6124 if ( someRolesExist ) {
@@ -104,7 +67,9 @@ const createRolesIfNeeded = async () => {
10467 description : 'Authors can manage and publish the content they created.' ,
10568 } ) ;
10669
107- const editorPermissions = getPermissionsWithNestedFields ( contentTypesActions ) ;
70+ const editorPermissions = strapi . admin . services [ 'content-type' ] . getPermissionsWithNestedFields (
71+ contentTypesActions
72+ ) ;
10873
10974 const authorPermissions = editorPermissions . map ( p => ( {
11075 ...p ,
@@ -145,7 +110,10 @@ const resetSuperAdminPermissions = async () => {
145110 const allActions = strapi . admin . services . permission . actionProvider . getAll ( ) ;
146111 const contentTypesActions = allActions . filter ( a => a . section === 'contentTypes' ) ;
147112
148- const permissions = getPermissionsWithNestedFields ( contentTypesActions , 1 ) ;
113+ const permissions = strapi . admin . services [ 'content-type' ] . getPermissionsWithNestedFields (
114+ contentTypesActions ,
115+ 1
116+ ) ;
149117
150118 const otherActions = allActions . filter ( a => a . section !== 'contentTypes' ) ;
151119 otherActions . forEach ( action => {
@@ -165,7 +133,7 @@ const resetSuperAdminPermissions = async () => {
165133module . exports = async ( ) => {
166134 registerAdminConditions ( ) ;
167135 registerPermissionActions ( ) ;
168- await cleanPermissionInDatabase ( ) ;
136+ await strapi . admin . services . permission . cleanPermissionInDatabase ( ) ;
169137 await createRolesIfNeeded ( ) ;
170138 await resetSuperAdminPermissions ( ) ;
171139 await displayWarningIfNoSuperAdmin ( ) ;
0 commit comments