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
public function trigger_action()
{
$context = Context::get();
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
if (!$context->isEditableByUser()) {
throw new AccessDeniedException();
}
if (Request::isPost()) {
if ($context->getRangeType() === 'course') {
if ($context instanceof Course) {
$sem_class = $context->getSemClass();
} else {
$sem_class = SemClass::getDefaultInstituteClass($context->type);
......@@ -129,6 +128,7 @@ class Course_ContentmodulesController extends AuthenticatedController
$this->redirect("course/contentmodules/trigger", ['cid' => $context->getId(), 'plugin_id' => $module->getPluginId()]);
return;
}
$active_tool = ToolActivation::find([$context->id, Request::int('plugin_id')]);
$template = $GLOBALS['template_factory']->open('tabs.php');
$template->navigation = Navigation::getItem('/course');
......@@ -142,11 +142,10 @@ class Course_ContentmodulesController extends AuthenticatedController
public function reorder_action()
{
$context = Context::get();
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
if (!$context->isEditableByUser()) {
throw new AccessDeniedException();
}
if (Request::isPost()) {
$position = 0;
foreach (Request::getArray('order') as $plugin_id) {
......@@ -157,6 +156,7 @@ class Course_ContentmodulesController extends AuthenticatedController
$this->redirect($this->reorderURL());
return;
}
Navigation::getItem('/course/admin')->setActive(true);
$template = $GLOBALS['template_factory']->open('tabs.php');
$template->navigation = Navigation::getItem('/course');
......@@ -170,12 +170,12 @@ class Course_ContentmodulesController extends AuthenticatedController
if (!Request::isPost()) {
throw new AccessDeniedException();
}
$context = Context::get();
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
$context = Context::get();
if (!$context->isEditableByUser()) {
throw new AccessDeniedException();
}
$moduleclass = Request::get('moduleclass');
$module = new $moduleclass;
......@@ -208,15 +208,15 @@ class Course_ContentmodulesController extends AuthenticatedController
public function rename_action($module_id)
{
$context = Context::get();
$required_perm = $context->getRangeType() === 'course' ? 'tutor' : 'admin';
if (!$GLOBALS['perm']->have_studip_perm($required_perm, $context->id)) {
if (!$context->isEditableByUser()) {
throw new AccessDeniedException();
}
$this->module = PluginManager::getInstance()->getPluginById($module_id);
$this->metadata = $this->module->getMetadata();
PageLayout::setTitle(_('Werkzeug umbenennen'));
$this->tool = ToolActivation::find([$context->id, $module_id]);
if (Request::isPost()) {
$metadata = $this->tool->metadata->getArrayCopy();
if (!trim(Request::get('displayname')) || Request::submitted('delete')) {
......@@ -359,8 +359,5 @@ class Course_ContentmodulesController extends AuthenticatedController
} catch (Exception $e) {
return null;
}
}
}
......@@ -311,10 +311,11 @@ class Institute extends SimpleORMap implements Range
public function isEditableByUser($user_id = null): bool
{
if ($user_id === null) {
$user_id = $GLOBALS['user']->id;
$user_id = User::findCurrent()->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';
}
......
......@@ -24,98 +24,111 @@ class CoreAdmin extends CorePlugin implements StudipModule
*/
public function getTabNavigation($course_id)
{
if ($GLOBALS['perm']->have_studip_perm('tutor', $course_id)) {
$navigation = new Navigation(_('Verwaltung'));
$navigation->setImage(Icon::create('admin', Icon::ROLE_INFO_ALT));
$navigation->setActiveImage(Icon::create('admin', Icon::ROLE_INFO));
$main = new Navigation(_('Werkzeuge'), 'dispatch.php/course/contentmodules');
$navigation->addSubNavigation('contentmodules', $main);
if (!Context::isInstitute()) {
$item = new Navigation(_('Grunddaten'), 'dispatch.php/course/basicdata/view/' . $course_id);
$item->setImage(Icon::create('edit'));
$item->setDescription(_('Bearbeiten der Grundeinstellungen dieser Veranstaltung.'));
$navigation->addSubNavigation('details', $item);
$item = new Navigation(_('Veranstaltungsbild'), 'dispatch.php/course/avatar');
$item->setDescription(_('Infobild dieser Veranstaltung bearbeiten oder löschen.'));
$navigation->addSubNavigation('avatar', $item);
$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.'));
$navigation->addSubNavigation('study_areas', $item);
$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']);
$item->setImage(Icon::create('learnmodule'));
$item->setDescription(_('Zuordnung der Veranstaltung zu Lehrveranstaltungsgruppen um die Einordnung innerhalb des Modulverzeichnisses festzulegen.'));
$navigation->addSubNavigation('lvgruppen', $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 ($GLOBALS['perm']->have_studip_perm('tutor', $course_id)) {
if (Config::get()->VOTE_ENABLE) {
$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);
}
$range = RangeFactory::find($course_id);
// Given range is invalid, leave early
if (!$range) {
return [];
}
// Special case: Tutors of institutes may manage votes
if (
Config::get()->VOTE_ENABLE
&& $range instanceof Institute
&& !$range->isEditableByUser()
&& Seminar_Perm::get()->have_studip_perm('tutor', $range->id)
) {
$navigation = $this->getRootNavigation();
$this->addVoteNavigation($navigation);
return ['admin' => $navigation];
}
// User may not edit this range
if (!$range->isEditableByUser()) {
return [];
}
// Build regular admin navigation
$navigation = $this->getRootNavigation();
$main = new Navigation(_('Werkzeuge'), 'dispatch.php/course/contentmodules');
$navigation->addSubNavigation('contentmodules', $main);
if ($range instanceof Course) {
$item = new Navigation(_('Grunddaten'), 'dispatch.php/course/basicdata/view/' . $course_id);
$item->setImage(Icon::create('edit'));
$item->setDescription(_('Bearbeiten der Grundeinstellungen dieser Veranstaltung.'));
$navigation->addSubNavigation('details', $item);
$item = new Navigation(_('Veranstaltungsbild'), 'dispatch.php/course/avatar');
$item->setDescription(_('Infobild dieser Veranstaltung bearbeiten oder löschen.'));
$navigation->addSubNavigation('avatar', $item);
$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.'));
$navigation->addSubNavigation('study_areas', $item);
if ($range->getSemClass()['module']) {
$item = new Navigation(_('LV-Gruppen'), 'dispatch.php/course/lvgselector/index/' . $course_id, ['list' => 'TRUE']);
$item->setImage(Icon::create('learnmodule'));
$item->setDescription(_('Zuordnung der Veranstaltung zu Lehrveranstaltungsgruppen um die Einordnung innerhalb des Modulverzeichnisses festzulegen.'));
$navigation->addSubNavigation('lvgruppen', $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?
* -> show child management
* Check if any SemClasses with grouping functionality exist at all
* -> show parent assignment.
*/
$course = Course::find($course_id);
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);
}
}
} else if (count(SemClass::getGroupClasses()) > 0) {
return ['admin' => $navigation];
} else {
return [];
$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];
}
/**
......@@ -138,4 +151,20 @@ class CoreAdmin extends CorePlugin implements StudipModule
// TODO: Implement getInfoTemplate() method.
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