InDefero

Sign in or create your account | Project List | Help

InDefero Git Source Tree

Root/src/IDF/Views/Project.php

Source at commit 7383e18dff19e7e6a1e56d55cdfbfa109e91bfb3 created 1 year 7 months 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
24Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
25Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse');
26Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
27Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
28
29/**
30 * Project's views.
31 */
32class IDF_Views_Project
33{
34    /**
35     * Home page of a project.
36     */
37    public function home($request, $match)
38    {
39        $prj = $request->project;
40        $team = $prj->getMembershipData();
41        $title = (string) $prj;
42        $downloads = array();
43        if ($request->rights['hasDownloadsAccess']) {
44            $tags = IDF_Views_Download::getDownloadTags($prj);
45            // the first tag is the featured, the last is the deprecated.
46            $downloads = $tags[0]->get_idf_upload_list();
47        }
48        return Pluf_Shortcuts_RenderToResponse('project-home.html',
49                                               array(
50                                                     'page_title' => $title,
51                                                     'team' => $team,
52                                                     'downloads' => $downloads,
53                                                     ),
54                                               $request);
55    }
56
57
58    /**
59     * Administrate the summary of a project.
60     */
61    public $admin_precond = array('IDF_Precondition::projectOwner');
62    public function admin($request, $match)
63    {
64        $prj = $request->project;
65        $title = sprintf(__('%s Project Summary'), (string) $prj);
66        $form_fields = array('fields'=> array('name', 'description'));
67        if ($request->method == 'POST') {
68            $form = Pluf_Shortcuts_GetFormForModel($prj, $request->POST,
69                                                   $form_fields);
70            if ($form->isValid()) {
71                $prj = $form->save();
72                $request->user->setMessage(__('The project has been updated.'));
73                $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::admin',
74                                                array($prj->shortname));
75                return new Pluf_HTTP_Response_Redirect($url);
76            }
77        } else {
78            $form = Pluf_Shortcuts_GetFormForModel($prj, $prj->getData(),
79                                                   $form_fields);
80        }
81        return Pluf_Shortcuts_RenderToResponse('admin/summary.html',
82                                               array(
83                                                     'page_title' => $title,
84                                                     'form' => $form,
85                                                     ),
86                                               $request);
87    }
88
89    /**
90     * Administrate the issue tracking of a project.
91     */
92    public $adminIssues_precond = array('IDF_Precondition::projectOwner');
93    public function adminIssues($request, $match)
94    {
95        $prj = $request->project;
96        $title = sprintf(__('%s Issue Tracking Configuration'), (string) $prj);
97        $conf = new IDF_Conf();
98        $conf->setProject($prj);
99        if ($request->method == 'POST') {
100            $form = new IDF_Form_IssueTrackingConf($request->POST);
101            if ($form->isValid()) {
102                foreach ($form->cleaned_data as $key=>$val) {
103                    $conf->setVal($key, $val);
104                }
105                $request->user->setMessage(__('The issue tracking configuration has been saved.'));
106                $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminIssues',
107                                                array($prj->shortname));
108                return new Pluf_HTTP_Response_Redirect($url);
109            }
110        } else {
111            $params = array();
112            $keys = array('labels_issue_open', 'labels_issue_closed',
113                          'labels_issue_predefined', 'labels_issue_one_max');
114            foreach ($keys as $key) {
115                $_val = $conf->getVal($key, false);
116                if ($_val !== false) {
117                    $params[$key] = $_val;
118                }
119            }
120            if (count($params) == 0) {
121                $params = null; //Nothing in the db, so new form.
122            }
123            $form = new IDF_Form_IssueTrackingConf($params);
124        }
125        return Pluf_Shortcuts_RenderToResponse('admin/issue-tracking.html',
126                                               array(
127                                                     'page_title' => $title,
128                                                     'form' => $form,
129                                                     ),
130                                               $request);
131    }
132
133    /**
134     * Administrate the downloads of a project.
135     */
136    public $adminDownloads_precond = array('IDF_Precondition::projectOwner');
137    public function adminDownloads($request, $match)
138    {
139        $prj = $request->project;
140        $title = sprintf(__('%s Downloads Configuration'), (string) $prj);
141        $conf = new IDF_Conf();
142        $conf->setProject($prj);
143        if ($request->method == 'POST') {
144            $form = new IDF_Form_UploadConf($request->POST);
145            if ($form->isValid()) {
146                foreach ($form->cleaned_data as $key=>$val) {
147                    $conf->setVal($key, $val);
148                }
149                $request->user->setMessage(__('The downloads configuration has been saved.'));
150                $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminDownloads',
151                                                array($prj->shortname));
152                return new Pluf_HTTP_Response_Redirect($url);
153            }
154        } else {
155            $params = array();
156            $keys = array('labels_download_predefined', 'labels_download_one_max');
157            foreach ($keys as $key) {
158                $_val = $conf->getVal($key, false);
159                if ($_val !== false) {
160                    $params[$key] = $_val;
161                }
162            }
163            if (count($params) == 0) {
164                $params = null; //Nothing in the db, so new form.
165            }
166            $form = new IDF_Form_UploadConf($params);
167        }
168        return Pluf_Shortcuts_RenderToResponse('admin/downloads.html',
169                                               array(
170                                                     'page_title' => $title,
171                                                     'form' => $form,
172                                                     ),
173                                               $request);
174    }
175
176    /**
177     * Administrate the members of a project.
178     */
179    public $adminMembers_precond = array('IDF_Precondition::projectOwner');
180    public function adminMembers($request, $match)
181    {
182        $prj = $request->project;
183        $title = sprintf(__('%s Project Members'), (string) $prj);
184        $params = array(
185                        'project' => $prj,
186                        'user' => $request->user,
187                        );
188        if ($request->method == 'POST') {
189            $form = new IDF_Form_MembersConf($request->POST, $params);
190            if ($form->isValid()) {
191                $form->save();
192                $request->user->setMessage(__('The project membership has been saved.'));
193                $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminMembers',
194                                                array($prj->shortname));
195                return new Pluf_HTTP_Response_Redirect($url);
196            }
197        } else {
198            $form = new IDF_Form_MembersConf($prj->getMembershipData('string'), $params);
199        }
200        return Pluf_Shortcuts_RenderToResponse('admin/members.html',
201                                               array(
202                                                     'page_title' => $title,
203                                                     'form' => $form,
204                                                     ),
205                                               $request);
206    }
207
208    /**
209     * Administrate the access rights to the tabs.
210     */
211    public $adminTabs_precond = array('IDF_Precondition::projectOwner');
212    public function adminTabs($request, $match)
213    {
214        $prj = $request->project;
215        $title = sprintf(__('%s Tabs Access Rights'), (string) $prj);
216        $extra = array(
217                       'conf' => $request->conf,
218                       );
219        if ($request->method == 'POST') {
220            $form = new IDF_Form_TabsConf($request->POST, $extra);
221            if ($form->isValid()) {
222                foreach ($form->cleaned_data as $key=>$val) {
223                    $request->conf->setVal($key, $val);
224                }
225                $request->user->setMessage(__('The project tabs access rights have been saved.'));
226                $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminTabs',
227                                                array($prj->shortname));
228                return new Pluf_HTTP_Response_Redirect($url);
229            }
230        } else {
231            $params = array();
232            $keys = array('downloads_access_rights', 'source_access_rights',
233                          'issues_access_rights');
234            foreach ($keys as $key) {
235                $_val = $request->conf->getVal($key, false);
236                if ($_val !== false) {
237                    $params[$key] = $_val;
238                }
239            }
240            if (count($params) == 0) {
241                $params = null; //Nothing in the db, so new form.
242            }
243            $form = new IDF_Form_TabsConf($params, $extra);
244        }
245        return Pluf_Shortcuts_RenderToResponse('admin/tabs.html',
246                                               array(
247                                                     'page_title' => $title,
248                                                     'form' => $form,
249                                                     ),
250                                               $request);
251    }
252}

Archive Download this file

Branches:
dev
master
newdiff
svn