Merge pull request #766 from Robbt/add-owner-edit
Added the ability for admins to edit the owner of a track via the edit track interface
This commit is contained in:
commit
e09a7a6a82
|
@ -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()) {
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue