Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Menu.php #6808

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
'admin.api.key': 'ajGwpy8Pdai22XDUpqjC5Ob04v0eG7EGgb4vz2bD2juT8YDmfM',
'user.api.key': 'JZJApQ9XOnF7nvupWZlTWBRrqMtHE9eNcWBTUzEWGqL4Sdqp6C',
},
retries: 2,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
Expand Down
5 changes: 1 addition & 4 deletions src/BackupDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

// Security: User must be an Admin to access this page.
// Otherwise, re-direct them to the main menu.
if (!AuthenticationManager::getCurrentUser()->isAdmin()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isAdmin());


// Set the page title and include HTML header
Expand Down
2 changes: 1 addition & 1 deletion src/BatchWinnerEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<input type="button" class="btn btn-default" value="<?= gettext('Cancel') ?>" name="Cancel" onclick="javascript:document.location='<?php if (strlen($linkBack) > 0) {
echo $linkBack;
} else {
echo 'Menu.php';
echo 'v2/dashboard';
} ?>';">
</td>
</tr>
Expand Down
5 changes: 1 addition & 4 deletions src/CSVImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\RedirectUtils;

if (!AuthenticationManager::getCurrentUser()->isAdmin()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isAdmin());

/**
* A monogamous society is assumed, however it can be patriarchal or matriarchal
Expand Down
5 changes: 1 addition & 4 deletions src/CanvassAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
$sPageTitle = gettext('Canvass Automation');

// Security: User must have canvasser permission to use this form
if (!AuthenticationManager::getCurrentUser()->isCanvasserEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isCanvasserEnabled());

$iFYID = CurrentFY();
if (array_key_exists('idefaultFY', $_SESSION)) {
Expand Down
7 changes: 2 additions & 5 deletions src/CanvassEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Security: User must have canvasser permission to use this form
if (!AuthenticationManager::getCurrentUser()->isCanvasserEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isCanvasserEnabled());

require 'Include/CanvassUtilities.php';

Expand Down Expand Up @@ -244,7 +241,7 @@
<input type="button" class="btn btn-default" value="<?= gettext('Cancel') ?>" name="Cancel" onclick="javascript:document.location='<?php if (strlen($linkBack) > 0) {
echo $linkBack;
} else {
echo 'Menu.php';
echo 'v2/dashboard';
} ?>';">

</div>
Expand Down
5 changes: 1 addition & 4 deletions src/CartToEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Security: User must have Manage Groups & Roles permission
if (!AuthenticationManager::getCurrentUser()->isManageGroupsEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isManageGroupsEnabled());

// Was the form submitted?
if (isset($_POST['Submit']) && count($_SESSION['aPeopleCart']) > 0 && isset($_POST['EventID'])) {
Expand Down
5 changes: 1 addition & 4 deletions src/CartToFamily.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Security: User must have add records permission
if (!AuthenticationManager::getCurrentUser()->isAddRecordsEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isAddRecordsEnabled());

// Was the form submitted?
if (isset($_POST['Submit']) && count($_SESSION['aPeopleCart']) > 0) {
Expand Down
5 changes: 1 addition & 4 deletions src/CartToGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Security: User must have Manage Groups & Roles permission
if (!AuthenticationManager::getCurrentUser()->isManageGroupsEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isManageGroupsEnabled());

// Was the form submitted?
if ((isset($_GET['groupeCreationID']) || isset($_POST['Submit'])) && count($_SESSION['aPeopleCart']) > 0) {
Expand Down
8 changes: 7 additions & 1 deletion src/ChurchCRM/Authentication/AuthenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function authenticate(AuthenticationRequest $AuthenticationRequest
}

if ($result->isAuthenticated && !$result->preventRedirect) {
$redirectLocation = array_key_exists('location', $_SESSION) ? $_SESSION['location'] : 'Menu.php';
$redirectLocation = $_SESSION['location'] ?? 'v2/dashboard';
NotificationService::updateNotifications();
$logger->debug(
'Authentication Successful; redirecting to: ' . $redirectLocation
Expand Down Expand Up @@ -209,4 +209,10 @@ public static function getForgotPasswordURL(): string
// but rather redirect users to some other password reset mechanism.
return SystemURLs::getRootPath() . '/session/forgot-password/reset-request';
}
public static function redirectHomeIfFalse(bool $hasAccess): void
{
if (!$hasAccess) {
RedirectUtils::redirect('v2/dashboard');
}
}
}
4 changes: 2 additions & 2 deletions src/ChurchCRM/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(string $BaseName, $BackupType, $IncludeExtraneousFil
);
}

public function copyToWebDAV(string $Endpoint, string $Username, string $Password)
public function copyToWebDAV(string $Endpoint, string $Username, string $Password): bool
{
LoggerUtils::getAppLogger()->info('Beginning to copy backup to: ' . $Endpoint);

Expand All @@ -78,7 +78,7 @@ public function copyToWebDAV(string $Endpoint, string $Username, string $Passwor
curl_setopt($ch, CURLOPT_INFILESIZE, $this->BackupFile->getSize());
LoggerUtils::getAppLogger()->debug('Beginning to send file');
$time = new ExecutionTime();
$result = curl_exec($ch);
$result = (bool) curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Backup/JobBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JobBase
*/
protected $TempFolder;

