import { RoleDefinition } from "gd-sprest-def/lib/SP" ; import { IaddPermissionLevel , IaddPermissionLevelProps } from "../../../@types/helper/methods" ; import { Site } from "../../lib" ; declare var SP ; /**
 * Adds a permission level to the current or specified web.
 */ export const addPermissionLevel = ( props ) : PromiseLike < RoleDefinition > => { return new Promise ( ( resolve , reject ) => { if ( SP && SP . BasePermissions ) { let ctx = props . WebUrl ? new SP . ClientContext ( props . WebUrl ) : SP . ClientContext . get_current ( ) ; let basePermissions = new SP . BasePermissions ( ) ; let permissions = props . Permissions || [ ] ; for ( let i = 0 ; i < permissions . length ; i ++ ) { basePermissions . set ( permissions [ i ] ) ; } let roleDefInfo = new SP . RoleDefinitionCreationInformation ( ) ; roleDefInfo . set_basePermissions ( basePermissions ) ; roleDefInfo . set_description ( props . Description ) ; roleDefInfo . set_order ( props . Order ) ; roleDefInfo . set_name ( props . Name ) ; let roleDef = ctx . get_site ( ) . get_rootWeb ( ) . get_roleDefinitions ( ) . add ( roleDefInfo ) ; ctx . load ( roleDef ) ; ctx . executeQueryAsync ( ( ) => { Site ( props . WebUrl ) . RootWeb ( ) . RoleDefinitions ( ) . getById ( roleDef . get_id ( ) ) . execute ( roleDef => { resolve ( roleDef ) ; } , reject ) ; } , reject ) ; } else { reject ( "The 'SP' core library is not available." ) ; } } ) ; } ;