Address files by name rather than ID in the downloads section (issue 686)
This commit is contained in:
parent
82bb18fe10
commit
ee33cc1832
@ -3,6 +3,7 @@
|
|||||||
## New Features
|
## New Features
|
||||||
|
|
||||||
- Mercurial source views now show parent revisions (if any) and detailed change information
|
- Mercurial source views now show parent revisions (if any) and detailed change information
|
||||||
|
- File download URLs now contain the file name rather than the upload id; old links still work though (issue 686)
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
||||||
|
@ -190,19 +190,35 @@ class IDF_Views_Download
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file.
|
* Download the file with the given name.
|
||||||
*/
|
*/
|
||||||
public $download_precond = array('IDF_Precondition::accessDownloads');
|
public $download_precond = array('IDF_Precondition::accessDownloads');
|
||||||
public function download($request, $match)
|
public function download($request, $match)
|
||||||
{
|
{
|
||||||
$prj = $request->project;
|
$prj = $request->project;
|
||||||
$upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]);
|
$sql = new Pluf_SQL('file=%s', array($match[2]));
|
||||||
|
$upload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen()));
|
||||||
|
if (!$upload) throw new Pluf_HTTP_Error404();
|
||||||
$prj->inOr404($upload);
|
$prj->inOr404($upload);
|
||||||
$upload->downloads += 1;
|
$upload->downloads += 1;
|
||||||
$upload->update();
|
$upload->update();
|
||||||
return new Pluf_HTTP_Response_Redirect($upload->getAbsoluteUrl($prj));
|
return new Pluf_HTTP_Response_Redirect($upload->getAbsoluteUrl($prj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download the file with the given ID (for legacy links).
|
||||||
|
*/
|
||||||
|
public $downloadById_precond = array('IDF_Precondition::accessDownloads');
|
||||||
|
public function downloadById($request, $match)
|
||||||
|
{
|
||||||
|
$upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]);
|
||||||
|
return new Pluf_HTTP_Response_Redirect(
|
||||||
|
Pluf_HTTP_URL_urlForView('IDF_Views_Download::download', array(
|
||||||
|
$match[1], $upload->file
|
||||||
|
)), 301
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit a new file for download.
|
* Submit a new file for download.
|
||||||
*/
|
*/
|
||||||
|
@ -294,11 +294,16 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/$#',
|
|||||||
'model' => 'IDF_Views_Download',
|
'model' => 'IDF_Views_Download',
|
||||||
'method' => 'view');
|
'method' => 'view');
|
||||||
|
|
||||||
$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/get/$#',
|
$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/get/(.+)$#',
|
||||||
'base' => $base,
|
'base' => $base,
|
||||||
'model' => 'IDF_Views_Download',
|
'model' => 'IDF_Views_Download',
|
||||||
'method' => 'download');
|
'method' => 'download');
|
||||||
|
|
||||||
|
$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/get/$#',
|
||||||
|
'base' => $base,
|
||||||
|
'model' => 'IDF_Views_Download',
|
||||||
|
'method' => 'downloadById');
|
||||||
|
|
||||||
$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/create/$#',
|
$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/create/$#',
|
||||||
'base' => $base,
|
'base' => $base,
|
||||||
'model' => 'IDF_Views_Download',
|
'model' => 'IDF_Views_Download',
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{block body}
|
{block body}
|
||||||
|
|
||||||
<div class="download-file">
|
<div class="download-file">
|
||||||
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.id)}">{$file}</a> - {$file.filesize|size}
|
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.file)}">{$file}</a> - {$file.filesize|size}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>{blocktrans}<strong>Attention!</strong> If you want to delete a specific version of your software, maybe, someone is depending on this specific version to run his systems. Are you sure, you will not affect anybody when removing this file?{/blocktrans}</p>
|
<p>{blocktrans}<strong>Attention!</strong> If you want to delete a specific version of your software, maybe, someone is depending on this specific version to run his systems. Are you sure, you will not affect anybody when removing this file?{/blocktrans}</p>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div class="download-file">
|
<div class="download-file">
|
||||||
{if $deprecated}<p class="smaller">{blocktrans}<strong>Attention!</strong> This file is marked as deprecated, download it only if you are sure you need this specific version.{/blocktrans}</p>{/if}
|
{if $deprecated}<p class="smaller">{blocktrans}<strong>Attention!</strong> This file is marked as deprecated, download it only if you are sure you need this specific version.{/blocktrans}</p>{/if}
|
||||||
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.id)}">{$file}</a> - {$file.filesize|size}
|
<a href="{url 'IDF_Views_Download::download', array($project.shortname, $file.file)}">{$file}</a> - {$file.filesize|size}
|
||||||
</div>
|
</div>
|
||||||
{if $file.changelog}
|
{if $file.changelog}
|
||||||
<h2 class="changes">{trans 'Changes'}</h2>
|
<h2 class="changes">{trans 'Changes'}</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user