InDefero

Sign in or create your account | Project List | Help

InDefero Git Source Tree

Root/src/IDF/Middleware.php

Source at commit 7383e18dff19e7e6a1e56d55cdfbfa109e91bfb3 created 2 years 1 month ago.
By Loic d'Anterroches, Fixed issue 4, with fine control over the tabs access.
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
38     * /p/(\w+)/whatever. This means that it will not try to match on
39     * /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('#^/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                        'source_access_rights' => 'hasSourceAccess',
57                        'issues_access_rights' => 'hasIssuesAccess');
58            $request->rights = array();
59            foreach ($ak as $key=>$val) {
60                $request->rights[$val] = (true === IDF_Precondition::accessTabGeneric($request, $key));
61            }
62        }
63        return false;
64    }
65}
66
67
68function IDF_Middleware_ContextPreProcessor($request)
69{
70    $c = array();
71    $c['request'] = $request;
72    if (isset($request->project)) {
73        $c['project'] = $request->project;
74        $c['isOwner'] = $request->user->hasPerm('IDF.project-owner',
75                                                $request->project);
76        $c['isMember'] = $request->user->hasPerm('IDF.project-member',
77                                                 $request->project);
78        $c = array_merge($c, $request->rights);
79    }
80    return $c;
81}
82
83

Archive Download this file

Branches:
dev
develop
master
newdiff
svn

Tags:
v1.0