Skip to content

Commit

Permalink
Allow to set policy for content pages
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Oct 27, 2024
1 parent 8509565 commit 30853a4
Show file tree
Hide file tree
Showing 60 changed files with 199 additions and 109 deletions.
14 changes: 13 additions & 1 deletion controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace app\controllers;

use app\models\policies\{IPolicy, UserGroups};
use app\models\settings\{Layout, Privileges, AntragsgruenApp};
use app\models\http\{BinaryFileResponse, HtmlErrorResponse, HtmlResponse, JsonResponse, RedirectResponse, ResponseInterface, RestApiResponse};
use app\components\{HTMLTools, Tools, UrlHelper, ZipWriter};
use app\models\db\{ConsultationFile, ConsultationFileGroup, ConsultationText, User};
use app\models\db\{ConsultationFile, ConsultationFileGroup, ConsultationText, ConsultationUserGroup, User};
use app\models\exceptions\{Access, FormError, ResponseException};
use yii\web\{NotFoundHttpException, Response};

Expand Down Expand Up @@ -183,6 +184,17 @@ public function actionSavePage(string $pageSlug): JsonResponse
$page->consultationId = $this->consultation->id;
}
}

if ($this->getHttpRequest()->post('policyReadPage')) {
$data = $this->getHttpRequest()->post('policyReadPage');
$policy = IPolicy::getInstanceFromDb($data['id'], $this->consultation, $page);
if (is_a($policy, UserGroups::class)) {
$groups = ConsultationUserGroup::loadGroupsByIdForConsultation($this->consultation, $data['groups'] ?? []);
$policy->setAllowedUserGroups($groups);
}
$page->setReadPolicy($policy);
}

