PHRAS-3399 fix feedback right issue

This commit is contained in:
aynsix
2021-03-18 17:09:14 +03:00
parent a350d49990
commit c8465d5a53
2 changed files with 26 additions and 11 deletions

View File

@@ -302,9 +302,12 @@ class PushController extends Controller
// we always add the author of the validation request (current user) to the participants // we always add the author of the validation request (current user) to the participants
// //
$found = false; $found = false;
foreach ($participants as $participant) { foreach ($participants as $key => $participant) {
if ($participant['usr_id'] === $this->getAuthenticatedUser()->getId()) { if ($Validation->isInitiator($this->getAuthenticatedUser()) && $participant['usr_id'] == $this->getAuthenticatedUser()->getId()) {
// the initiator always can see others
$participants[$key]['see_others'] = 1;
$found = true; $found = true;
break; break;
} }
} }
@@ -353,9 +356,14 @@ class PushController extends Controller
} }
// end of sanity check // end of sanity check
// if participant already exists, skip insertion // if participant already exists, just update right
try { try {
$Validation->getParticipant($participantUser); $validationParticipant = $Validation->getParticipant($participantUser);
$validationParticipant->setCanAgree($participant['agree']);
$validationParticipant->setCanSeeOthers($participant['see_others']);
$manager->persist($validationParticipant);
$manager->flush();
continue; continue;
} }
catch (NotFoundHttpException $e) { catch (NotFoundHttpException $e) {
@@ -460,10 +468,17 @@ class PushController extends Controller
$this->app->trans('Unknown user %usr_id%', ['%usr_id%' => $userIdToRemove]) $this->app->trans('Unknown user %usr_id%', ['%usr_id%' => $userIdToRemove])
); );
} }
$validationParticipant = $Validation->getParticipant($participantUser); $validationParticipant = $Validation->getParticipant($participantUser);
$Validation->removeParticipant($validationParticipant);
$manager->remove($validationParticipant); // if initiator is removed from the user selection,
// do not remove it to the participant list, just set can_agree to false for it
if ($Validation->isInitiator($participantUser)) {
$validationParticipant->setCanAgree(false);
$manager->persist($validationParticipant);
} else {
$Validation->removeParticipant($validationParticipant);
$manager->remove($validationParticipant);
}
} }
} }

View File

@@ -273,19 +273,19 @@
</td> </td>
</tr> </tr>
<tr class="toggles"> <tr class="toggles">
<td class="toggle status_on toggle_agree"> <td class="toggle toggle_agree {{ participant.getCanAgree() ? 'status_on' : 'status_off' }} ">
<img title="{% trans %}User contribute to the feedback{% endtrans %}" class="toggle_off" <img title="{% trans %}User contribute to the feedback{% endtrans %}" class="toggle_off"
src="/assets/common/images/icons/grey-pen.png"/> src="/assets/common/images/icons/grey-pen.png"/>
<img title="{% trans %}User contribute to the feedback{% endtrans %}" class="toggle_on" <img title="{% trans %}User contribute to the feedback{% endtrans %}" class="toggle_on"
src="/assets/common/images/icons/dark-green-pen.png"/> src="/assets/common/images/icons/dark-green-pen.png"/>
<input type="hidden" name="participants[{{ userId }}][agree]" value="1" /> <input type="hidden" name="participants[{{ userId }}][agree]" value="{{ participant.getCanAgree() ? '1' : '0' }}" />
</td> </td>
<td class="toggle status_off toggle_see_others" style="text-align: center;"> <td class="toggle {{ participant.getCanSeeOthers() ? 'status_on' : 'status_off' }} toggle_see_others" style="text-align: center;">
<img title="{% trans %}User can see others choices{% endtrans %}" class="toggle_off" <img title="{% trans %}User can see others choices{% endtrans %}" class="toggle_off"
src="/assets/common/images/icons/grey-user.png"/> src="/assets/common/images/icons/grey-user.png"/>
<img title="{% trans %}User can see others choices{% endtrans %}" class="toggle_on" <img title="{% trans %}User can see others choices{% endtrans %}" class="toggle_on"
src="/assets/common/images/icons/dark-green-user.png"/> src="/assets/common/images/icons/dark-green-user.png"/>
<input type="hidden" name="participants[{{ userId }}][see_others]" value="0" /> <input type="hidden" name="participants[{{ userId }}][see_others]" value="{{ participant.getCanSeeOthers() ? '1' : '0' }}" />
</td> </td>
<td class="toggle status_off toggle_HD" style="text-align: right;"> <td class="toggle status_off toggle_HD" style="text-align: right;">
<img title="{% trans %}User can download HD{% endtrans %}" class="toggle_off" <img title="{% trans %}User can download HD{% endtrans %}" class="toggle_off"