From 009fb49a6aa44426e9696a9d7405b9a96414c473 Mon Sep 17 00:00:00 2001 From: Robbt Date: Tue, 5 Mar 2019 10:00:54 -0500 Subject: [PATCH] Added the ability for admins to edit the owner of a track via the edit track interface --- .../controllers/LibraryController.php | 5 ++ airtime_mvc/application/forms/EditAudioMD.php | 18 ++++++ airtime_mvc/application/models/StoredFile.php | 59 +++++++++---------- airtime_mvc/application/models/User.php | 5 ++ 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 7ec84ddef..aefad2114 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -364,6 +364,7 @@ class LibraryController extends Zend_Controller_Action { $user = Application_Model_User::getCurrentUser(); $isAdminOrPM = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + $isAdmin = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN)); $request = $this->getRequest(); @@ -380,6 +381,10 @@ class LibraryController extends Zend_Controller_Action $form->removeActionButtons(); $this->view->permissionDenied = true; } + // only admins should be able to edit the owner of a file + if (!$isAdmin) { + $form->removeOwnerEdit(); + } if ($request->isPost()) { diff --git a/airtime_mvc/application/forms/EditAudioMD.php b/airtime_mvc/application/forms/EditAudioMD.php index 3faa209bd..e4e6768f9 100644 --- a/airtime_mvc/application/forms/EditAudioMD.php +++ b/airtime_mvc/application/forms/EditAudioMD.php @@ -48,6 +48,21 @@ class Application_Form_EditAudioMD extends Zend_Form )); $this->addElement($album_title); + + // Add album field + $user_options = array(); + $users = Application_Model_User::getNonGuestUsers(); + + foreach ($users as $host) { + $user_options[$host['index']] = $host['label']; + } + + $owner_id = new Zend_Form_Element_Select('owner_id'); + $owner_id->class = 'input_text'; + $owner_id->setLabel(_('Owner:')); + $owner_id->setMultiOptions($user_options); + $this->addelement($owner_id); + // Description field $description = new Zend_Form_Element_Textarea('description'); $description->class = 'input_text'; @@ -244,6 +259,9 @@ class Application_Form_EditAudioMD extends Zend_Form } } + public function removeOwnerEdit() { + $this->removeElement('owner_id'); + } public function removeActionButtons() { $this->removeElement('editmdsave'); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 819df76b4..25d692c12 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -172,39 +172,36 @@ class Application_Model_StoredFile $this->_file->$method(null); } } else { - $owner = $this->_file->getFkOwner(); - // if owner_id is already set we don't want to set it again. - if (!$owner) { // no owner detected, we try to assign one. - // if MDATA_OWNER_ID is not set then we default to the - // first admin user we find - if (!array_key_exists('owner_id', $p_md)) { - //$admins = Application_Model_User::getUsers(array('A')); - $admins = array_merge(Application_Model_User::getUsersOfType('A')->getData(), - Application_Model_User::getUsersOfType('S')->getData()); - if (count($admins) > 0) { // found admin => pick first one - $owner = $admins[0]; + // in order to edit the owner of a file we see if owner_id exists in the track form metadata otherwise + // we determine it via the algorithm below + if (!array_key_exists('owner_id', $p_md)) { + $owner = $this->_file->getFkOwner(); + // if owner_id is already set we don't want to set it again. + if (!$owner) { // no owner detected, we try to assign one. + // if MDATA_OWNER_ID is not set then we default to the + // first admin user we find + if (!array_key_exists('owner_id', $p_md)) { + //$admins = Application_Model_User::getUsers(array('A')); + $admins = array_merge(Application_Model_User::getUsersOfType('A')->getData(), + Application_Model_User::getUsersOfType('S')->getData()); + if (count($admins) > 0) { // found admin => pick first one + $owner = $admins[0]; + } + } // get the user by id and set it like that + else { + $user = CcSubjsQuery::create() + ->findPk($p_md['owner_id']); + if ($user) { + $owner = $user; + } + } + if ($owner) { + $this->_file->setDbOwnerId($owner->getDbId()); + } else { + Logging::info("Could not find suitable owner for file + '" . $p_md['filepath'] . "'"); } } - // get the user by id and set it like that - else { - $user = CcSubjsQuery::create() - ->findPk($p_md['owner_id']); - if ($user) { - $owner = $user; - } - } - if ($owner) { - $this->_file->setDbOwnerId( $owner->getDbId() ); - } else { - Logging::info("Could not find suitable owner for file - '".$p_md['filepath']."'"); - } - } - # We don't want to process owner_id in bulk because we already - # processed it in the code above. This is done because owner_id - # needs special handling - if (array_key_exists('owner_id', $p_md)) { - unset($p_md['owner_id']); } foreach ($p_md as $dbColumn => $mdValue) { // don't blank out name, defaults to original filename on first diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 0b105e125..6f39d01d6 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -325,6 +325,11 @@ class Application_Model_User return Application_Model_User::getUsers(array('H'), $search); } + public static function getNonGuestUsers($search=null) + { + return Application_Model_User::getUsers(array('H','A','S','P'), $search); + } + public static function getUsersDataTablesInfo($datatables) {