public function getFarmRole($farmRoleId, $farmId = null, $modify = false)
{
/* @var $role FarmRole */
$role = FarmRole::findPk($farmRoleId);
if (!$role) {
throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Farm Role either does not exist or is not owned by your environment.");
}
if (isset($farmId)) {
if ($role->farmId != $farmId) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the farm");
}
} else {
$farmId = $role->farmId;
}
$this->getFarm($farmId, $modify);
if (!$this->hasPermissions($role, $modify)) {
//Checks entity level write access permissions
throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions");
}
return $role;
}