mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	This trims role names before validation and subsequent validation. This fixes a bug where you could have names that were empty or that were duplicates of other names, but with leading or trailing spaces. (They display the same in the UI). This does not modify how we handle descriptions in the API. While the UI form requires you to enter a description, the API does not. As such, we can't make that required now without it being a breaking change.
		
			
				
	
	
		
			25 lines
		
	
	
		
			736 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			736 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import joi from 'joi';
 | 
						|
 | 
						|
export const permissionRoleSchema = joi
 | 
						|
    .object()
 | 
						|
    .keys({
 | 
						|
        id: joi.number(),
 | 
						|
        name: joi.string(),
 | 
						|
        environment: joi.string().optional().allow('').allow(null).default(''),
 | 
						|
    })
 | 
						|
    .or('id', 'name')
 | 
						|
    .options({ stripUnknown: true, allowUnknown: false, abortEarly: false });
 | 
						|
 | 
						|
export const roleSchema = joi
 | 
						|
    .object()
 | 
						|
    .keys({
 | 
						|
        name: joi.string().trim().required(),
 | 
						|
        description: joi.string().optional().allow('').allow(null).default(''),
 | 
						|
        permissions: joi
 | 
						|
            .array()
 | 
						|
            .allow(null)
 | 
						|
            .optional()
 | 
						|
            .items(permissionRoleSchema),
 | 
						|
    })
 | 
						|
    .options({ stripUnknown: true, allowUnknown: false, abortEarly: false });
 |