Fixed issue 105 point 2, added deletion of a project.

Note that the source code is not deleted at the moment.
This commit is contained in:
Loic d'Anterroches 2009-02-27 10:42:18 +01:00
parent f986184254
commit 7f4f14e78d
7 changed files with 257 additions and 2 deletions

View File

@ -0,0 +1,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;
}
}

View File

@ -425,6 +425,57 @@ class IDF_Project extends Pluf_Model
return $this->_pconf; return $this->_pconf;
} }
/**
* 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 * Needs to be called when you update the memberships of a
* project. * project.

View File

@ -142,6 +142,39 @@ class IDF_Views_Admin
$request); $request);
} }
/**
* 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. * Users overview.
* *

View File

@ -417,6 +417,12 @@ $ctl[] = array('regex' => '#^/admin/projects/create/$#',
'model' => 'IDF_Views_Admin', 'model' => 'IDF_Views_Admin',
'method' => 'projectCreate'); 'method' => 'projectCreate');
$ctl[] = array('regex' => '#^/admin/projects/(\d+)/delete/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Admin',
'method' => 'projectDelete');
$ctl[] = array('regex' => '#^/admin/users/$#', $ctl[] = array('regex' => '#^/admin/users/$#',
'base' => $base, 'base' => $base,
'priority' => 4, 'priority' => 4,

View File

@ -0,0 +1,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}

View File

@ -34,9 +34,10 @@
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td> <td> {aurl 'url', 'IDF_Views_Admin::projectDelete', array($project.id)}
<input type="submit" value="{trans 'Update Project'}" name="submit" /> <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> </td>
</tr> </tr>
</table> </table>

View File

@ -142,6 +142,10 @@ table.recent-issues {
width: 90%; width: 90%;
} }
table.minsize {
width: auto !important;
}
table.recent-issues tr.log { table.recent-issues tr.log {
border-bottom: 1px solid #e7ebe3; border-bottom: 1px solid #e7ebe3;
} }