mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 18:08:11 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| const { merge } = require('lodash/fp');
 | |
| const { getService } = require('./utils');
 | |
| const adminActions = require('./config/admin-actions');
 | |
| const adminConditions = require('./config/admin-conditions');
 | |
| 
 | |
| const defaultAdminAuthSettings = {
 | |
|   providers: {
 | |
|     autoRegister: false,
 | |
|     defaultRole: null,
 | |
|   },
 | |
| };
 | |
| 
 | |
| const registerPermissionActions = () => {
 | |
|   getService('permission').actionProvider.registerMany(adminActions.actions);
 | |
| };
 | |
| 
 | |
| const registerAdminConditions = () => {
 | |
|   getService('permission').conditionProvider.registerMany(adminConditions.conditions);
 | |
| };
 | |
| 
 | |
| const syncAuthSettings = async () => {
 | |
|   const adminStore = await strapi.store({ type: 'core', name: 'admin' });
 | |
|   const adminAuthSettings = await adminStore.get({ key: 'auth' });
 | |
|   const newAuthSettings = merge(defaultAdminAuthSettings, adminAuthSettings);
 | |
| 
 | |
|   const roleExists = await getService('role').exists({
 | |
|     id: newAuthSettings.providers.defaultRole,
 | |
|   });
 | |
| 
 | |
|   // Reset the default SSO role if it has been deleted manually
 | |
|   if (!roleExists) {
 | |
|     newAuthSettings.providers.defaultRole = null;
 | |
|   }
 | |
| 
 | |
|   await adminStore.set({ key: 'auth', value: newAuthSettings });
 | |
| };
 | |
| 
 | |
| module.exports = async () => {
 | |
|   registerAdminConditions();
 | |
|   registerPermissionActions();
 | |
| 
 | |
|   const permissionService = getService('permission');
 | |
|   const userService = getService('user');
 | |
|   const roleService = getService('role');
 | |
|   const apiTokenService = getService('api-token');
 | |
| 
 | |
|   await roleService.createRolesIfNoneExist();
 | |
|   await roleService.resetSuperAdminPermissions();
 | |
|   await roleService.displayWarningIfNoSuperAdmin();
 | |
| 
 | |
|   await permissionService.ensureBoundPermissionsInDatabase();
 | |
|   await permissionService.cleanPermissionsInDatabase();
 | |
| 
 | |
|   await userService.displayWarningIfUsersDontHaveRole();
 | |
| 
 | |
|   await syncAuthSettings();
 | |
| 
 | |
|   apiTokenService.createSaltIfNotDefined();
 | |
| };
 | 