$newTextId = $this->getHttpRequest()->post('url');
if ($newTextId && !preg_match('/[^\w_\-,.äöüß]/siu', $newTextId) && $page->textId !== $newTextId) {
$page->textId = $newTextId;
Expand Down
12 changes: 11 additions & 1 deletion models/db/ConsultationText.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ public function isCustomPage(): bool

public function getReadPolicy(): IPolicy
{
return IPolicy::getInstanceFromDb($this->policyRead, $this->getMyConsultation(), $this);
if ($this->policyRead === null) {
$policy = (string)IPolicy::POLICY_ALL;
} else {
$policy = $this->policyRead;
}
return IPolicy::getInstanceFromDb($policy, $this->getMyConsultation(), $this);
}

public function setReadPolicy(IPolicy $policy): void
{
$this->policyRead = $policy->serializeInstanceForDb();
}

public function getUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion plugins/green_layout/assets/layout-green_layout.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/green_layout/assets/layout-green_layout.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci1.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci1.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci2.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci2.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci3.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/gruen_ci/assets/layout-gruen_ci3.css.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions views/admin/motion-type/_initiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
$policies,
['id' => 'typeInitiatorPersonPolicy', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeInitiatorPersonGroups', 'formName' => 'initiatorPersonPolicy', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeInitiatorPersonGroups', 'formName' => 'type[initiatorPersonPolicy]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand All @@ -110,7 +110,7 @@
$policies,
['id' => 'typeInitiatorOrgaPolicy', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeInitiatorOrgaGroups', 'formName' => 'initiatorOrgaPolicy', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeInitiatorOrgaGroups', 'formName' => 'type[initiatorOrgaPolicy]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down Expand Up @@ -393,7 +393,7 @@
$policies,
['id' => 'typeAmendmentInitiatorPersonPolicy', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeAmendmentInitiatorPersonGroups', 'formName' => 'amendmentInitiatorPersonPolicy', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeAmendmentInitiatorPersonGroups', 'formName' => 'type[amendmentInitiatorPersonPolicy]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand All @@ -411,7 +411,7 @@
$policies,
['id' => 'typeAmendmentInitiatorOrgaPolicy', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeAmendmentInitiatorOrgaGroups', 'formName' => 'amendmentInitiatorOrgaPolicy', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typeAmendmentInitiatorOrgaGroups', 'formName' => 'type[amendmentInitiatorOrgaPolicy]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions views/admin/motion-type/_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
$policies,
['id' => 'typePolicyMotions', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyMotionsGroups', 'formName' => 'policyMotions', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyMotionsGroups', 'formName' => 'type[policyMotions]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand All @@ -57,7 +57,7 @@
$policies,
['id' => 'typePolicySupportMotions', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicySupportMotionsGroups', 'formName' => 'policySupportMotions', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicySupportMotionsGroups', 'formName' => 'type[policySupportMotions]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down Expand Up @@ -115,7 +115,7 @@
$policies,
['id' => 'typePolicyAmendments', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyAmendmentsGroups', 'formName' => 'policyAmendments', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyAmendmentsGroups', 'formName' => 'type[policyAmendments]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down Expand Up @@ -170,7 +170,7 @@
$policies,
['id' => 'typePolicySupportAmendments', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicySupportAmendmentsGroups', 'formName' => 'policySupportAmendments', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicySupportAmendmentsGroups', 'formName' => 'type[policySupportAmendments]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down Expand Up @@ -229,7 +229,7 @@
$policies,
['id' => 'typePolicyComments', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyCommentsGroups', 'formName' => 'policyComments', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'typePolicyCommentsGroups', 'formName' => 'type[policyComments]', 'consultation' => $motionType->getConsultation(), 'currentPolicy' => $currentPolicy]);
?>
</div>
</div>
Expand Down
34 changes: 22 additions & 12 deletions views/pages/contentpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

if ($admin) {
$layout->loadCKEditor();
$layout->loadSelectize();

echo Html::beginForm($saveUrl, 'post', [
'class' => 'contentEditForm',
Expand Down Expand Up @@ -92,19 +93,28 @@
</div>
</section>

<section class="policyToolbarBelowTitle hidden policyWidget">
<label class="title" for="policyReadPage">
Lesezugriff:
</label>
<div class="policySelectHolder">
<?php
$policies = [];
foreach (IPolicy::getPolicies() as $policy) {
$policies[$policy::getPolicyID()] = $policy::getPolicyName();
}
$currentPolicy = $pageData->getReadPolicy();
echo Html::dropDownList(
'policyReadPage[id]',
$currentPolicy::getPolicyID(),
$policies,
['id' => 'policyReadPage', 'class' => 'stdDropdown policySelect']
);
?>
</div>
<?= $this->render('@app/views/shared/usergroup_selector', ['id' => 'policyReadPageGroups', 'formName' => 'policyReadPage', 'consultation' => $consultation, 'currentPolicy' => $currentPolicy]) ?>
</section>
<?php
$policies = [];
foreach (IPolicy::getPolicies() as $policy) {
$policies[$policy::getPolicyID()] = $policy::getPolicyName();
}
$currentPolicy = $pageData->getReadPolicy();
echo Html::dropDownList(
'policyReadPageId',
$currentPolicy::getPolicyID(),
$policies,
['id' => 'policyReadPage', 'class' => 'stdDropdown policySelect']
);
echo $this->render('@app/views/shared/usergroup_selector', ['id' => 'policyReadPageGroups', 'formName' => 'policyReadPage', 'consultation' => $consultation, 'currentPolicy' => $currentPolicy]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion views/shared/usergroup_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
?>
<div class="userGroupSelect" data-load-url="<?= Html::encode($groupLoadUrl) ?>">
<select id="<?= $id ?>" name="type[<?= $formName ?>][groups][]" multiple
<select id="<?= $id ?>" name="<?= $formName ?>[groups][]" multiple
placeholder="<?= Yii::t('admin', 'motion_type_group_ph') ?>" title="<?= Yii::t('admin', 'motion_type_group_title') ?>">
<?php
foreach ($consultation->getAllAvailableUserGroups($preselectedUserGroupsIds) as $group) {
Expand Down
22 changes: 22 additions & 0 deletions web/css/_contentpage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
}
}
}
.policyToolbarBelowTitle {
border-bottom: solid 1px #aaa;
padding: 7px 19px;
background: #f7f7f7;
display: flex;
flex-direction: row;
> .title {
flex-basis: 15%;
padding-top: 7px;
}
> .policySelectHolder {
flex-basis: 35%;
width: auto;
padding-right: 10px;
.stdDropdown {
padding-bottom: 10px;
}
}
#policyReadPageGroups {
flex-basis: 50%;
}
}

.deadlineCircle {
float: right;
Expand Down
2 changes: 1 addition & 1 deletion web/css/layout-classic.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-classic.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-dbjr.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/css/layout-dbjr.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/js/build/backend/AdminIndex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/js/build/backend/AdminIndex.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 30853a4

Please sign in to comment.