Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
papnoisanjeev committed Dec 23, 2024
1 parent c823883 commit 39a0a52
Show file tree
Hide file tree
Showing 30 changed files with 224 additions and 153 deletions.
13 changes: 7 additions & 6 deletions Controller/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Filesystem\Filesystem as Fileservice;

class Account extends AbstractController
{
private $userService;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function loadDashboard(Request $request)

public function listAgents(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT')){
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -82,7 +83,7 @@ public function loadProfile(Request $request)
// Profile upload validation
$validMimeType = ['image/jpeg', 'image/png', 'image/jpg'];
if (isset($dataFiles['profileImage'])){
if (!in_array($dataFiles['profileImage']->getMimeType(), $validMimeType)) {
if (! in_array($dataFiles['profileImage']->getMimeType(), $validMimeType)) {
$this->addFlash('warning', $this->translator->trans('Error ! Profile image is not valid, please upload a valid format'));

return $this->redirect($this->generateUrl('helpdesk_member_profile'));
Expand All @@ -98,7 +99,7 @@ public function loadProfile(Request $request)
$errorFlag = 1;
}

if (!$errorFlag) {
if (! $errorFlag) {
$password = $user->getPassword();

$form = $this->createForm(UserProfile::class, $user);
Expand All @@ -113,7 +114,7 @@ public function loadProfile(Request $request)
// save previous password if password is blank or null provided
$encodedPassword = empty($submittedPassword) ? $password : $encoder->encodePassword($user, $submittedPassword);

if (!empty($encodedPassword) ) {
if (! empty($encodedPassword) ) {
$user->setPassword($encodedPassword);
} else {
$this->addFlash('warning', $this->translator->trans('Error! Given current password is incorrect.'));
Expand Down Expand Up @@ -164,7 +165,7 @@ public function loadProfile(Request $request)
// Recaptcha Setting
$recaptchaSetting = $em->getRepository(Recaptcha::class)->findOneBy(['id' => 1]);

if($recaptchaSetting) {
if ($recaptchaSetting) {
$recaptchaSetting->setSiteKey($data['recaptcha_site_key']);
$recaptchaSetting->setSecretKey($data['recaptcha_secret_key']);
if (isset($data['recaptcha_status'])) {
Expand Down Expand Up @@ -255,7 +256,7 @@ public function editAgent($agentId)
$errorFlag = 1;
}

if (!$errorFlag) {
if (! $errorFlag) {
if (
isset($data['password']['first']) && !empty(trim($data['password']['first']))
&& isset($data['password']['second']) && !empty(trim($data['password']['second']))
Expand Down
12 changes: 8 additions & 4 deletions Controller/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class Authentication extends AbstractController
{
private $userService;
Expand Down Expand Up @@ -46,15 +47,15 @@ public function clearProjectCache(Request $request)
$processId = (int) $output[0];

$responseContent = [
'alertClass' => 'success',
'alertClass' => 'success',
'alertMessage' => $this->translator->trans('Success ! Project cache cleared successfully.')
];

return new Response(json_encode($responseContent), 200, ['Content-Type' => 'application/json']);
}

$responseContent = [
'alertClass' => 'warning',
'alertClass' => 'warning',
'alertMessage' => $this->translator->trans('Error! Something went wrong.')
];

Expand Down Expand Up @@ -100,7 +101,7 @@ public function forgotPassword(Request $request)
$repository = $this->getDoctrine()->getRepository(User::class);
$user = $entityManager->getRepository(User::class)->findOneByEmail($form->getData()->getEmail());

if (!empty($user)) {
if (! empty($user)) {
// Trigger agent forgot password event
$event = new CoreWorkflowEvents\User\ForgotPassword();
$event
Expand All @@ -127,7 +128,10 @@ public function updateCredentials($email, $verificationCode, Request $request, U
$user = $entityManager->getRepository(User::class)->findOneByEmail($email);
$lastUpdatedInstance = $entityManager->getRepository(User::class)->lastUpdatedRole($user);

if (empty($user) || $user->getVerificationCode() != $verificationCode) {
if (
empty($user)
|| $user->getVerificationCode() != $verificationCode
) {
$this->addFlash('success', $this->translator->trans('You have already update password using this link if you wish to change password again click on forget password link here from login page'));

return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
Expand Down
1 change: 1 addition & 0 deletions Controller/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Filesystem\Filesystem as Fileservice;

class Customer extends AbstractController
{
private $userService;
Expand Down
11 changes: 6 additions & 5 deletions Controller/CustomerXHR.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class CustomerXHR extends AbstractController
{
private $userService;
Expand All @@ -27,7 +28,7 @@ public function __construct(UserService $userService, EventDispatcherInterface $

public function listCustomersXHR(Request $request, ContainerInterface $container)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -46,7 +47,7 @@ public function listCustomersXHR(Request $request, ContainerInterface $container

public function removeCustomerXHR(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -66,12 +67,12 @@ public function removeCustomerXHR(Request $request)

$this->eventDispatcher->dispatch($event, 'uvdesk.automation.workflow.execute');

$json['alertClass'] = 'success';
$json['alertClass'] = 'success';
$json['alertMessage'] = $this->translator->trans('Success ! Customer removed successfully.');
} else {
$json['alertClass'] = 'danger';
$json['alertClass'] = 'danger';
$json['alertMessage'] = $this->translator->trans('Error ! Invalid customer id.');
$json['statusCode'] = Response::HTTP_NOT_FOUND;
$json['statusCode'] = Response::HTTP_NOT_FOUND;
}
}

Expand Down
19 changes: 10 additions & 9 deletions Controller/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class Email extends AbstractController
{
const LIMIT = 10;
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function getTemplate($request)

public function templates(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -53,7 +54,7 @@ public function templates(Request $request)

public function templateForm(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -63,11 +64,11 @@ public function templateForm(Request $request)
$template = new EmailTemplates();
}

if (!$template) {
if (! $template) {
$this->noResultFound();
}

if (!$template->getMessage()) {
if (! $template->getMessage()) {
$template->setMessage('<p>{%global.companyLogo%}<hr></p><p><br><br><br></p><p><i>' . "Cheers !" . ' </i><br> <i style="color:#397b21">{%global.companyName%}</i><br></p>');
}

Expand Down Expand Up @@ -104,7 +105,7 @@ public function templateForm(Request $request)

public function templatesxhr(Request $request, ContainerInterface $container)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
if (! $this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_EMAIL_TEMPLATE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -115,21 +116,21 @@ public function templatesxhr(Request $request, ContainerInterface $container)
$repository = $this->getDoctrine()->getRepository(EmailTemplates::class);
$json = $repository->getEmailTemplates($request->query, $container);
} else {
if ($request->attributes->get('template')){
if ($request->attributes->get('template')) {
if ($templateBase = $this->getTemplate($request)) {
if ($request->getMethod() == 'DELETE' ) {
$em = $this->getDoctrine()->getManager();
$em->remove($templateBase);
$em->flush();

$json['alertClass'] = 'success';
$json['alertClass'] = 'success';
$json['alertMessage'] = 'Success! Template has been deleted successfully.';
} else
$error = true;
} else {
$json['alertClass'] = 'danger';
$json['alertClass'] = 'danger';
$json['alertMessage'] = $this->translator->trans('Warning! resource not found.');
$json['statusCode'] = Response::HTTP_NO_FOUND;
$json['statusCode'] = Response::HTTP_NO_FOUND;
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions Controller/EmailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer;
use Webkul\UVDesk\MailboxBundle\Services\MailboxService;

class EmailSettings extends AbstractController
{
private $userService;
Expand All @@ -27,7 +28,7 @@ public function loadSettings()
{
$smtpConfiguration = $swiftmailerConfigurations = [];

if (!$this->userService->isAccessAuthorized('ROLE_ADMIN')) {
if (! $this->userService->isAccessAuthorized('ROLE_ADMIN')) {
throw new AccessDeniedException("Insufficient account privileges");
}

Expand All @@ -39,14 +40,17 @@ public function loadSettings()
$smtpConfig = $mailbox->getSmtpConfiguration();
$swiftmailerConfig = $mailbox->getSwiftMailerConfiguration();

if ($smtpConfig && $mailbox->getIsenabled()) {
if (
$smtpConfig
&& $mailbox->getIsenabled()
) {
$smtpConfiguration[] = $mailbox->getId();
}
}

return $this->render('@UVDeskCoreFramework//Email//emailSettings.html.twig', [
'swiftmailers' => $swiftmailerConfigurations,
'outlooks' => $smtpConfiguration,
'outlooks' => $smtpConfiguration,
'email_settings' => [
'id' => $this->getParameter('uvdesk.support_email.id'),
'name' => $this->getParameter('uvdesk.support_email.name'),
Expand Down
15 changes: 8 additions & 7 deletions Controller/EmailSettingsXHR.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer;
use Symfony\Component\HttpKernel\KernelInterface;

class EmailSettingsXHR extends AbstractController
{
private $userService;
Expand Down Expand Up @@ -45,14 +46,14 @@ public function updateSettingsXHR(Request $request)
$mailer_id = ( $supportEmailConfiguration['mailer_id'] == 'None Selected' ? '~' : $supportEmailConfiguration['mailer_id'] );

$file_content_array = strtr(require __DIR__ . "/../Templates/uvdesk.php", [
'{{ SUPPORT_EMAIL_ID }}' => $supportEmailConfiguration['id'],
'{{ SUPPORT_EMAIL_NAME }}' => $supportEmailConfiguration['name'],
'{{ SUPPORT_EMAIL_MAILER_ID }}' => $mailer_id,
'{{ SUPPORT_EMAIL_ID }}' => $supportEmailConfiguration['id'],
'{{ SUPPORT_EMAIL_NAME }}' => $supportEmailConfiguration['name'],
'{{ SUPPORT_EMAIL_MAILER_ID }}' => $mailer_id,
'{{ SUPPORT_EMAIL_MAILER_TYPE }}' => $supportEmailConfiguration['smtp[transport]'],
'{{ SITE_URL }}' => $request->getHttpHost() . $request->getBasePath(),
'{{ APP_LOCALES }}' => $app_locales,
'{{ MEMBER_PANEL_PREFIX }}' => $memberPrefix,
'{{ CUSTOMER_PANEL_PREFIX }}' => $customerPrefix,
'{{ SITE_URL }}' => $request->getHttpHost() . $request->getBasePath(),
'{{ APP_LOCALES }}' => $app_locales,
'{{ MEMBER_PANEL_PREFIX }}' => $memberPrefix,
'{{ CUSTOMER_PANEL_PREFIX }}' => $customerPrefix,
]);

// update uvdesk.yaml file
Expand Down
Loading

0 comments on commit 39a0a52

Please sign in to comment.