Indefero

Indefero Git Source Tree

Root/src/IDF/Middleware.php

1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of InDefero, an open source project management application.
6# Copyright (C) 2008 Céondo Ltd and contributors.
7#
8# InDefero is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# InDefero is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24/**
25 * Project middleware.
26 *
27 * It must be after the session middleware.
28 */
29class IDF_Middleware
30{
31 /**
32 * Process the request.
33 *
34 * When processing the request, check if matching a project. If
35 * so, directly set $request->project to the project.
36 *
37 * The url to match a project is in the format /p/(\w+)/whatever
38 * or /api/p/(\w+)/whatever. This means that it will not try to
39 * match on /login/ or /logout/.
40 *
41 * @param Pluf_HTTP_Request The request
42 * @return bool false or redirect.
43 */
44 function process_request(&$request)
45 {
46 $match = array();
47 if (preg_match('#^/(?:api/p|p)/([\-\w]+)/#', $request->query, $match)) {
48 try {
49 $request->project = IDF_Project::getOr404($match[1]);
50 } catch (Pluf_HTTP_Error404 $e) {
51 return new Pluf_HTTP_Response_NotFound(sprintf(__('The page <em>%s</em> was not found on the server.'), htmlspecialchars($request->query)));
52 }
53 $request->conf = new IDF_Conf();
54 $request->conf->setProject($request->project);
55 $ak = array('downloads_access_rights' => 'hasDownloadsAccess',
56 'wiki_access_rights' => 'hasWikiAccess',
57 'source_access_rights' => 'hasSourceAccess',
58 'issues_access_rights' => 'hasIssuesAccess');
59 $request->rights = array();
60 foreach ($ak as $key=>$val) {
61 $request->rights[$val] = (true === IDF_Precondition::accessTabGeneric($request, $key));
62 }
63 }
64 return false;
65 }
66}
67
68
69function IDF_Middleware_ContextPreProcessor($request)
70{
71 $c = array();
72 $c['request'] = $request;
73 if (isset($request->project)) {
74 $c['project'] = $request->project;
75 $c['isOwner'] = $request->user->hasPerm('IDF.project-owner',
76 $request->project);
77 $c['isMember'] = $request->user->hasPerm('IDF.project-member',
78 $request->project);
79 $c = array_merge($c, $request->rights);
80 }
81 return $c;
82}
83
84

Archive Download this file