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

Handling title-changing amendments when merging only one amendment #837

Merged
merged 2 commits into from
Sep 19, 2023
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
6 changes: 2 additions & 4 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
- The motion list can now be filtered for To Do items (that is, motions/amendments that need to be screened) and also shows the To Do action for items on that list as part of the Status.
- The motion list now persists its filter and sort settings for each user session, until changed or reset.
- If an amendment is set to show the full text by default, this now also affects the PDF export.
- Merging a single amendment into a motion now also handles amendments only changing the title of the motion.
- The maintenance mode page is now specific to a consultation; that is, delegates bookmarking a link to a consultation that is still in maintenance mode can open that bookmark later and get to theat very consultation, not the generic home page.
- Bugfix: If a draft of a revised motion (by merging amendments) existed and the motion list was opened, the original motion was not shown anymore by default.
- Bugfix: Some edge cases around uploaded logos breaking the PDF export or not being shown on the page were resolved.
- Bugfix: Super-admins could lock themselves out of protected consultations.
- Bugfix: Putting a active speaker back into the speaking waiting list did not work - the speaker vanished from the list completely.
- Bugfix: Closing the full screen mode of a speaking list was leading to an error page.

### Version 4.12.1 [not released yet]

- The maintenance mode page is now specific to a consultation; that is, delegates bookmarking a link to a consultation that is still in maintenance mode can open that bookmark later and get to theat very consultation, not the generic home page.
- Bugfix: If not-logged-in users are allowed to support motions/amendments, they showed up as empty bullet points in the supporter list. Now they have to enter their name.
- Bugfix: The delete button in the admin motion list was shown even if no delete permissions were granted and it was therefore non-functional.
- Bugfix: If a motion collecting supporters was edited by an admin, then no publication mail was sent later when it was actually published.
Expand Down
2 changes: 1 addition & 1 deletion controllers/AmendmentMergingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function actionMerge(string $motionSlug, int $amendmentId): ResponseInter
$this->getPostValue('motionTitlePrefix'),
$this->getPostValue('motionVersion'),
$this->getPostValue('amendmentStatus'),
$this->getPostValue('newParas'),
$this->getPostValue('newParas', []),
$this->getPostValue('amendmentOverride', []),
$newAmendmentStatuses
);
Expand Down
17 changes: 13 additions & 4 deletions controllers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace app\controllers;

use app\models\exceptions\{ApiResponseException, NotFound, Internal, ResponseException};
use app\models\http\{HtmlResponse, ResponseInterface, RestApiExceptionResponse, RestApiResponse};
use app\models\http\{HtmlResponse, RedirectResponse, ResponseInterface, RestApiExceptionResponse, RestApiResponse};
use app\components\{ConsultationAccessPassword, HTMLTools, RequestContext, UrlHelper};
use app\models\settings\{AntragsgruenApp, Layout, Privileges};
use app\models\db\{Amendment, Consultation, Motion, Site, User};
Expand Down Expand Up @@ -490,6 +490,10 @@ protected function consultationNotFound(): void
$this->showErrorpage(404, $message);
}

/**
* @throws ResponseException
* @throws Internal
*/
protected function checkConsistency(?Motion $checkMotion = null, ?Amendment $checkAmendment = null, bool $throwExceptions = false): void
{
$consultationPath = strtolower($this->consultation->urlPath);
Expand All @@ -500,23 +504,28 @@ protected function checkConsistency(?Motion $checkMotion = null, ?Amendment $che
throw new Internal(Yii::t('base', 'err_cons_not_site'), 400);
}
$this->getHttpSession()->setFlash("error", Yii::t('base', 'err_cons_not_site'));
$this->redirect(UrlHelper::createUrl('/consultation/index'));
throw new ResponseException(new RedirectResponse(UrlHelper::homeUrl()));
}

if (is_object($checkMotion) && strtolower($checkMotion->getMyConsultation()->urlPath) !== $consultationPath) {
if ($throwExceptions) {
throw new Internal(Yii::t('motion', 'err_not_found'), 404);
}
$this->getHttpSession()->setFlash('error', Yii::t('motion', 'err_not_found'));
$this->redirect(UrlHelper::createUrl('/consultation/index'));
throw new ResponseException(new RedirectResponse(UrlHelper::homeUrl()));
}

if ($checkAmendment !== null && ($checkMotion === null || $checkAmendment->motionId !== $checkMotion->id)) {
if ($throwExceptions) {
throw new Internal(Yii::t('base', 'err_amend_not_consult'), 400);
}
$this->getHttpSession()->setFlash('error', Yii::t('base', 'err_amend_not_consult'));
$this->redirect(UrlHelper::createUrl('/consultation/index'));
throw new ResponseException(new RedirectResponse(UrlHelper::homeUrl()));
}

