Add appData/screenshot::mustBeQueued()

This commit is contained in:
Alexander Nicolaysen Sørnes
2007-04-21 17:49:43 +00:00
committed by WineHQ
parent a6127c1b07
commit 3ab921cf0d
3 changed files with 84 additions and 39 deletions

View File

@@ -116,9 +116,6 @@ class appData
if($sQueued === false) if($sQueued === false)
$sQueued = "false"; $sQueued = "false";
if(($sQueued == "true" || $sQueued == "all") && !appData::canEdit($sType))
return FALSE;
if(($sQueued == "true" || $sQueued == "all") && if(($sQueued == "true" || $sQueued == "all") &&
!$_SESSION['current']->hasPriv("admin")) !$_SESSION['current']->hasPriv("admin"))
{ {
@@ -226,9 +223,6 @@ class appData
if($bRejected) if($bRejected)
return FALSE; return FALSE;
if($bQueued && !appData::canEdit($sType))
return FALSE;
if($bQueued && !$_SESSION['current']->hasPriv("admin")) if($bQueued && !$_SESSION['current']->hasPriv("admin"))
{ {
$sQuery = "SELECT DISTINCT appData.* FROM appData, appMaintainers, $sQuery = "SELECT DISTINCT appData.* FROM appData, appMaintainers,
@@ -327,19 +321,53 @@ class appData
return $hResult; return $hResult;
} }
function canEdit($sType = null) function canEdit()
{ {
if($sType) if($_SESSION['current']->hasPriv("admin"))
return TRUE;
if($this)
{ {
$oObject = new $sType(); if($this->iVersionId)
return $oObject->canEdit();
} else
{ {
if($_SESSION['current']->hasPriv("admin") || $oVersion = new version($this->iVersionId);
maintainer::isUserMaintainer($_SESSION['current'])) if($oVersion->canEdit())
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
} else if($this->iAppId)
{
$oApp = new application($this->iAppId);
if($oApp->canEdit())
return TRUE;
else
return FALSE;
} else
return FALSE;
}
}
function mustBeQueued()
{
if($_SESSION['current']->hasPriv("admin"))
return FALSE;
if($this)
{
if($this->iVersionId)
{
$oVersion = new version($this->iVersionId);
if($oVersion->canEdit())
return FALSE;
else
return TRUE;
} else if($this->iAppId)
{
$oApp = new application($this->iAppId);
if($oApp->canEdit())
return FALSE;
else
return TRUE;
} else
return TRUE;
} }
} }

View File

@@ -14,11 +14,16 @@ $watermark = new Image("/images/watermark.png");
*/ */
class Screenshot { class Screenshot {
var $iScreenshotId; var $iScreenshotId;
// parameters necessary for creating a new screenshot with
// Screenshot::create()
var $iVersionId;
var $hFile;
var $sDescription; var $sDescription;
var $oScreenshotImage; var $oScreenshotImage;
var $oThumbnailImage; var $oThumbnailImage;
var $bQueued; var $bQueued;
var $iVersionId;
var $iAppId; var $iAppId;
var $sUrl; var $sUrl;
var $sSubmitTime; var $sSubmitTime;
@@ -50,6 +55,7 @@ class Screenshot {
$this->bQueued = ($oRow->queued=="true")?true:false; $this->bQueued = ($oRow->queued=="true")?true:false;
$this->sSubmitTime = $oRow->submitTime; $this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId; $this->iSubmitterId = $oRow->submitterId;
$this->hFile = null;
} }
} }
} }
@@ -59,21 +65,14 @@ class Screenshot {
/** /**
* Creates a new screenshot. * Creates a new screenshot.
*/ */
function create($iVersionId = null, $sDescription = null, $hFile = null) function create()
{ {
$oVersion = new Version($iVersionId); $hResult = query_parameters("INSERT INTO appData
// Security, if we are not an administrator or a maintainer, the screenshot must be queued. (versionId, type, description, queued, submitterId)
if(!($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($oVersion->iVersionId) || $_SESSION['current']->isSuperMaintainer($oVersion->iAppId))) VALUES('?', '?', '?', '?', '?')",
{ $this->iVersionId, "screenshot",
$this->bQueued = true; $this->sDescription,
} else $this->mustBeQueued() ? "true" : "false",
{
$this->bQueued = false;
}
$hResult = query_parameters("INSERT INTO appData (versionId, type, description, queued, submitterId) ".
"VALUES('?', '?', '?', '?', '?')",
$iVersionId, "screenshot", $sDescription, $this->bQueued?"true":"false",
$_SESSION['current']->iUserId); $_SESSION['current']->iUserId);
if($hResult) if($hResult)
{ {
@@ -81,10 +80,10 @@ class Screenshot {
/* make sure we supply the full path to move_uploaded_file() */ /* make sure we supply the full path to move_uploaded_file() */
$moveToPath = appdb_fullpath("data/screenshots/originals/").$this->iScreenshotId; $moveToPath = appdb_fullpath("data/screenshots/originals/").$this->iScreenshotId;
if(!move_uploaded_file($hFile['tmp_name'], $moveToPath)) if(!move_uploaded_file($this->hFile['tmp_name'], $moveToPath))
{ {
// whoops, moving failed, do something // whoops, moving failed, do something
addmsg("Unable to move screenshot from '".$hFile['tmp_name']."' to '".$moveToPath."'", "red"); addmsg("Unable to move screenshot from '".$this->hFile['tmp_name']."' to '".$moveToPath."'", "red");
$sQuery = "DELETE $sQuery = "DELETE
FROM appData FROM appData
WHERE id = '?'"; WHERE id = '?'";
@@ -531,11 +530,26 @@ class Screenshot {
function canEdit() function canEdit()
{ {
if($_SESSION['current']->hasPriv("admin") || if($this)
maintainer::isUserMaintainer($_SESSION['current'])) {
return TRUE; $oAppData = new appData();
else $oAppData->iVersionId = $this->iVersionId;
return FALSE; $oAppData->iAppId = NULL;
return $oAppData->canEdit();
} else
return appData::canEdit();
}
function mustBeQueued()
{
if($this)
{
$oAppData = new appData();
$oAppData->iVersionId = $this->iVersionId;
$oAppData->iAppId = NULL;
return $oAppData->mustBeQueued();
} else
return appData::mustBeQueued();
} }
function objectGetInstanceFromRow($oRow) function objectGetInstanceFromRow($oRow)

View File

@@ -38,7 +38,10 @@ if($aClean['sCmd'])
} else } else
{ {
$oScreenshot = new Screenshot(); $oScreenshot = new Screenshot();
$oScreenshot->create($aClean['iVersionId'], $aClean['sScreenshotDesc'], $_FILES['sImageFile']); $oScreenshot->iVersionId = $aClean['iVersionId'];
$oScreenshot->sScreenshotDesc = $aClean['sScreenshotDesc'];
$oScreenshot->hFile = $_FILES['sImageFile'];
$oScreenshot->create();
$oScreenshot->free(); $oScreenshot->free();
} }
} elseif($aClean['sCmd'] == "delete" && is_numeric($aClean['iImageId'])) // process screenshot deletion } elseif($aClean['sCmd'] == "delete" && is_numeric($aClean['iImageId'])) // process screenshot deletion