aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2024-12-11 14:58:36 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2024-12-11 14:58:36 +0000
commitc14cdd1a892fe19b9035feba01273ef5015cb64b (patch)
tree5c6e961de7e0b124e408957fa28aa633860aa511
parent44b518ce738a282fd0efa30e40e17f53b104e424 (diff)
Resolve "Wiki: Exception taucht auf, wenn ich mit autor-Berechtigungen eine nicht existierende Seite aufrufe"
Closes #4991 Merge request studip/studip!3750
-rw-r--r--app/controllers/course/wiki.php8
-rw-r--r--lib/classes/RangeFactory.php22
-rw-r--r--lib/models/WikiPage.php9
3 files changed, 30 insertions, 9 deletions
diff --git a/app/controllers/course/wiki.php b/app/controllers/course/wiki.php
index ddda49a..6fbd7ce 100644
--- a/app/controllers/course/wiki.php
+++ b/app/controllers/course/wiki.php
@@ -1338,6 +1338,8 @@ class Course_WikiController extends AuthenticatedController
private function validateWikiPage(WikiPage $page, Range $context, bool $for_edit = false): void
{
+ $page->range_id = $page->range_id ?: $context->id;
+
if (
!$page->isNew()
&& $page->range_id !== $context->id
@@ -1349,7 +1351,11 @@ class Course_WikiController extends AuthenticatedController
}
if ($for_edit && !$page->isEditable()) {
- throw new Exception(_('Sie dürfen diese Wikiseite nicht bearbeiten'));
+ if ($page->isNew()) {
+ throw new AccessDeniedException(_('Sie dürfen keine neue Wikiseite anlegen.'));
+ } else {
+ throw new AccessDeniedException(_('Sie dürfen diese Wikiseite nicht bearbeiten'));
+ }
}
}
}
diff --git a/lib/classes/RangeFactory.php b/lib/classes/RangeFactory.php
index 8da592a..f70e25a 100644
--- a/lib/classes/RangeFactory.php
+++ b/lib/classes/RangeFactory.php
@@ -8,16 +8,24 @@
*/
final class RangeFactory
{
- const TYPE_MAPPING = [
+ public const TYPE_MAPPING = [
'sem' => 'course',
'user' => 'user',
'inst' => 'institute',
'fak' => 'institute',
];
- public static function find($id)
- {
- $type = get_object_type($id, ['sem', 'user', 'inst', 'fak']);
+ /**
+ * Finds a Range for a given id or false if there is no Range with the id.
+ * @param string $id Range id
+ * @param array $search_types array can have values of 'sem', 'user', 'inst' and/or 'fak'
+ * @return Range|false
+ */
+ public static function find(
+ string $id,
+ array $search_types = ['sem', 'user', 'inst', 'fak']
+ ) {
+ $type = get_object_type($id, $search_types);
if ($type === false) {
return false;
}
@@ -30,12 +38,10 @@ final class RangeFactory
*
* @param string $type Range type
* @param mixed $id Range id
- * @return mixed any of the supported range types
+ * @return Range any of the supported range types
* @throws Exception when an invalid range type was given
- *
- * @todo Should this be more dynamic in case any more ranges are added?
*/
- public static function createRange($type, $id)
+ public static function createRange(string $type, string $id): Range
{
if ($type === 'user') {
return new User($id);
diff --git a/lib/models/WikiPage.php b/lib/models/WikiPage.php
index 6cb4c8a..57b9c89 100644
--- a/lib/models/WikiPage.php
+++ b/lib/models/WikiPage.php
@@ -191,6 +191,15 @@ class WikiPage extends SimpleORMap implements PrivacyObject
return false;
}
+ // Check create permission if page is new
+ if ($this->isNew()) {
+ $range = RangeFactory::find($this->range_id, ['sem', 'inst']);
+ $permission = $range->getConfiguration()->getValue('WIKI_CREATE_PERMISSION');
+ return $permission === 'all'
+ || $GLOBALS['perm']->have_studip_perm($permission, $this->range_id, $user_id);
+ }
+
+ // Otherwise check write permissions
if ($this->write_permission === 'all') {
return true;
}