Skip to content
Snippets Groups Projects
Commit b2635ede authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

fix access to institute administration, fixes #4458

Closes #4458

Merge request studip/studip!3243
parent ad22a665
No related branches found
No related tags found
No related merge requests found
...@@ -101,13 +101,12 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -101,13 +101,12 @@ class Course_ContentmodulesController extends AuthenticatedController
public function trigger_action() public function trigger_action()
{ {
$context = Context::get(); $context = Context::get();
if (!$context->isEditableByUser()) {
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
if (Request::isPost()) { if (Request::isPost()) {
if ($context->getRangeType() === 'course') { if ($context instanceof Course) {
$sem_class = $context->getSemClass(); $sem_class = $context->getSemClass();
} else { } else {
$sem_class = SemClass::getDefaultInstituteClass($context->type); $sem_class = SemClass::getDefaultInstituteClass($context->type);
...@@ -129,6 +128,7 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -129,6 +128,7 @@ class Course_ContentmodulesController extends AuthenticatedController
$this->redirect("course/contentmodules/trigger", ['cid' => $context->getId(), 'plugin_id' => $module->getPluginId()]); $this->redirect("course/contentmodules/trigger", ['cid' => $context->getId(), 'plugin_id' => $module->getPluginId()]);
return; return;
} }
$active_tool = ToolActivation::find([$context->id, Request::int('plugin_id')]); $active_tool = ToolActivation::find([$context->id, Request::int('plugin_id')]);
$template = $GLOBALS['template_factory']->open('tabs.php'); $template = $GLOBALS['template_factory']->open('tabs.php');
$template->navigation = Navigation::getItem('/course'); $template->navigation = Navigation::getItem('/course');
...@@ -142,11 +142,10 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -142,11 +142,10 @@ class Course_ContentmodulesController extends AuthenticatedController
public function reorder_action() public function reorder_action()
{ {
$context = Context::get(); $context = Context::get();
if (!$context->isEditableByUser()) {
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
if (Request::isPost()) { if (Request::isPost()) {
$position = 0; $position = 0;
foreach (Request::getArray('order') as $plugin_id) { foreach (Request::getArray('order') as $plugin_id) {
...@@ -157,6 +156,7 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -157,6 +156,7 @@ class Course_ContentmodulesController extends AuthenticatedController
$this->redirect($this->reorderURL()); $this->redirect($this->reorderURL());
return; return;
} }
Navigation::getItem('/course/admin')->setActive(true); Navigation::getItem('/course/admin')->setActive(true);
$template = $GLOBALS['template_factory']->open('tabs.php'); $template = $GLOBALS['template_factory']->open('tabs.php');
$template->navigation = Navigation::getItem('/course'); $template->navigation = Navigation::getItem('/course');
...@@ -170,12 +170,12 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -170,12 +170,12 @@ class Course_ContentmodulesController extends AuthenticatedController
if (!Request::isPost()) { if (!Request::isPost()) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
$context = Context::get();
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin'; $context = Context::get();
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) { if (!$context->isEditableByUser()) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
$moduleclass = Request::get('moduleclass'); $moduleclass = Request::get('moduleclass');
$module = new $moduleclass; $module = new $moduleclass;
...@@ -208,15 +208,15 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -208,15 +208,15 @@ class Course_ContentmodulesController extends AuthenticatedController
public function rename_action($module_id) public function rename_action($module_id)
{ {
$context = Context::get(); $context = Context::get();
if (!$context->isEditableByUser()) {
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
$this->module = PluginManager::getInstance()->getPluginById($module_id); $this->module = PluginManager::getInstance()->getPluginById($module_id);
$this->metadata = $this->module->getMetadata(); $this->metadata = $this->module->getMetadata();
PageLayout::setTitle(_('Werkzeug umbenennen')); PageLayout::setTitle(_('Werkzeug umbenennen'));
$this->tool = ToolActivation::find([$context->id, $module_id]); $this->tool = ToolActivation::find([$context->id, $module_id]);
if (Request::isPost()) { if (Request::isPost()) {
$metadata = $this->tool->metadata->getArrayCopy(); $metadata = $this->tool->metadata->getArrayCopy();
if (!trim(Request::get('displayname')) || Request::submitted('delete')) { if (!trim(Request::get('displayname')) || Request::submitted('delete')) {
...@@ -359,8 +359,5 @@ class Course_ContentmodulesController extends AuthenticatedController ...@@ -359,8 +359,5 @@ class Course_ContentmodulesController extends AuthenticatedController
} catch (Exception $e) { } catch (Exception $e) {
return null; return null;
} }
} }
} }
...@@ -311,10 +311,11 @@ class Institute extends SimpleORMap implements Range ...@@ -311,10 +311,11 @@ class Institute extends SimpleORMap implements Range
public function isEditableByUser($user_id = null): bool public function isEditableByUser($user_id = null): bool
{ {
if ($user_id === null) { if ($user_id === null) {
$user_id = $GLOBALS['user']->id; $user_id = User::findCurrent()->id;
} }
$member = $this->members->findOneBy('user_id', $user_id); $member = $this->members->findOneBy('user_id', $user_id);
return ($member && in_array($member->inst_perms, ['tutor', 'dozent', 'admin'])) return ($member && $member->inst_perms === 'admin')
|| User::find($user_id)->perms === 'root'; || User::find($user_id)->perms === 'root';
} }
......
...@@ -24,98 +24,111 @@ class CoreAdmin extends CorePlugin implements StudipModule ...@@ -24,98 +24,111 @@ class CoreAdmin extends CorePlugin implements StudipModule
*/ */
public function getTabNavigation($course_id) public function getTabNavigation($course_id)
{ {
if ($GLOBALS['perm']->have_studip_perm('tutor', $course_id)) { $range = RangeFactory::find($course_id);
$navigation = new Navigation(_('Verwaltung'));
$navigation->setImage(Icon::create('admin', Icon::ROLE_INFO_ALT)); // Given range is invalid, leave early
$navigation->setActiveImage(Icon::create('admin', Icon::ROLE_INFO)); if (!$range) {
return [];
$main = new Navigation(_('Werkzeuge'), 'dispatch.php/course/contentmodules'); }
$navigation->addSubNavigation('contentmodules', $main);
// Special case: Tutors of institutes may manage votes
if (!Context::isInstitute()) { if (
$item = new Navigation(_('Grunddaten'), 'dispatch.php/course/basicdata/view/' . $course_id); Config::get()->VOTE_ENABLE
$item->setImage(Icon::create('edit')); && $range instanceof Institute
$item->setDescription(_('Bearbeiten der Grundeinstellungen dieser Veranstaltung.')); && !$range->isEditableByUser()
$navigation->addSubNavigation('details', $item); && Seminar_Perm::get()->have_studip_perm('tutor', $range->id)
) {
$item = new Navigation(_('Veranstaltungsbild'), 'dispatch.php/course/avatar'); $navigation = $this->getRootNavigation();
$item->setDescription(_('Infobild dieser Veranstaltung bearbeiten oder löschen.')); $this->addVoteNavigation($navigation);
$navigation->addSubNavigation('avatar', $item);
return ['admin' => $navigation];
$item = new Navigation(_('Studienbereiche'), 'dispatch.php/course/study_areas/show/' . $course_id); }
$item->setImage(Icon::create('module'));
$item->setDescription(_('Zuordnung dieser Veranstaltung zu Studienbereichen für die Darstellung im Verzeichnis aller Veranstaltungen.')); // User may not edit this range
$navigation->addSubNavigation('study_areas', $item); if (!$range->isEditableByUser()) {
return [];
$current_course = Course::find($course_id); }
if ($current_course && $current_course->getSemClass()->offsetGet('module')) {
$item = new Navigation(_('LV-Gruppen'), 'dispatch.php/course/lvgselector/index/' . $course_id, ['list' => 'TRUE']); // Build regular admin navigation
$item->setImage(Icon::create('learnmodule')); $navigation = $this->getRootNavigation();
$item->setDescription(_('Zuordnung der Veranstaltung zu Lehrveranstaltungsgruppen um die Einordnung innerhalb des Modulverzeichnisses festzulegen.'));
$navigation->addSubNavigation('lvgruppen', $item); $main = new Navigation(_('Werkzeuge'), 'dispatch.php/course/contentmodules');
} $navigation->addSubNavigation('contentmodules', $main);
$item = new Navigation(_('Zeiten/Räume'), 'dispatch.php/course/timesrooms'); if ($range instanceof Course) {
$item->setImage(Icon::create('date')); $item = new Navigation(_('Grunddaten'), 'dispatch.php/course/basicdata/view/' . $course_id);
$item->setDescription(_('Regelmäßige Veranstaltungszeiten, Einzeltermine und Ortsangaben ändern.')); $item->setImage(Icon::create('edit'));
$navigation->addSubNavigation('dates', $item); $item->setDescription(_('Bearbeiten der Grundeinstellungen dieser Veranstaltung.'));
$navigation->addSubNavigation('details', $item);
$item = new Navigation(_('Zugangsberechtigungen'), 'dispatch.php/course/admission');
$item->setImage(Icon::create('lock-locked')); $item = new Navigation(_('Veranstaltungsbild'), 'dispatch.php/course/avatar');
$item->setDescription(_('Zugangsbeschränkungen, Anmeldeverfahren oder einen Passwortschutz für diese Veranstaltung einrichten.')); $item->setDescription(_('Infobild dieser Veranstaltung bearbeiten oder löschen.'));
$navigation->addSubNavigation('admission', $item); $navigation->addSubNavigation('avatar', $item);
$item = new AutoNavigation(_('Zusatzangaben'), 'dispatch.php/admin/additional'); $item = new Navigation(_('Studienbereiche'), 'dispatch.php/course/study_areas/show/' . $course_id);
$item->setImage(Icon::create('add')); $item->setImage(Icon::create('module'));
$item->setDescription(_('Vorlagen zur Erhebung weiterer Angaben von Teilnehmenden auswählen.')); $item->setDescription(_('Zuordnung dieser Veranstaltung zu Studienbereichen für die Darstellung im Verzeichnis aller Veranstaltungen.'));
$navigation->addSubNavigation('additional_data', $item); $navigation->addSubNavigation('study_areas', $item);
} // endif modules only seminars if ($range->getSemClass()['module']) {
$item = new Navigation(_('LV-Gruppen'), 'dispatch.php/course/lvgselector/index/' . $course_id, ['list' => 'TRUE']);
if ($GLOBALS['perm']->have_studip_perm('tutor', $course_id)) { $item->setImage(Icon::create('learnmodule'));
if (Config::get()->VOTE_ENABLE) { $item->setDescription(_('Zuordnung der Veranstaltung zu Lehrveranstaltungsgruppen um die Einordnung innerhalb des Modulverzeichnisses festzulegen.'));
$item = new Navigation(_('Fragebögen'), 'dispatch.php/questionnaire/courseoverview'); $navigation->addSubNavigation('lvgruppen', $item);
$item->setImage(Icon::create('vote'));
$item->setDescription(_('Erstellen und bearbeiten von Fragebögen.'));
$navigation->addSubNavigation('questionnaires', $item);
}
} }
$item = new Navigation(_('Zeiten/Räume'), 'dispatch.php/course/timesrooms');
$item->setImage(Icon::create('date'));
$item->setDescription(_('Regelmäßige Veranstaltungszeiten, Einzeltermine und Ortsangaben ändern.'));
$navigation->addSubNavigation('dates', $item);
$item = new Navigation(_('Zugangsberechtigungen'), 'dispatch.php/course/admission');
$item->setImage(Icon::create('lock-locked'));
$item->setDescription(_('Zugangsbeschränkungen, Anmeldeverfahren oder einen Passwortschutz für diese Veranstaltung einrichten.'));
$navigation->addSubNavigation('admission', $item);
$item = new AutoNavigation(_('Zusatzangaben'), 'dispatch.php/admin/additional');
$item->setImage(Icon::create('add'));
$item->setDescription(_('Vorlagen zur Erhebung weiterer Angaben von Teilnehmenden auswählen.'));
$navigation->addSubNavigation('additional_data', $item);
} // endif modules only seminars
if (Config::get()->VOTE_ENABLE) {
$this->addVoteNavigation($navigation);
}
/*
* Is the current SemClass available for grouping other courses?
* -> show child management
*/
if ($range instanceof Course) {
$c = $range->getSemClass();
if ($c->isGroup()) {
$item = new Navigation(_('Unterveranstaltungen'), 'dispatch.php/course/grouping/children');
$item->setImage(Icon::create('group', Icon::ROLE_INFO_ALT));
$item->setActiveImage(Icon::create('group', Icon::ROLE_INFO));
$item->setDescription(_('Ordnen Sie dieser Veranstaltung eine oder mehrere Unterveranstaltungen zu.'));
$navigation->addSubNavigation('children', $item);
/* /*
* Is the current SemClass available for grouping other courses? * Check if any SemClasses with grouping functionality exist at all
* -> show child management * -> show parent assignment.
*/ */
$course = Course::find($course_id); } else if (count(SemClass::getGroupClasses()) > 0) {
if ($course) {
$c = $course->getSemClass();
if ($c->isGroup()) {
$item = new Navigation(_('Unterveranstaltungen'), 'dispatch.php/course/grouping/children');
$item->setImage(Icon::create('group', Icon::ROLE_INFO_ALT));
$item->setActiveImage(Icon::create('group', Icon::ROLE_INFO));
$item->setDescription(_('Ordnen Sie dieser Veranstaltung eine oder mehrere Unterveranstaltungen zu.'));
$navigation->addSubNavigation('children', $item);
/*
* Check if any SemClasses with grouping functionality exist at all
* -> show parent assignment.
*/
} else if (count(SemClass::getGroupClasses()) > 0) {
$item = new Navigation(_('Zuordnung zu Hauptveranstaltung'), 'dispatch.php/course/grouping/parent');
$item->setImage(Icon::create('group', Icon::ROLE_INFO_ALT));
$item->setActiveImage(Icon::create('group', Icon::ROLE_INFO));
$item->setDescription(_('Ordnen Sie diese Veranstaltung einer bestehenden ' .
'Hauptveranstaltung zu oder lösen Sie eine bestehende Zuordnung.'));
$navigation->addSubNavigation('parent', $item);
}
}
return ['admin' => $navigation]; $item = new Navigation(_('Zuordnung zu Hauptveranstaltung'), 'dispatch.php/course/grouping/parent');
} else { $item->setImage(Icon::create('group', Icon::ROLE_INFO_ALT));
return []; $item->setActiveImage(Icon::create('group', Icon::ROLE_INFO));
$item->setDescription(_('Ordnen Sie diese Veranstaltung einer bestehenden ' .
'Hauptveranstaltung zu oder lösen Sie eine bestehende Zuordnung.'));
$navigation->addSubNavigation('parent', $item);
}
} }
return ['admin' => $navigation];
} }
/** /**
...@@ -138,4 +151,20 @@ class CoreAdmin extends CorePlugin implements StudipModule ...@@ -138,4 +151,20 @@ class CoreAdmin extends CorePlugin implements StudipModule
// TODO: Implement getInfoTemplate() method. // TODO: Implement getInfoTemplate() method.
return null; return null;
} }
private function getRootNavigation(): Navigation
{
$navigation = new Navigation(_('Verwaltung'));
$navigation->setImage(Icon::create('admin', Icon::ROLE_INFO_ALT));
$navigation->setActiveImage(Icon::create('admin', Icon::ROLE_INFO));
return $navigation;
}
private function addVoteNavigation(Navigation &$navigation): void
{
$item = new Navigation(_('Fragebögen'), 'dispatch.php/questionnaire/courseoverview');
$item->setImage(Icon::create('vote'));
$item->setDescription(_('Erstellen und bearbeiten von Fragebögen.'));
$navigation->addSubNavigation('questionnaires', $item);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment