Skip to content

Commit

Permalink
Tutoren können Sichtbarkeit nicht ändern -- fix-360 (#366)
Browse files Browse the repository at this point in the history
* Implemented switch to allow tutor editing episodes

* Using only one querry
  • Loading branch information
ssrahn authored Dec 16, 2020
1 parent ff0988e commit 17dc3ce
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Constants {
'OPENCAST_ALLOW_MEDIADOWNLOAD' ,
'OPENCAST_ALLOW_STUDIO',
'OPENCAST_HIDE_EPISODES',
'OPENCAST_TUTOR_EPISODE_PERM',
'OPENCAST_RESOURCE_PROPERTY_ID'
];

Expand Down
7 changes: 4 additions & 3 deletions controllers/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,10 @@ public function permission_action($episode_id, $permission)
if ($this->isLive($episode_id)) {
throw new AccessDeniedException();
}

if (!$GLOBALS['perm']->have_studip_perm('admin', $this->course_id)
&& !OCModel::checkPermForEpisode($episode_id, $this->user_id)) {

$check_perm_for = Config::get()->OPENCAST_TUTOR_EPISODE_PERM ? ['tutor', 'dozent'] : 'dozent';

if (!$GLOBALS['perm']->have_studip_perm('admin', $this->course_id) && !OCModel::checkPermForEpisode($episode_id, $this->user_id, $check_perm_for)) {
throw new AccessDeniedException();
}

Expand Down
30 changes: 30 additions & 0 deletions migrations/035_add_tutor_episode_perm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
class AddTutorEpisodePerm extends Migration
{

function up()
{
$db = DBManager::get();

$stmt = $db->prepare('INSERT IGNORE INTO config (field, value, section, type, `range`, mkdate, chdate, description)
VALUES (:name, :value, :section, :type, :range, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)');
$stmt->execute([
'name' => 'OPENCAST_TUTOR_EPISODE_PERM',
'section' => 'opencast',
'description' => 'Sollen Tutoren Rechte für das Bearbeiten der Episoden haben?',
'range' => 'global',
'type' => 'boolean',
'value' => false
]);

SimpleOrMap::expireTableScheme();
}

function down()
{
$db = DBManager::get();

$db->exec("DELETE FROM config WHERE field = 'OPENCAST_TUTOR_EPISODE_PERM'");
}

}
6 changes: 3 additions & 3 deletions models/OCModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,14 @@ static function getConfigurationstate()
return false;
}

static function checkPermForEpisode($episode_id, $user_id)
static function checkPermForEpisode($episode_id, $user_id, $user_status)
{
$stmt = DBManager::get()->prepare("SELECT COUNT(*) AS COUNT FROM oc_seminar_episodes oce
JOIN oc_seminar_series oss USING (series_id)
JOIN seminar_user su ON (oss.seminar_id = su.Seminar_id)
WHERE oce.episode_id = ? AND su.status = 'dozent' AND su.user_id = ?");
WHERE oce.episode_id = ? AND su.status IN (?) AND su.user_id = ?");

$stmt->execute([$episode_id, $user_id]);
$stmt->execute([$episode_id, $user_status, $user_id]);
$rows = $stmt->fetchAll(PDO::FETCH_COLUMN);

if ($rows['0'] > 0) {
Expand Down

0 comments on commit 17dc3ce

Please sign in to comment.