CC-5734: RESTful API media ownership

This commit is contained in:
drigato 2014-03-13 17:00:15 -04:00
parent 259edebadc
commit 6a68967f81
1 changed files with 24 additions and 0 deletions

View File

@ -69,6 +69,7 @@ class Rest_MediaController extends Zend_Rest_Controller
//TODO: Strip or sanitize the JSON output //TODO: Strip or sanitize the JSON output
$file = new CcFiles(); $file = new CcFiles();
$file->fromArray($this->getRequest()->getPost()); $file->fromArray($this->getRequest()->getPost());
$file->setDbOwnerId($this->getOwnerId());
$file->save(); $file->save();
$callbackUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri() . "/" . $file->getPrimaryKey(); $callbackUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri() . "/" . $file->getPrimaryKey();
@ -200,5 +201,28 @@ class Rest_MediaController extends Zend_Rest_Controller
$finalDestinationDir, $callbackUrl, $apiKey); $finalDestinationDir, $callbackUrl, $apiKey);
} }
private function getOwnerId()
{
try {
if ($this->verifySession()) {
$service_user = new Application_Service_UserService();
return $service_user->getCurrentUser()->getDbId();
} else {
$defaultOwner = CcSubjsQuery::create()
->filterByDbType('A')
->orderByDbId()
->findOne();
if (!$defaultOwner) {
// what to do if there is no admin user?
// should we handle this case?
return null;
}
return $defaultOwner->getDbId();
}
} catch(Exception $e) {
Logging::info($e->getMessage());
}
}
} }