if ($checkAmendment !== null && ($checkAmendment->amendingAmendmentId && !$checkAmendment->amendedAmendment)) {
$this->getHttpSession()->setFlash('error', Yii::t('base', 'err_amend_no_parent'));
throw new ResponseException(new RedirectResponse(UrlHelper::homeUrl()));
}
}

Expand Down
1 change: 1 addition & 0 deletions messages/de/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'err_max_len_exceed' => 'Maximum length of %MAX% exceeded',
'err_no_site_internal' => 'Keine Seite angegeben. Das dürfte ein Fehler bei der Installation sein.',
'err_amend_not_consult' => 'Der Änderungsantrag gehört nicht zum Antrag.',
'err_amend_no_parent' => 'Der Basis-Änderungsantrag dieses ÄAs wurde gelöscht.',
'err_cons_not_site' => 'Fehlerhafte Parameter - die Veranstaltung gehört nicht zur Veranstaltungsreihe.',
'err_site_403' => 'Kein Zugriff auf diese Seite.',
'err_site_410' => 'Dieser Inhalt wurde gelöscht.',
Expand Down
1 change: 1 addition & 0 deletions messages/en/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'err_max_len_exceed' => 'Maximum length of %MAX% exceeded',
'err_no_site_internal' => 'No site given. This is probably an installation error.',
'err_amend_not_consult' => 'Invalid URL: this amendment does not belong to the given motion.',
'err_amend_no_parent' => 'The parent amendment for this amendment was deleted.',
'err_cons_not_site' => 'Invalid URL: this consultation is not part of the given site.',
'err_site_403' => 'No access',
'err_site_410' => 'This content has been deleted.',
Expand Down
44 changes: 22 additions & 22 deletions models/forms/MergeSingleAmendmentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,18 @@ class MergeSingleAmendmentForm
{
public Motion $oldMotion;
public ?Motion $newMotion = null;
public string $newTitlePrefix;
public string $newVersion;
public Amendment $mergeAmendment;
public int $mergeAmendStatus;
public array $otherAmendStatuses;
public array $otherAmendOverrides;
public array $paragraphs;

public function __construct(
Amendment $amendment,
string $newTitlePrefix,
string $newVersion,
int $newStatus,
array $paragraphs,
array $otherAmendOverrides,
array $otherAmendStatuses
public Amendment $mergeAmendment,
public string $newTitlePrefix,
public string $newVersion,
public int $mergeAmendStatus,
public array $paragraphs,
public array $otherAmendOverrides,
public array $otherAmendStatuses
)
{
$this->newTitlePrefix = $newTitlePrefix;
$this->newVersion = $newVersion;
$this->oldMotion = $amendment->getMyMotion();
$this->mergeAmendment = $amendment;
$this->mergeAmendStatus = $newStatus;
$this->paragraphs = $paragraphs;
$this->otherAmendStatuses = $otherAmendStatuses;
$this->otherAmendOverrides = $otherAmendOverrides;
$this->oldMotion = $mergeAmendment->getMyMotion();
}

private function getNewHtmlParas(): array
Expand Down Expand Up @@ -141,6 +127,9 @@ private function createNewMotionSections(): void
$newSection->dataRaw = '';
}
}
if ($section->getSettings()->type === ISectionType::TYPE_TITLE && $this->mergeAmendment->getSection($section->sectionId)) {
$newSection->setData($this->mergeAmendment->getSection($section->sectionId)->getData());
}
if (!$newSection->save()) {
throw new DB($newSection->getErrors());
}
Expand Down Expand Up @@ -175,6 +164,15 @@ private function rewriteOtherAmendments(): void
throw new DB($section->getErrors());
}
}
foreach ($amendment->getActiveSections(ISectionType::TYPE_TITLE) as $section) {
foreach ($this->oldMotion->sections as $motionSection) {
if ($motionSection->sectionId === $section->sectionId && $motionSection->getData() === $section->getData() && $this->mergeAmendment->getSection($section->sectionId)) {
// Change the title of amendments that didn't try to change the title of the motion
$section->setData($this->mergeAmendment->getSection($section->sectionId)->getData());
$section->save();
}
}
}
$amendment->motionId = $this->newMotion->id;
$amendment->cache = '';
$amendment->status = $this->otherAmendStatuses[$amendment->id];
Expand Down Expand Up @@ -232,6 +230,8 @@ public function performRewrite(): Motion
$consultation->save();
}

$this->newMotion->refreshTitle();
$this->newMotion->save();
$this->newMotion->trigger(Motion::EVENT_MERGED, new MotionEvent($this->newMotion));

return $this->newMotion;
Expand Down