Implement resource deletion.

This commit is contained in:
Thomas Keller 2011-12-06 08:13:06 +01:00
parent a1c8a49430
commit 22dfab253b
4 changed files with 151 additions and 4 deletions

View File

@ -0,0 +1,64 @@
<?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-2011 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 documentation page.
*
* This is a hard delete of the page and the revisions.
*
*/
class IDF_Form_WikiResourceDelete extends Pluf_Form
{
protected $resource = null;
public function initFields($extra=array())
{
$this->resource = $extra['resource'];
$this->fields['confirm'] = new Pluf_Form_Field_Boolean(
array('required' => true,
'label' => __('Yes, I understand that the resource and all its revisions will be deleted.'),
'initial' => '',
));
}
/**
* Check the confirmation.
*/
public function clean_confirm()
{
if (!$this->cleaned_data['confirm']) {
throw new Pluf_Form_Invalid(__('You need to confirm the deletion.'));
}
return $this->cleaned_data['confirm'];
}
function save($commit=true)
{
if (!$this->isValid()) {
throw new Exception(__('Cannot save the model from an invalid form.'));
}
$this->resource->delete();
return true;
}
}

View File

@ -569,6 +569,45 @@ class IDF_Views_Wiki
$request);
}
/**
* Delete a Wiki resource.
*/
public $deleteResource_precond = array('IDF_Precondition::accessWiki',
'IDF_Precondition::projectMemberOrOwner');
public function deleteResource($request, $match)
{
$prj = $request->project;
$resource = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_Resource', $match[2]);
$prj->inOr404($resource);
$params = array('resource' => $resource);
if ($request->method == 'POST') {
$form = new IDF_Form_WikiResourceDelete($request->POST, $params);
if ($form->isValid()) {
$form->save();
$request->user->setMessage(__('The documentation resource has been deleted.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listResources',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$form = new IDF_Form_WikiResourceDelete(null, $params);
}
$title = sprintf(__('Delete Resource %s'), $resource->title);
$revision = $resource->get_current_revision();
$false = Pluf_DB_BooleanToDb(false, $resource->getDbConnection());
$revs = $resource->get_revisions_list(array('order' => 'creation_dtime DESC',
'filter' => 'is_head='.$false));
return Pluf_Shortcuts_RenderToResponse('idf/wiki/deleteResource.html',
array(
'page_title' => $title,
'resource' => $resource,
'form' => $form,
'rev' => $revision,
'revs' => $revs,
),
$request);
}
/**
* Get the wiki tags.
*

View File

@ -123,8 +123,7 @@ class IDF_Wiki_ResourceRevision extends Pluf_Model
function preDelete()
{
// if we kill off a head revision, ensure that we either mark a previous
// revision as head or kill off the resource record as well
// if we kill off a head revision, ensure that we either mark a previous revision as head
if ($this->is_head) {
$sql = new Pluf_SQL('wikiresource=%s and id!=%s', array($this->wikiresource, $this->id));
$revs = Pluf::factory('IDF_Wiki_ResourceRevision')->getList(array('filter'=>$sql->gen(), 'order'=>'id DESC'));
@ -132,8 +131,6 @@ class IDF_Wiki_ResourceRevision extends Pluf_Model
$previous = $revs[0];
$previous->is_head = true;
$previous->update();
} else {
$this->get_wikiresource()->delete();
}
}

View File

@ -0,0 +1,47 @@
{extends "idf/wiki/base.html"}
{block docclass}yui-t3{assign $inResourceView=true}{/block}
{block body}
<p>{blocktrans}If you delete this documentation resource, it will be removed from the database with all the associated revisions
and <strong>you will not be able to recover it</strong>. Any documentation pages that reference this resource,
will no longer be able to render it, but won't be deleted.{/blocktrans}</p>
<form method="post" action=".">
<table class="form" summary="">
<tr>
<td>&nbsp;</td>
<td>
{$form.f.confirm|unsafe} <strong>{$form.f.confirm.labelTag}</strong><br />
{if $form.f.confirm.errors}{$form.f.confirm.fieldErrors}{/if}
<input type="submit" value="{trans 'Delete Resource'}" name="submit" /> | <a href="{url 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title)}">{trans 'Cancel'}</a>
</td>
</tr>
</table>
</form>
<p class="desc">{$resource.summary}</p>
{assign $preview = $rev.renderRaw()}
{if $preview == ''}
{assign $preview = __('Unable to render preview for this MIME type.')}
{/if}
<p class="preview">{$preview|unsafe}</p>
<ul>
<li>{trans 'File size'}: {$rev.filesize|size}</li>
<li>{trans 'MIME type'}: {$resource.mime_type}</li>
<li><a href="{$rev.getRawURL(true)}">{trans 'Download this file'}</a></li>
</ul>
{/block}
{block context}
{assign $submitter = $resource.get_submitter()}
<p><strong>{trans 'Created:'}</strong> <span class="nobrk">{$resource.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
{if $rev.creation_dtime != $resource.creation_dtime}<p>{assign $submitter = $rev.get_submitter()}
<strong>{trans 'Updated:'}</strong> <span class="nobrk">{$rev.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>{/if}
{if $revs.count() > 0}
<p><strong>{trans 'Old Revisions'}</strong></p>
<ul>{foreach $revs as $old}
<li><a href="{url 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title), array('rev'=>$old.id)}">{$old.summary}</a></li>
{/foreach}</ul>
{/if}
{/block}