protected function createEmptyTempFolder()
protected function createEmptyTempFolder(): string
{
// both backup and restore operations require a clean temporary working folder. Create it.
$TempFolder = SystemURLs::getDocumentRoot() . '/tmp_attach/ChurchCRMBackups';
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Config/Menu/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function getMenu(): ?array
private static function buildMenuItems(): array
{
return [
'Dashboard' => new MenuItem(gettext('Dashboard'), 'Menu.php', true, 'fa-tachometer-alt'),
'Dashboard' => new MenuItem(gettext('Dashboard'), 'v2/dashboard', true, 'fa-tachometer-alt'),
'Calendar' => self::getCalendarMenu(),
'People' => self::getPeopleMenu(),
'Groups' => self::getGroupMenu(),
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Emails/users/BaseUserEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct($user)

abstract protected function getSubSubject();

public function getTokens()
public function getTokens(): array
{
$myTokens = ['toName' => $this->user->getPerson()->getFirstName(),
'userName' => $this->user->getUserName(),
Expand All @@ -37,7 +37,7 @@ public function getTokens()
return array_merge($this->getCommonTokens(), $myTokens);
}

protected function getFullURL()
protected function getFullURL(): string
{
return SystemURLs::getURL() . '/session/begin?username=' . $this->user->getUserName();
}
Expand Down
6 changes: 3 additions & 3 deletions src/ChurchCRM/Service/MailChimpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ private function getListsFromCache()
return $_SESSION['MailChimpLists'];
}

public function isEmailInMailChimp(?string $email)
public function isEmailInMailChimp(?string $email): array
{
if (empty($email)) {
return new Exception(gettext('No email passed in'));
throw new Exception(gettext('No email passed in'));
}

if (!$this->isActive()) {
return new Exception(gettext('Mailchimp is not active'));
throw new Exception(gettext('Mailchimp is not active'));
}

$lists = $this->getListsFromCache();
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/dto/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function countPeople(): int
return count($_SESSION['aPeopleCart']);
}

public static function convertCartToString($aCartArray)
public static function convertCartToString($aCartArray): string
{
// Implode the array
$sCartString = implode(',', $aCartArray);
Expand Down
32 changes: 21 additions & 11 deletions src/ChurchCRM/dto/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ private function photoHunt(): void
}

if (SystemConfig::getBooleanValue('bEnableGravatarPhotos')) {
$photoPath = $this->loadFromGravatar($personEmail, $baseName);
if ($photoPath) {
try {
$photoPath = $this->loadFromGravatar($personEmail, $baseName);
$this->setURIs($photoPath);

return;
} catch (\Exception $e) {
// do nothing
}
}
}
Expand All @@ -166,7 +168,7 @@ private function convertToPNG(): void
$this->setURIs($targetPath);
}

private function getGDImage($sourceImagePath)
private function getGDImage($sourceImagePath): \GdImage
{
$sourceImageType = exif_imagetype($sourceImagePath);
switch ($sourceImageType) {
Expand All @@ -182,6 +184,7 @@ private function getGDImage($sourceImagePath)
default:
throw new \Exception('Unsupported image type: ' . $sourceImageType);
}
MiscUtils::throwIfFailed($sourceGDImage);

return $sourceGDImage;
}
Expand All @@ -193,18 +196,24 @@ private function ensureThumbnailsPath(): void
}
}

public function getThumbnailBytes()
public function getThumbnailBytes(): string
{
if (!file_exists($this->photoThumbURI)) {
$this->createThumbnail();
}

return file_get_contents($this->photoThumbURI);
$content = file_get_contents($this->photoThumbURI);
MiscUtils::throwIfFailed($content);

return $content;
}

public function getPhotoBytes()
public function getPhotoBytes(): string|false
{
return file_get_contents($this->photoURI);
$content = file_get_contents($this->photoURI);
MiscUtils::throwIfFailed($content);

return $content;
}

