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 return true; // Again need authentication error
} }
$request->user = $users[0]; $request->user = $users[0];
IDF_Middleware::setRights($request);
// Don't try to load projects rights access if we are not in one
if ($request->query !== "/api/") {
IDF_Middleware::setRights($request);
}
return true; return true;
} }

View File

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

View File

@ -64,7 +64,7 @@ class IDF_Views_Api
$out = array(); $out = array();
if ($request->method == 'GET') { if ($request->method == 'GET') {
// We give the details of the form // 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) if ($request->user->hasPerm('IDF.project-owner', $request->project)
or $request->user->hasPerm('IDF.project-member', $request->project)) { or $request->user->hasPerm('IDF.project-member', $request->project)) {
$out['status'] = array(); $out['status'] = array();
@ -76,16 +76,37 @@ class IDF_Views_Api
} else { } else {
// We need to give back the results of the creation // We need to give back the results of the creation
if (is_object($p) and 'IDF_Issue' == get_class($p)) { if (is_object($p) and 'IDF_Issue' == get_class($p)) {
$out['mess'] = 'success'; $out['message'] = 'success';
$out['issue'] = $p->id; $out['issue'] = $p->id;
} else { } else {
$out['mess'] = 'error'; $out['message'] = 'error';
$out['errors'] = $p['form']->errors; $out['errors'] = $p['form']->errors;
} }
} }
return new Pluf_HTTP_Response_Json($out); 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 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 * 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', 'model' => 'IDF_Views_Api',
'method' => 'issueCreate'); 'method' => 'issueCreate');
$ctl[] = array('regex' => '#^/api/$#',
'base' => $base,
'model' => 'IDF_Views_Api',
'method' => 'projectIndex');
// ---------- FORGE ADMIN -------------------------------- // ---------- FORGE ADMIN --------------------------------
$ctl[] = array('regex' => '#^/admin/projects/$#', $ctl[] = array('regex' => '#^/admin/projects/$#',