Fixed issue 4, with fine control over the tabs access.

For each tab, at the exception of the project home and the
administration area, it possible to control the access rights if the
user is anonymous, signed in, member or owner.
This commit is contained in:
Loic d'Anterroches
2008-08-07 15:35:03 +02:00
parent 1831716b07
commit 7383e18dff
20 changed files with 475 additions and 70 deletions

View File

@@ -38,6 +38,7 @@ class IDF_Views_Download
/**
* List the files available for download.
*/
public $index_precond = array('IDF_Precondition::accessDownloads');
public function index($request, $match)
{
$prj = $request->project;
@@ -75,6 +76,7 @@ class IDF_Views_Download
/**
* View details of a file.
*/
public $view_precond = array('IDF_Precondition::accessDownloads');
public function view($request, $match)
{
$prj = $request->project;
@@ -123,6 +125,7 @@ class IDF_Views_Download
/**
* Download a file.
*/
public $download_precond = array('IDF_Precondition::accessDownloads');
public function download($request, $match)
{
$prj = $request->project;
@@ -136,7 +139,8 @@ class IDF_Views_Download
/**
* Submit a new file for download.
*/
public $submit_precond = array('IDF_Precondition::projectMemberOrOwner');
public $submit_precond = array('IDF_Precondition::accessDownloads',
'IDF_Precondition::projectMemberOrOwner');
public function submit($request, $match)
{
$prj = $request->project;
@@ -197,6 +201,7 @@ class IDF_Views_Download
/**
* View list of downloads with a given label.
*/
public $listLabel_precond = array('IDF_Precondition::accessDownloads');
public function listLabel($request, $match)
{
$prj = $request->project;

View File

@@ -34,6 +34,7 @@ class IDF_Views_Issue
/**
* View list of issues for a given project.
*/
public $index_precond = array('IDF_Precondition::accessIssues');
public function index($request, $match)
{
$prj = $request->project;
@@ -77,7 +78,8 @@ class IDF_Views_Issue
*
* Only open issues are shown.
*/
public $myIssues_precond = array('Pluf_Precondition::loginRequired');
public $myIssues_precond = array('IDF_Precondition::accessIssues',
'Pluf_Precondition::loginRequired');
public function myIssues($request, $match)
{
$prj = $request->project;
@@ -124,7 +126,8 @@ class IDF_Views_Issue
$request);
}
public $create_precond = array('Pluf_Precondition::loginRequired');
public $create_precond = array('IDF_Precondition::accessIssues',
'Pluf_Precondition::loginRequired');
public function create($request, $match)
{
$prj = $request->project;
@@ -157,6 +160,7 @@ class IDF_Views_Issue
$request);
}
public $view_precond = array('IDF_Precondition::accessIssues');
public function view($request, $match)
{
$prj = $request->project;
@@ -204,6 +208,7 @@ class IDF_Views_Issue
/**
* View list of issues for a given project with a given status.
*/
public $listStatus_precond = array('IDF_Precondition::accessIssues');
public function listStatus($request, $match)
{
$prj = $request->project;
@@ -246,6 +251,7 @@ class IDF_Views_Issue
/**
* View list of issues for a given project with a given label.
*/
public $listLabel_precond = array('IDF_Precondition::accessIssues');
public function listLabel($request, $match)
{
$prj = $request->project;

View File

@@ -39,9 +39,12 @@ class IDF_Views_Project
$prj = $request->project;
$team = $prj->getMembershipData();
$title = (string) $prj;
$tags = IDF_Views_Download::getDownloadTags($prj);
// the first tag is the featured, the last is the deprecated.
$downloads = $tags[0]->get_idf_upload_list();
$downloads = array();
if ($request->rights['hasDownloadsAccess']) {
$tags = IDF_Views_Download::getDownloadTags($prj);
// the first tag is the featured, the last is the deprecated.
$downloads = $tags[0]->get_idf_upload_list();
}
return Pluf_Shortcuts_RenderToResponse('project-home.html',
array(
'page_title' => $title,
@@ -201,4 +204,49 @@ class IDF_Views_Project
),
$request);
}
/**
* Administrate the access rights to the tabs.
*/
public $adminTabs_precond = array('IDF_Precondition::projectOwner');
public function adminTabs($request, $match)
{
$prj = $request->project;
$title = sprintf(__('%s Tabs Access Rights'), (string) $prj);
$extra = array(
'conf' => $request->conf,
);
if ($request->method == 'POST') {
$form = new IDF_Form_TabsConf($request->POST, $extra);
if ($form->isValid()) {
foreach ($form->cleaned_data as $key=>$val) {
$request->conf->setVal($key, $val);
}
$request->user->setMessage(__('The project tabs access rights have been saved.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminTabs',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$params = array();
$keys = array('downloads_access_rights', 'source_access_rights',
'issues_access_rights');
foreach ($keys as $key) {
$_val = $request->conf->getVal($key, false);
if ($_val !== false) {
$params[$key] = $_val;
}
}
if (count($params) == 0) {
$params = null; //Nothing in the db, so new form.
}
$form = new IDF_Form_TabsConf($params, $extra);
}
return Pluf_Shortcuts_RenderToResponse('admin/tabs.html',
array(
'page_title' => $title,
'form' => $form,
),
$request);
}
}

View File

@@ -31,6 +31,7 @@ Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
*/
class IDF_Views_Source
{
public $changeLog_precond = array('IDF_Precondition::accessSource');
public function changeLog($request, $match)
{
$title = sprintf(__('%s Git Change Log'), (string) $request->project);
@@ -49,6 +50,7 @@ class IDF_Views_Source
$request);
}
public $treeBase_precond = array('IDF_Precondition::accessSource');
public function treeBase($request, $match)
{
$title = sprintf(__('%s Git Source Tree'), (string) $request->project);
@@ -78,6 +80,7 @@ class IDF_Views_Source
$request);
}
public $tree_precond = array('IDF_Precondition::accessSource');
public function tree($request, $match)
{
$title = sprintf(__('%s Git Source Tree'), (string) $request->project);
@@ -149,6 +152,7 @@ class IDF_Views_Source
return '<span class="breadcrumb">'.implode('<span class="sep">'.$sep.'</span>', $out).'</span>';
}
public $commit_precond = array('IDF_Precondition::accessSource');
public function commit($request, $match)
{
$git = new IDF_Git($request->project->getGitRepository());
@@ -182,6 +186,7 @@ class IDF_Views_Source
* Get a zip archive of the current commit.
*
*/
public $download_precond = array('IDF_Precondition::accessSource');
public function download($request, $match)
{
$commit = trim($match[2]);