Commit 34158785 authored by Sebastian Castro's avatar Sebastian Castro

Improve modification from hash with new status and hide owning checkbox if not loggued

parent 111afdc7
parameters:
app.version: 1.7.4
\ No newline at end of file
app.version: 1.7.5
\ No newline at end of file
......@@ -6,7 +6,7 @@
*
* @copyright Copyright (c) 2016 Sebastian Castro - 90scastro@gmail.com
* @license MIT License
* @Last Modified time: 2018-03-18 15:25:35
* @Last Modified time: 2018-04-05 08:44:59
*/
......@@ -71,8 +71,11 @@ class ElementFormController extends GoGoController
if ($request->get('logout')) $session->remove('userEmail');
$userType = "anonymous";
$isEditingWithHash = $element->getRandomHash() == $request->get('hash');
// is user not allowed, we show the contributor-login page
if (!$configService->isUserAllowed($addEditName, $request, $session->get('userEmail')) && $element->getRandomHash() != $request->get('hash'))
if (!$configService->isUserAllowed($addEditName, $request, $session->get('userEmail')) && !$isEditingWithHash)
{
// creating simple form to let user enter a email address
$loginform = $this->get('form.factory')->createNamedBuilder('user', 'form')
......@@ -88,6 +91,7 @@ class ElementFormController extends GoGoController
if ($loginform->handleRequest($request)->isValid() && !$emailAlreadyUsed)
{
$session->set('userEmail', $userEmail);
$userType = "email";
}
else
{
......@@ -102,22 +106,26 @@ class ElementFormController extends GoGoController
{
if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'))
{
$userType = "loggued";
$user = $this->get('security.context')->getToken()->getUser();
$userRoles = $user->getRoles();
$userEmail = $user->getEmail();
}
else if ($session->has('userEmail'))
{
$userType = "email";
$user = $session->get('userEmail');
$userEmail = $session->get('userEmail');
}
else if ($element->getRandomHash() == $request->get('hash'))
else if ($isEditingWithHash)
{
$userType = "hash";
$user = 'Anonymous with Hash';
$userEmail = 'Anonymous with Hash';
}
else
{
$userType = "anonymous";
$user = 'Anonymous';
$userEmail = 'Anonymous';
}
......@@ -126,12 +134,13 @@ class ElementFormController extends GoGoController
// We need to detect if the owner contribution has been validated. Because after that, the owner have direct moderation on the element
// To check that, we check is element is Valid or element is pending but from a contribution not made by the owner
$isUserOwnerOfValidElement = $editMode && ($element->isValid() || $element->isPending() && $element->getCurrContribution()->getUserEmail() != $userEmail)
&& $element->getUserOwnerEmail() && $element->getUserOwnerEmail() == $userEmail;
&& $element->getUserOwnerEmail() && $element->getUserOwnerEmail() == $userEmail;
$isAllowedDirectModeration = $configService->isUserAllowed('directModeration')
|| (!$editMode && in_array('ROLE_DIRECTMODERATION_ADD', $userRoles))
|| ($editMode && in_array('ROLE_DIRECTMODERATION_EDIT_OWN_CONTRIB', $userRoles) && $element->hasValidContributionMadeBy($userEmail))
|| $isUserOwnerOfValidElement;
|| $isUserOwnerOfValidElement
|| $isEditingWithHash;
$editingOwnPendingContrib = $element->isPending() && $element->getCurrContribution() && $element->getCurrContribution()->getUserEmail() == $userEmail;
......@@ -229,10 +238,11 @@ class ElementFormController extends GoGoController
$elementActionService = $this->container->get('biopen.element_action_service');
$message = $request->get('admin-message');
dump($isAllowedDirectModeration);
if ($isAllowedDirectModeration)
{
if (!$editMode) $elementActionService->add($element, $sendMail, $message);
else $elementActionService->edit($element, $sendMail, $message, $isUserOwnerOfValidElement);
else $elementActionService->edit($element, $sendMail, $message, $isUserOwnerOfValidElement, $isEditingWithHash);
}
else // non direct moderation
{
......@@ -302,9 +312,10 @@ class ElementFormController extends GoGoController
'mainCategory'=> $mainCategory,
"element" => $element,
"userEmail" => $userEmail,
"userType" => $userType,
"isAllowedDirectModeration" => $isAllowedDirectModeration,
"isAnonymousWithEmail" => $session->has('userEmail'),
"config" => $configService->getConfig()
"config" => $configService->getConfig(),
));
}
......
......@@ -7,7 +7,7 @@
*
* @copyright Copyright (c) 2016 Sebastian Castro - 90scastro@gmail.com
* @license MIT License
* @Last Modified time: 2018-03-05 12:37:19
* @Last Modified time: 2018-04-05 08:53:05
*/
namespace Biopen\GeoDirectoryBundle\Document;
......@@ -29,7 +29,8 @@ abstract class ElementStatus
const CollaborativeValidate = 2;
const AddedByAdmin = 3;
const ModifiedByAdmin = 4;
const ModifiedByOwner = 5;
const ModifiedByOwner = 5;
const ModifiedFromHash = 6;
}
abstract class ModerationState
......
......@@ -21,7 +21,8 @@ abstract class UserRoles
const Anonymous = 0;
const AnonymousWithEmail = 1;
const Loggued = 2;
const Admin = 3;
const Admin = 3;
const AnonymousWithHash = 4;
}
/** @MongoDB\Document */
......@@ -118,7 +119,7 @@ class UserInteraction
return $this->getUserRole() == UserRoles::Admin;
}
public function updateUserInformation($securityContext, $email = null)
public function updateUserInformation($securityContext, $email = null, $directModerationWithHash = false)
{
if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'))
{
......@@ -133,14 +134,13 @@ class UserInteraction
$this->setUserEmail($email);
$this->setUserRole(UserRoles::AnonymousWithEmail);
}
else
{
$this->setUserRole(UserRoles::Anonymous);
}
else $this->setUserRole(UserRoles::Anonymous);
if ($directModerationWithHash) $this->setUserRole(UserRoles::AnonymousWithHash);
}
}
public function updateResolvedBy($securityContext, $email = null)
public function updateResolvedBy($securityContext, $email = null, $directModerationWithHash = false)
{
if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'))
{
......@@ -149,14 +149,9 @@ class UserInteraction
}
else
{
if ($email)
{
$this->setResolvedBy($email);
}
else
{
$this->setResolvedBy('Anonymous');
}
if ($email) $this->setResolvedBy($email);
else if ($directModerationWithHash) $this->setResolvedBy('Anonymous with hash');
else $this->setResolvedBy('Anonymous');
}
}
......
......@@ -22,7 +22,8 @@
{% include "@BiopenGeoDirectory/element-form/form-partials/user-validation.html.twig" %}
{% endif %}
<div class="col s12 checkbox-container" {{ config.elementFormOwningText ? '' : 'style="display:none"'}}>
{% set showOwnerCheckbox = config.elementFormOwningText and (userType == "loggued" or userType == "email") %}
<div class="col s12 checkbox-container" {{ showOwnerCheckbox ? '' : 'style="display:none"'}}>
<input type="checkbox" name="owning" id="owning" {{ userEmail == element.userOwnerEmail ? 'checked' : '' }} />
<label id="label-owning" for="owning">{{ config.elementFormOwningText | raw }}</label>
</div>
......
......@@ -7,7 +7,7 @@
*
* @copyright Copyright (c) 2016 Sebastian Castro - 90scastro@gmail.com
* @license MIT License
* @Last Modified time: 2018-02-11 13:06:48
* @Last Modified time: 2018-04-05 08:53:44
*/
......@@ -63,10 +63,11 @@ class ElementActionService
$element->updateTimestamp();
}
public function edit($element, $sendMail = true, $message = null, $modifiedByOwner = false)
public function edit($element, $sendMail = true, $message = null, $modifiedByOwner = false, $directModerationWithHash = false)
{
$status = $modifiedByOwner ? ElementStatus::ModifiedByOwner : ElementStatus::ModifiedByAdmin;
$this->addContribution($element, $message, InteractType::Edit, $status);
$status = $directModerationWithHash ? ElementStatus::ModifiedFromHash : $status;
$this->addContribution($element, $message, InteractType::Edit, $status, $directModerationWithHash);
$element->setStatus($status);
if (!$modifiedByOwner) $this->resolveReports($element, $message);
if($sendMail) $this->mailService->sendAutomatedMail('edit', $element, $message);
......@@ -123,13 +124,12 @@ class ElementActionService
$element->updateTimestamp();
}
private function addContribution($element, $message, $InteractType, $status)
private function addContribution($element, $message, $InteractType, $status, $directModerationWithHash = false)
{
$contribution = new UserInteractionContribution();
$contribution->updateUserInformation($this->securityContext);
$contribution->updateUserInformation($this->securityContext, null, $directModerationWithHash);
$contribution->setResolvedMessage($message);
$contribution->updateResolvedBy($this->securityContext);
$contribution->setType($InteractType);
$contribution->updateResolvedBy($this->securityContext, null, $directModerationWithHash);
$contribution->setType($InteractType);
$contribution->setStatus($status);
$element->addContribution($contribution);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment