Add Project List API

This commit is contained in:
William MARTIN 2011-03-07 15:01:51 +01:00
parent fba5841bdc
commit c3cd494386
4 changed files with 39 additions and 6 deletions

View File

@ -190,7 +190,12 @@ class IDF_Precondition
return true; // Again need authentication error
}
$request->user = $users[0];
// Don't try to load projects rights access if we are not in one
if ($request->query !== "/api/") {
IDF_Middleware::setRights($request);
}
return true;
}

View File

@ -37,10 +37,12 @@ class IDF_Views
* Only the public projects are listed or the private with correct
* rights.
*/
public function index($request, $match)
public function index($request, $match, $api=false)
{
$projects = self::getProjects($request->user);
$stats = self::getProjectsStatistics ($projects);
if ($api == true) return $projects;
return Pluf_Shortcuts_RenderToResponse('idf/index.html',
array('page_title' => __('Projects'),
'projects' => $projects,

View File

@ -64,7 +64,7 @@ class IDF_Views_Api
$out = array();
if ($request->method == 'GET') {
// We give the details of the form
$out['doc'] = 'A POST request against this url will allow you to create a new issue.';
$out['help'] = 'A POST request against this url will allow you to create a new issue.';
if ($request->user->hasPerm('IDF.project-owner', $request->project)
or $request->user->hasPerm('IDF.project-member', $request->project)) {
$out['status'] = array();
@ -76,16 +76,37 @@ class IDF_Views_Api
} else {
// We need to give back the results of the creation
if (is_object($p) and 'IDF_Issue' == get_class($p)) {
$out['mess'] = 'success';
$out['message'] = 'success';
$out['issue'] = $p->id;
} else {
$out['mess'] = 'error';
$out['message'] = 'error';
$out['errors'] = $p['form']->errors;
}
}
return new Pluf_HTTP_Response_Json($out);
}
/**
* List all the projects
*/
public $projectIndex_precond = array('IDF_Precondition::apiSetUser');
public function projectIndex($request, $match)
{
$view = new IDF_Views();
$projects = $view->index($request, $match, true);
$data = array();
foreach ($projects as $p) {
$data[] = array("shortname" => $p->shortname, "name" => $p->name, "shortdesc" => $p->shortdesc, "private" => $p->private);
}
$out = array();
$out['message'] = 'success';
$out['projects'] = $data;
return new Pluf_HTTP_Response_Json($out);
}
/**
* Get the list of tags to give them to the end users when doing a
* GET request against a form. That way it is possible for them to

View File

@ -364,6 +364,11 @@ $ctl[] = array('regex' => '#^/api/p/([\-\w]+)/issues/create/$#',
'model' => 'IDF_Views_Api',
'method' => 'issueCreate');
$ctl[] = array('regex' => '#^/api/$#',
'base' => $base,
'model' => 'IDF_Views_Api',
'method' => 'projectIndex');
// ---------- FORGE ADMIN --------------------------------
$ctl[] = array('regex' => '#^/admin/projects/$#',