/**
  * @param ProgramYearInterface $programYear
  * @param UserInterface $user
  * @return bool
  */
 protected function isWriteGranted(ProgramYearInterface $programYear, $user)
 {
     // the given user is granted CREATE/EDIT/DELETE permissions on the given program year
     // when at least one of the following statements is true
     // 1. The user's primary school is the same as the parent program's owning school
     //    and the user has at least one of 'Course Director' and 'Developer' role.
     // 2. The user has WRITE permissions on the parent program's owning school
     //    and the user has at least one of 'Course Director' and 'Developer' role.
     // 3. The user's primary school matches at least one of the schools owning the
     //    program years' stewarding department,
     //    and the user has at least one of 'Course Director' and 'Developer' role.
     // 4. The user has WRITE permissions on the parent program.
     return $this->userHasRole($user, ['Course Director', 'Developer']) && ($this->schoolsAreIdentical($programYear->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $programYear->getSchool()->getId()) || $this->stewardManager->schoolIsStewardingProgramYear($user, $programYear)) || $this->permissionManager->userHasWritePermissionToProgram($user, $programYear->getProgram());
 }