Skip to content

Commit

Permalink
Merge branch '1.0' of https://github.com/uvdesk/core-framework into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay kumar committed Oct 23, 2019
2 parents 244407e + 932e055 commit 361383a
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 178 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ CHANGELOG for 1.0.x

This changelog references any relevant changes introduced in 1.0 minor versions.

* 1.0.3 (2019-10-23)
* **Issue #230:** Custom field privilege issue
* **Issue #29:** File attachment limit exceed
* **Issue #234:** Agent profile issue while thread added at customer panel
* **Issue #240:** Super admin name is not showing when set via terminal
* **Misc. Updates:**
* Added patch to support previously configured workflows with deprecated events
* Both agents and customers now share a common password reset page (events agent.forgot_password & customer.forgot_password deprecated)
* Updated README.md with link to the official gitter chat for uvdesk/core-framework

* 1.0.1 (2019-10-15)
* **Issue #223:** Custom field privilege issue
* **Issue #224:** Email template privilege issue
Expand Down
99 changes: 45 additions & 54 deletions Controller/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Webkul\UVDesk\CoreFrameworkBundle\Controller;

use Symfony\Component\Form\FormError;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
use Symfony\Component\HttpFoundation\Response;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;

class Authentication extends Controller
Expand All @@ -32,82 +34,71 @@ public function logout(Request $request)

