def create_role_with_permissions(step, stored, name): roleModel = RoleModel() name = roleModel.get_stored_or_store_name(stored, name) # create the new role role_payload = {"companyId": CompanyModel().get_seed_resid()[0], "name": name} roleModel.create(role_payload) #get the new role ID role_id, role_version = roleModel.get_resid(name) # get the list of all available permissions perm_array = PermissionModel().get_all_list() # walk the hash of permissionCodes add these to the new role for perm_code in step.hashes: permissionCode = perm_code["permissionCode"] # find the matching permission object based on the permissionCode field found_perm = verify_single_item_in_list(perm_array, "permissionCode", permissionCode) try: # there will always be only one that matches, in this case perm_id = found_perm[ns("resourceIdentity")]["@id"] except KeyError: assert False, "%s.%s not found in:\n%s" % (ns("resourceIdentity"), "@id", found_perm) # now add the permissions to that role roleModel.add_permission(role_id, role_version, perm_id)