Indefero

Indefero Commit Details


Date:2009-02-27 03:42:18 (15 years 9 months ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:7f4f14e78d66dff75033dcf302b42bafbc61de60
Parents: f986184254fbd3580f6564513ee2087bd5e0d742
Message:Fixed issue 105 point 2, added deletion of a project.

Note that the source code is not deleted at the moment.
Changes:

File differences

src/IDF/Form/Admin/ProjectDelete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 CĂ©ondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Delete a project.
*
* It is also removing the SCM files, so handle with care.
*
*/
class IDF_Form_Admin_ProjectDelete extends Pluf_Form
{
public $project = null;
public function initFields($extra=array())
{
$this->project = $extra['project'];
$this->user = $extra['user'];
$this->fields['code'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Confirmation code'),
'initial' => '',
));
$this->fields['agree'] = new Pluf_Form_Field_Boolean(
array('required' => true,
'label' => __('I have made a backup of all the important data of this project.'),
'initial' => '',
));
}
public function clean_code()
{
$code = $this->cleaned_data['code'];
if ($code != $this->getCode()) {
throw new Pluf_Form_Invalid(__('The confirmation code does not match. Please provide a valid confirmation code to delete the project.'));
}
return $code;
}
public function clean_agree()
{
if (!$this->cleaned_data['agree']) {
throw new Pluf_Form_Invalid(__('Sorry, you really need to backup your data before deletion.'));
}
return $this->cleaned_data['agree'];
}
public function getCode()
{
return substr(md5(Pluf::f('secret_key').$this->user->id.'.'.$this->project->id),
0, 8);
}
public function save($commit=true)
{
if (!$this->isValid()) {
throw new Exception(__('Cannot save the model from an invalid form.'));
}
// So, we drop the project, it will cascade and delete all the
// elements of the project. For large projects, this may use
// quite some memory.
$this->project->delete();
return true;
}
}
src/IDF/Project.php
426426
427427
428428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
429480
430481
431482
}
/**
* Get simple statistics about the project.
*
* This returns an associative array with number of tickets,
* number of downloads, etc.
*
* @return array Stats
*/
public function getStats()
{
$stats = array();
$stats['total'] = 0;
$what = array('downloads' => 'IDF_Upload',
'reviews' => 'IDF_Review',
'issues' => 'IDF_Issue',
'docpages' => 'IDF_WikiPage',
'commits' => 'IDF_Commit',
);
foreach ($what as $key=>$m) {
$i = Pluf::factory($m)->getCount(array('filter' => 'project='.(int)$this->id));
$stats[$key] = $i;
$stats['total'] += $i;
}
/**
* [signal]
*
* IDF_Project::getStats
*
* [sender]
*
* IDF_Project
*
* [description]
*
* This signal allows an application to update the statistics
* array of a project. For example to add the on disk size
* of the repository if available.
*
* [parameters]
*
* array('project' => $project,
* 'stats' => $stats)
*
*/
$params = array('project' => $this,
'stats' => $stats);
Pluf_Signal::send('IDF_Project::getStats',
'IDF_Project', $params);
return $stats;
}
/**
* Needs to be called when you update the memberships of a
* project.
*
src/IDF/Views/Admin.php
143143
144144
145145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
146179
147180
148181
}
/**
* Deletion of a project.
*
* Only the forge administrator can perform this operation.
*/
public $projectDelete_precond = array('Pluf_Precondition::adminRequired');
public function projectDelete($request, $match)
{
$project = Pluf_Shortcuts_GetObjectOr404('IDF_Project', $match[1]);
$title = sprintf(__('Delete %s Project'), $project);
$extra = array('project' => $project,
'user' => $request->user);
if ($request->method == 'POST') {
$form = new IDF_Form_Admin_ProjectDelete($request->POST, $extra);
if ($form->isValid()) {
$project = $form->save();
$request->user->setMessage(__('The project has been deleted.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::projects');
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$form = new IDF_Form_Admin_ProjectDelete(null, $extra);
}
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/projects/delete.html',
array(
'page_title' => $title,
'form' => $form,
'stats' => $project->getStats(),
'code' => $form->getCode(),
),
$request);
}
/**
* Users overview.
*
*/
src/IDF/conf/urls.php
417417
418418
419419
420
421
422
423
424
425
420426
421427
422428
'model' => 'IDF_Views_Admin',
'method' => 'projectCreate');
$ctl[] = array('regex' => '#^/admin/projects/(\d+)/delete/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Admin',
'method' => 'projectDelete');
$ctl[] = array('regex' => '#^/admin/users/$#',
'base' => $base,
'priority' => 4,
src/IDF/templates/idf/gadmin/projects/delete.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{extends "idf/gadmin/projects/base.html"}
{block body}
{if $form.errors}
<div class="px-message-error">
<p>{trans 'The form contains some errors. Please correct them to delete the project.'}</p>
{if $form.get_top_errors}
{$form.render_top_errors|unsafe}
{/if}
</div>
{/if}
<h2{if !$form.get_top_errors} class="top"{/if}>{trans 'Project Statistics'}</h2>
<table summary=" " class="recent-issues minsize">
<thead>
<tr><th><span class="px-header-title">{trans 'Tab'}</span></th><th><span class="px-header-title">{trans 'Number'}</span></th></tr>
</thead>
<tbody>
<tr><td class="right">{trans 'Downloads'}</td><td class="a-c">{$stats['downloads']}</td></tr>
<tr><td class="right">{trans 'Code reviews'}</td><td class="a-c">{$stats['reviews']}</td></tr>
<tr><td class="right">{trans 'Commits'}</td><td class="a-c">{$stats['commits']}</td></tr>
<tr><td class="right">{trans 'Issues'}</td><td class="a-c">{$stats['issues']}</td></tr>
<tr><td class="right">{trans 'Documentation pages'}</td><td class="a-c">{$stats['docpages']}</td></tr>
</tbody>
</table>
<h2>{trans 'Delete Project'}</h2>
<form method="post" action=".">
<table class="form" summary="">
<tr>
<td>&nbsp;</td>
<td>
{blocktrans}Confirmation code to confirm the deletion of the project:
<em>{$code}</em>.{/blocktrans}<br />
<br />
<strong>{$form.f.code.labelTag}:</strong>
{if $form.f.code.errors}{$form.f.code.fieldErrors}{/if}
{$form.f.code|unsafe}
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
{if $form.f.agree.errors}{$form.f.agree.fieldErrors}{/if}
{$form.f.agree|unsafe} <strong>{$form.f.agree.labelTag}</strong>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="{trans 'Delete Project'}" name="submit" />
| <a href="{url 'IDF_Views_Admin::projects'}">{trans 'Cancel'}</a>{if $stats['total'] > 200}<br />
<span class="helptext">{trans 'For large projects, the suppression can take a while, please be patient.'}</span>{/if}
</td>
</tr>
</table>
</form>
{/block}
{block context}
<div class="issue-submit-info">
<p>{blocktrans}
<strong>Attention!</strong> Deleting a project is a one second operation
with the consequences that <strong>all the data</strong> related to the
project <strong>will be deleted</strong>.
{/blocktrans}</p>
</div>
{/block}
src/IDF/templates/idf/gadmin/projects/update.html
3434
3535
3636
37
37
3838
39
39
40
4041
4142
4243
</tr>
<tr>
<td>&nbsp;</td>
<td>
<td> {aurl 'url', 'IDF_Views_Admin::projectDelete', array($project.id)}
<input type="submit" value="{trans 'Update Project'}" name="submit" />
| <a href="{url 'IDF_Views_Admin::projects'}">{trans 'Cancel'}</a>
| <a href="{url 'IDF_Views_Admin::projects'}">{trans 'Cancel'}</a> {if $isAdmin}
<span class="dellink"><a href="{$url}" title="{trans 'Delete this project'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}" title="{trans 'Delete this project'}">{trans 'Delete this project'}</a><br /><span class="note helptext">{trans 'You will be ask to confirm.'}</span></span>{/if}
</td>
</tr>
</table>
www/media/idf/css/style.css
142142
143143
144144
145
146
147
148
145149
146150
147151
width: 90%;
}
table.minsize {
width: auto !important;
}
table.recent-issues tr.log {
border-bottom: 1px solid #e7ebe3;
}

Archive Download the corresponding diff file

Page rendered in 0.10267s using 14 queries.