public function getPhotoContentType()
Expand Down Expand Up @@ -237,7 +246,7 @@ public function getPhotoURI()
return $this->photoURI;
}

private function loadFromGravatar($email, string $baseName)
private function loadFromGravatar($email, string $baseName): string
{
$s = 60;
$d = '404';
Expand All @@ -256,10 +265,10 @@ private function loadFromGravatar($email, string $baseName)
return $photoPath;
}

return false;
throw new \Exception('Gravatar not found');
}

private function loadFromGoogle($email, string $baseName)
private function loadFromGoogle($email, string $baseName): string|false
{
$url = 'http://picasaweb.google.com/data/entry/api/user/';
$url .= strtolower(trim($email));
Expand All @@ -284,7 +293,7 @@ private function loadFromGoogle($email, string $baseName)
return false;
}

private function getRandomColor($image)
private function getRandomColor(\GdImage $image): int|false
{
$red = random_int(0, 150);
$green = random_int(0, 150);
Expand Down Expand Up @@ -318,6 +327,7 @@ private function renderInitials(): void
$pointSize = SystemConfig::getValue('iInitialsPointSize');
$font = SystemURLs::getDocumentRoot() . '/fonts/Roboto-Regular.ttf';
$image = imagecreatetruecolor($width, $height);
MiscUtils::throwIfFailed($image);
$bgcolor = $this->getRandomColor($image);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, $height, $width, $bgcolor);
Expand Down
15 changes: 13 additions & 2 deletions src/ChurchCRM/utils/InputUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ public static function legacyFilterInputArr(array $arr, $key, $type = 'string',
}
}

public static function translateSpecialCharset($string)
public static function translateSpecialCharset($string): string
{
if (empty($string)) {
return '';
}

return (SystemConfig::getValue('sCSVExportCharset') === 'UTF-8') ? gettext($string) : iconv('UTF-8', SystemConfig::getValue('sCSVExportCharset'), gettext($string));
if (SystemConfig::getValue('sCSVExportCharset') === 'UTF-8') {
return gettext($string);
}

$resultString = iconv(
'UTF-8',
SystemConfig::getValue('sCSVExportCharset'),
gettext($string)
);
MiscUtils::throwIfFailed($resultString);

return $resultString;
}

public static function filterString($sInput): string
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/utils/RedirectUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public static function absoluteRedirect(string $sTargetURL): void
public static function securityRedirect(string $missingRole): void
{
LoggerUtils::getAppLogger()->info('Security Redirect Request due to Role: ' . $missingRole);
self::Redirect('Menu.php');
self::Redirect('v2/dashboard');
}
}
5 changes: 1 addition & 4 deletions src/ConvertIndividualToFamily.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Security
if (!AuthenticationManager::getCurrentUser()->isAdmin()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isAdmin());

if ($_GET['all'] == 'true') {
$bDoAll = true;
Expand Down
4 changes: 2 additions & 2 deletions src/DepositSlipEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@

// Security: User must have finance permission or be the one who created this deposit
if (!(AuthenticationManager::getCurrentUser()->isFinanceEnabled() || AuthenticationManager::getCurrentUser()->getId() == $thisDeposit->getEnteredby())) {
RedirectUtils::redirect('Menu.php');
RedirectUtils::redirect('v2/dashboard');
exit;
}
} elseif ($iDepositSlipID == 0) {
RedirectUtils::redirect('FindDepositSlip.php');
exit;
} else {
RedirectUtils::redirect('Menu.php');
RedirectUtils::redirect('v2/dashboard');
}

//Set the page title
Expand Down
7 changes: 2 additions & 5 deletions src/DirectoryReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
use ChurchCRM\Utils\RedirectUtils;

// Check for Create Directory user permission.
if (!AuthenticationManager::getCurrentUser()->isCreateDirectoryEnabled()) {
RedirectUtils::redirect('Menu.php');
exit;
}
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isCreateDirectoryEnabled());

// Set the page title and include HTML header
$sPageTitle = gettext('Directory reports');
Expand Down Expand Up @@ -285,7 +282,7 @@
<p align="center">
<BR>
<input type="submit" class="btn btn-primary" name="Submit" value="<?= gettext('Create Directory') ?>">
<input type="button" class="btn btn-default" name="Cancel" <?= 'value="' . gettext('Cancel') . '"' ?> onclick="javascript:document.location='Menu.php';">
<input type="button" class="btn btn-default" name="Cancel" <?= 'value="' . gettext('Cancel') . '"' ?> onclick="javascript:document.location='v2/dashboard';">
</p>
</form>
</div>
Expand Down
Loading
Loading