public function forgotPassword(Request $request)
{
if (null == $this->get('user.service')->getSessionUser()) {
$entityManager = $this->getDoctrine()->getManager();
if (null != $this->get('user.service')->getSessionUser()) {
return new Response('How did you land here? :/', 404);
}

$entityManager = $this->getDoctrine()->getManager();

if ($request->getMethod() == 'POST') {
$user = new User();
$form = $this->createFormBuilder($user,['csrf_protection' => false])
->add('email',EmailType::class)
->getForm();
if ($request->getMethod() == 'POST') {
$user = new User();
$form = $this->createFormBuilder($user,['csrf_protection' => false])
->add('email',EmailType::class)
->getForm();

$form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
$form->handleRequest($request);

if ($form->isValid()) {
$repository = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneBy(array('email' => $form->getData()->getEmail()));

if ($user && $user->getAgentInstance()) {
// Trigger agent forgot password event
$event = new GenericEvent(CoreWorkflowEvents\Agent\ForgotPassword::getId(), [
'entity' => $user,
]);

$this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute', $event);
$request->getSession()->getFlashBag()->set('success','Please check your mail for password update.');
$form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
$form->handleRequest($request);

if ($form->isValid()) {
$repository = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($form->getData()->getEmail());

if (!empty($user)) {
// Trigger agent forgot password event
$event = new GenericEvent(CoreWorkflowEvents\UserForgotPassword::getId(), [
'entity' => $user,
]);

return $this->redirect($this->generateUrl('helpdesk_member_update_account_credentials')."/".$form->getData()->getEmail());
} else {
$request->getSession()->getFlashBag()->set('warning', 'This Email address is not registered with us.');
}
$this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute', $event);
$request->getSession()->getFlashBag()->set('success', 'Please check your mail for password update.');
} else {
$request->getSession()->getFlashBag()->set('warning', 'This email address is not registered with us.');
}
}

return $this->render("@UVDeskCoreFramework//forgotPassword.html.twig");
}

return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
return $this->render("@UVDeskCoreFramework//forgotPassword.html.twig");
}

public function updateCredentials($email, $verificationCode)
public function updateCredentials($email, $verificationCode, Request $request, UserPasswordEncoderInterface $encoder)
{
if (empty($email) || empty($verificationCode)) {
return $this->redirect($this->generateUrl('helpdesk_member_handle_login'));
return new Response('How did you land here? :/', 404);
} else {
$entityManager = $this->getDoctrine()->getManager();
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

if (empty($user) || $user->getVerificationCode() != $verificationCode) {
return new Response('How did you land here? :/', 404);
}
}

$entityManager = $this->getDoctrine()->getManager();
$request = $this->container->get('request_stack')->getCurrentRequest();

// Validate request
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

if (empty($user) || null == $user->getAgentInstance() || $user->getVerificationCode() != $verificationCode) {
return $this->redirect($this->generateUrl('helpdesk_member_handle_login'));
}

if ($request->getMethod() == 'POST') {
$updatedCredentials = $request->request->all();

if ($updatedCredentials['password'] === $updatedCredentials['confirmPassword']) {
$user->setPassword($this->encodePassword($user, $updatedCredentials['password']));
$user->setPassword($encoder->encodePassword($user, $updatedCredentials['password']));
$user->setVerificationCode(TokenGenerator::generateToken());

$entityManager->persist($user);
$entityManager->flush();

$request->getSession()->getFlashBag()->set('success', 'Your password has been updated successfully.');
return $this->redirect($this->generateUrl('helpdesk_member_handle_login'));
} else {
$request->getSession()->getFlashBag()->set('warning', "Password don't match.");
$request->getSession()->getFlashBag()->set('warning', "Please try again. The passwords do not match.");
}
}

return $this->render("@UVDeskCoreFramework//resetPassword.html.twig");
}

protected function encodePassword(User $user, $plainPassword)
{
return $encodedPassword = $this->container->get('security.password_encoder')->encodePassword($user, $plainPassword);
return $this->render("@UVDeskCoreFramework//resetPassword.html.twig");
}
}
3 changes: 1 addition & 2 deletions Fixtures/EmailTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
class EmailTemplates extends DoctrineFixture
{
private static $seeds = [
CoreEmailTemplates\UserForgotPassword::class,
CoreEmailTemplates\Agent\TicketReply::class,
CoreEmailTemplates\Agent\TicketCreated::class,
CoreEmailTemplates\Agent\AccountCreated::class,
CoreEmailTemplates\Agent\ForgotPassword::class,
CoreEmailTemplates\Agent\TicketAssigned::class,
CoreEmailTemplates\Customer\TicketReply::class,
CoreEmailTemplates\Customer\TicketCreated::class,
CoreEmailTemplates\Customer\AccountCreated::class,
CoreEmailTemplates\Customer\ForgotPassword::class,
];

public function load(ObjectManager $entityManager)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<img src="https://s3-ap-southeast-1.amazonaws.com/cdn.uvdesk.com/uvdesk/bundles/webkuldefault/images/uvdesk-wide.svg">
</a></p>

[UVDesk Community Edition][1] is an easy-to-use, highly customizable open-source **helpdesk solution** built on top of the reliable [Symfony][2] **PHP framework**, enabling organizations to provide their customers with the best level of support solution possible.

CoreFrameworkBundle
--------------
<p align="center">
<a href="https://packagist.org/packages/uvdesk/core-framework"><img src="https://poser.pugx.org/uvdesk/core-framework/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/uvdesk/core-framework"><img src="https://poser.pugx.org/uvdesk/core-framework/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/uvdesk/core-framework"><img src="https://poser.pugx.org/uvdesk/core-framework/license.svg" alt="License"></a>
<a href="https://gitter.im/uvdesk/core-framework"><img src="https://badges.gitter.im/uvdesk/core-framework.svg" alt="connect on gitter"></a>
</p>

The standalone **CoreFrameworkBundle** lies at the heart of the [UVDesk Community][1] helpdesk, providing the core essential functionalities and integration tools to easily integrate any other community helpdesk packages, furhter extending the capabilities of the helpdesk system.

Expand Down
2 changes: 1 addition & 1 deletion Repository/ThreadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function getAllCustomerThreads($ticketId,\Symfony\Component\HttpFoundatio
'reply' => html_entity_decode($thread['message']),
'source' => $thread['source'],
'threadType' => $thread['threadType'],
'userType' => 'customer',
'userType' => $thread['createdBy'],
'formatedCreatedAt' => $userService->getLocalizedFormattedTime($userService->getSessionUser(), $thread['createdAt']),
'timestamp' => $userService->convertToDatetimeTimezoneTimestamp($thread['createdAt']),
'cc' => $thread['cc'],
Expand Down
9 changes: 0 additions & 9 deletions Resources/config/routes/private.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ helpdesk_member_handle_logout:
path: /logout
controller: Webkul\UVDesk\CoreFrameworkBundle\Controller\Authentication::logout

helpdesk_member_forgot_account_password:
path: /forgot-password
controller: Webkul\UVDesk\CoreFrameworkBundle\Controller\Authentication::forgotPassword

helpdesk_member_update_account_credentials:
path: /update-credentials/{email}/{verificationCode}
controller: Webkul\UVDesk\CoreFrameworkBundle\Controller\Authentication::updateCredentials
defaults: { email: '', verificationCode: '' }

# Agent Panel Resources
helpdesk_member_dashboard:
path: /dashboard
Expand Down
13 changes: 12 additions & 1 deletion Resources/config/routes/public.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Add public routing resources here ...
# Add public routing resources here ...
helpdesk_forgot_account_password:
path: /{_locale}/forgot-password
controller: Webkul\UVDesk\CoreFrameworkBundle\Controller\Authentication::forgotPassword
requirements: { _locale: '%app_locales%' }
defaults: { _locale: '%locale%' }

helpdesk_update_account_credentials:
path: /{_locale}/update-credentials/{email}/{verificationCode}
controller: Webkul\UVDesk\CoreFrameworkBundle\Controller\Authentication::updateCredentials
requirements: { _locale: '%app_locales%' }
defaults: { _locale: '%locale%', email: '', verificationCode: '' }
66 changes: 57 additions & 9 deletions Resources/views/Templates/attachment.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,85 @@
$(function () {
var FileView = Backbone.View.extend({
fileCounter: 0,
max_post_size: {{ max_post_size }},
max_file_uploads: {{ max_file_uploads }},
upload_max_filesize: {{ upload_max_filesize }},
el: '.attachment-block',
events : {
'click .uv-file-label': 'createFileType',
'change .attachment': 'selectFile',
'click .uv-added-attachment span': 'removeFile'
'click .uv-added-attachment span': 'removeFile',
'click .uv-field-message': 'removeError',
},
createFileType: function(e) {
currentElement = Backbone.$(e.currentTarget)
this.removeError(e)
var currentElement = Backbone.$(e.currentTarget),
attachmentBlock = currentElement.parents('.attachment-block')
if (attachmentBlock.children('.uv-added-attachment').length + 1 > this.max_file_uploads) {
attachmentBlock.append(this.getDefaultErrorMessage())
return;
}
this.fileCounter += 1;
currentElement.parents('.attachment-block').append('<div class="uv-added-attachment" style="display: none" id="file-' + this.fileCounter + '"><div class="uv-attachment"><input type="file" name="attachments[]" class="attachment" multiple="multiple"></div><span></span></div>')
attachmentBlock.append('<div class="uv-added-attachment" style="display: none" id="file-' + this.fileCounter + '"><div class="uv-attachment"><input type="file" name="attachments[]" class="attachment" multiple="multiple"></div><span></span></div>')
$('#file-' + this.fileCounter).find('.attachment').trigger('click')
},
labelTemplate: _.template('<label class="file-name"><%- fileName %></label><br>'),
selectFile: function(e) {
currentElement = Backbone.$(e.currentTarget)
var currentElement = Backbone.$(e.currentTarget);
var attachmentBlock = currentElement.parents(".uv-added-attachment");
if(currentElement.length) {
files = currentElement[0].files;
if(files.length) {
var isError = false;
if (currentElement.length) {
files = currentElement[0].files;
if (files.length) {
for (var i = 0; i < files.length; i++) {
var fileName = files[i].name;
if (files[i].size > this.upload_max_filesize) {
isError = true;
break;
}
// Validating Form Size
var formSize = 0
var formData = new FormData(currentElement.parents('form')[0])
for (var pair of formData.entries()) {
if (pair[1] instanceof Blob) {
formSize += pair[1].size
} else {
formSize += pair[1].length
}
}
if (formSize > this.max_post_size) {
isError = true
}
attachmentBlock.append(this.labelTemplate({'fileName': fileName}));
}
}
}
}
if (isError) {
attachmentBlock.parents('.attachment-block').append(this.getDefaultErrorMessage())
attachmentBlock.remove()
return
}
attachmentBlock.show()
},
removeFile: function(e) {
this.removeError(e)
Backbone.$(e.currentTarget).parents('.uv-added-attachment').remove()
}
},
getDefaultErrorMessage: function() {
return '<span class="uv-field-message">You can send up to ' + Math.floor(this.upload_max_filesize/(1024*1024)) + ' MB in attachments. If you have more than one attachment, they can\'t add up to more than ' + Math.floor(this.max_post_size/(1024*1024)) + ' MB and ' + this.max_file_uploads + ' attachments in total.</span>'
},
removeError: function(e) {
Backbone.$(e.currentTarget).parents('.attachment-block').find('.uv-field-message').remove()
}
});
var fileView = new FileView();
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Templates/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</div>

{% set currentUser = user_service.getSessionUser() %}
{% if currentUser is not empty %}
{% if currentUser is not empty and currentUser.getAgentInstance() is not empty %}
{% set currentUserDetails = currentUser.getAgentInstance().getPartialDetails() %}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="uv-adjacent-element-block" style="position: relative;">
<label>Password</label>
<div class="uv-max-field">
<a class="forgot-password-cta" href="{{ path('helpdesk_member_forgot_account_password') }}" tabindex="-1">Forgot Password?</a>
<a class="forgot-password-cta" href="{{ path('helpdesk_forgot_account_password') }}" tabindex="-1">Forgot Password?</a>
<input type="password" name="_password">
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Services/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function getEmailPlaceholderValues(User $user, $userType = 'member')
}

// Link to update account login credentials
$updateCredentialsURL = $router->generate(('customer' == $userType) ? 'helpdesk_customer_update_account_credentials' : 'helpdesk_member_update_account_credentials', [
$updateCredentialsURL = $router->generate( 'helpdesk_update_account_credentials', [
'email' => $user->getEmail(),
'verificationCode' => $user->getVerificationCode(),
], UrlGeneratorInterface::ABSOLUTE_URL);
Expand Down
14 changes: 7 additions & 7 deletions Services/TicketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,16 @@ public function isTicketAccessGranted(Ticket $ticket, User $user = null, $firewa
// @TODO: Take current firewall into consideration (access check on behalf of agent/customer)
if (empty($user)) {
$user = $this->container->get('user.service')->getSessionUser();

if (empty($user)) {
return false;
}
}

$agentInstance = $user->getAgentInstance();

if (empty($agentInstance)) {
if (empty($user)) {
return false;
} else {
$agentInstance = $user->getAgentInstance();

if (empty($agentInstance)) {
return false;
}
}

if ($agentInstance->getSupportRole()->getId() == 3 && in_array($agentInstance->getTicketAccessLevel(), [2, 3, 4])) {
Expand Down
Loading

0 comments on commit 361383a

Please sign in to comment.