[Rt-commit] rt branch, 4.4/disabled-articles, created. rt-4.2.5-208-gb58bac6
? sunnavy
sunnavy at bestpractical.com
Wed Oct 22 12:56:14 EDT 2014
The branch, 4.4/disabled-articles has been created
at b58bac6baf9166d830d810391b5e259727bbe9a8 (commit)
- Log -----------------------------------------------------------------
commit b58bac6baf9166d830d810391b5e259727bbe9a8
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 21 00:03:37 2014 +0800
don't delete articles, just disable them.
So the right "DeleteArticle" is renamed to "DisableArticle".
Note that in previous description of "ModifyArticle" right, it's:
Modify or delete articles in this class
it's not true because we only checked "DeleteArticle" in RT::Article->Delete,
so I fixed the description
Fixes: #19323
diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 847adfa..e1989b7 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -445,6 +445,7 @@ SortOrder NUMBER(11,0) DEFAULT 0 NOT NULL,
Class NUMBER(11,0) DEFAULT 0 NOT NULL,
Parent NUMBER(11,0) DEFAULT 0 NOT NULL,
URI varchar2(255),
+Disabled NUMBER(11,0) DEFAULT 0 NOT NULL,
Creator NUMBER(11,0) DEFAULT 0 NOT NULL,
Created DATE,
LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index c1ef22f..dbe28c5 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -677,6 +677,7 @@ SortOrder integer NOT NULL DEFAULT 0,
Class integer NOT NULL DEFAULT 0,
Parent integer NOT NULL DEFAULT 0,
URI varchar(255),
+Disabled smallint NOT NULL DEFAULT 0,
Creator integer NOT NULL DEFAULT 0,
Created TIMESTAMP NULL,
LastUpdatedBy integer NOT NULL DEFAULT 0,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index b748d85..7e06b76 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -483,6 +483,7 @@ SortOrder integer NOT NULL DEFAULT 0,
Class integer NOT NULL DEFAULT 0,
Parent integer NOT NULL DEFAULT 0,
URI varchar(255) collate NOCASE,
+Disabled smallint NOT NULL DEFAULT 0,
Creator integer NOT NULL DEFAULT 0,
Created TIMESTAMP NULL,
LastUpdatedBy integer NOT NULL DEFAULT 0,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index f1458b4..36884eb 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -470,6 +470,7 @@ CREATE TABLE Articles (
Class int(11) NOT NULL default '0',
Parent int(11) NOT NULL default '0',
URI varchar(255) character set ascii default NULL,
+ Disabled int(2) NOT NULL default '0',
Creator int(11) NOT NULL default '0',
Created datetime default NULL,
LastUpdatedBy int(11) NOT NULL default '0',
diff --git a/etc/upgrade/4.3.4/schema.Oracle b/etc/upgrade/4.3.4/schema.Oracle
new file mode 100644
index 0000000..9c3dbeb
--- /dev/null
+++ b/etc/upgrade/4.3.4/schema.Oracle
@@ -0,0 +1 @@
+ALTER TABLE Articles ADD COLUMN Disabled NUMBER(11,0) DEFAULT 0 NOT NULL;
diff --git a/etc/upgrade/4.3.4/schema.Pg b/etc/upgrade/4.3.4/schema.Pg
new file mode 100644
index 0000000..8e7bfaf
--- /dev/null
+++ b/etc/upgrade/4.3.4/schema.Pg
@@ -0,0 +1 @@
+ALTER TABLE Articles ADD COLUMN Disabled smallint NOT NULL DEFAULT 0;
diff --git a/etc/upgrade/4.3.4/schema.SQLite b/etc/upgrade/4.3.4/schema.SQLite
new file mode 100644
index 0000000..8e7bfaf
--- /dev/null
+++ b/etc/upgrade/4.3.4/schema.SQLite
@@ -0,0 +1 @@
+ALTER TABLE Articles ADD COLUMN Disabled smallint NOT NULL DEFAULT 0;
diff --git a/etc/upgrade/4.3.4/schema.mysql b/etc/upgrade/4.3.4/schema.mysql
new file mode 100644
index 0000000..17036d8
--- /dev/null
+++ b/etc/upgrade/4.3.4/schema.mysql
@@ -0,0 +1 @@
+ALTER TABLE Articles ADD COLUMN Disabled int(2) NOT NULL DEFAULT 0;
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index e2833f0..039a460 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -258,79 +258,25 @@ sub ValidateName {
=head2 Delete
-Delete all its transactions
-Delete all its custom field values
-Delete all its relationships
-Delete this article.
+ This doesn't really delete but disable the article.
=cut
sub Delete {
my $self = shift;
- unless ( $self->CurrentUserHasRight('DeleteArticle') ) {
- return ( 0, $self->loc("Permission Denied") );
- }
-
- $RT::Handle->BeginTransaction();
- my $linksto = $self->_Links( 'Target' );
- my $linksfrom = $self->_Links( 'Base' );
- my $cfvalues = $self->CustomFieldValues;
- my $txns = $self->Transactions;
- my $topics = $self->Topics;
-
- while ( my $item = $linksto->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $linksfrom->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $txns->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
+ return $self->SetDisabled(1);
+}
- while ( my $item = $cfvalues->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
+# }}}
- while ( my $item = $topics->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
+sub SetDisabled {
+ my $self = shift;
+ unless ( $self->CurrentUserHasRight('DisableArticle') ) {
+ return ( 0, $self->loc("Permission Denied") );
}
-
- $self->SUPER::Delete();
- $RT::Handle->Commit();
- return ( 1, $self->loc('Article Deleted') );
-
+ return $self->SUPER::SetDisabled(@_);
}
-# }}}
-
# {{{ Children
=head2 Children
@@ -764,6 +710,21 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
=cut
+=head2 Disabled
+
+Returns the current value of Disabled.
+(In the database, Disabled is stored as int(2).)
+
+
+
+=head2 SetDisabled VALUE
+
+
+Set Disabled to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Disabled will be stored as a int(2).)
+
+
=head2 Creator
@@ -819,6 +780,8 @@ sub _CoreAccessible {
{read => 1, write => 1, type => 'int(11)', default => '0'},
URI =>
{read => 1, write => 1, type => 'varchar(255)', default => ''},
+ Disabled =>
+ {read => 1, write => 1, type => 'int(2)', default => '0'},
Creator =>
{read => 1, auto => 1, type => 'int(11)', default => '0'},
Created =>
diff --git a/lib/RT/Articles.pm b/lib/RT/Articles.pm
index 97a4708..0fd0ec1 100644
--- a/lib/RT/Articles.pm
+++ b/lib/RT/Articles.pm
@@ -57,6 +57,7 @@ sub Table {'Articles'}
sub _Init {
my $self = shift;
+ $self->{'with_disabled_column'} = 1;
$self->OrderByCols(
{ FIELD => 'SortOrder', ORDER => 'ASC' },
{ FIELD => 'Name', ORDER => 'ASC' },
diff --git a/lib/RT/Class.pm b/lib/RT/Class.pm
index 01c0d79..00d47ea 100644
--- a/lib/RT/Class.pm
+++ b/lib/RT/Class.pm
@@ -89,14 +89,14 @@ __PACKAGE__->AddRight( Staff => CreateArticle => 'Create articles in thi
__PACKAGE__->AddRight( General => ShowArticle => 'See articles in this class'); # loc
__PACKAGE__->AddRight( Staff => ShowArticleHistory => 'See changes to articles in this class'); # loc
__PACKAGE__->AddRight( General => SeeCustomField => 'View custom field values' ); # loc
-__PACKAGE__->AddRight( Staff => ModifyArticle => 'Modify or delete articles in this class'); # loc
+__PACKAGE__->AddRight( Staff => ModifyArticle => 'Modify articles in this class'); # loc
__PACKAGE__->AddRight( Staff => ModifyArticleTopics => 'Modify topics for articles in this class'); # loc
__PACKAGE__->AddRight( Staff => ModifyCustomField => 'Modify custom field values' ); # loc
__PACKAGE__->AddRight( Admin => AdminClass => 'Modify metadata and custom fields for this class'); # loc
__PACKAGE__->AddRight( Admin => AdminTopics => 'Modify topic hierarchy associated with this class'); # loc
__PACKAGE__->AddRight( Admin => ShowACL => 'Display Access Control List'); # loc
__PACKAGE__->AddRight( Admin => ModifyACL => 'Create, modify and delete Access Control List entries'); # loc
-__PACKAGE__->AddRight( Staff => DeleteArticle => 'Delete articles in this class'); # loc
+__PACKAGE__->AddRight( Staff => DisableArticle => 'Disable articles in this class'); # loc
# {{{ Create
diff --git a/share/html/Articles/Article/Delete.html b/share/html/Articles/Article/Delete.html
deleted file mode 100644
index 22dc303..0000000
--- a/share/html/Articles/Article/Delete.html
+++ /dev/null
@@ -1,106 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
-%# <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
-%# LICENSE:
-%#
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%#
-%# This work 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 Street, Fifth Floor, Boston, MA
-%# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%#
-%#
-%# CONTRIBUTION SUBMISSION POLICY:
-%#
-%# (The following paragraph is not intended to limit the rights granted
-%# to you to modify and distribute this software under the terms of
-%# the GNU General Public License and is only of importance to you if
-%# you choose to contribute your changes and enhancements to the
-%# community by submitting them to Best Practical Solutions, LLC.)
-%#
-%# By intentionally submitting any modifications, corrections or
-%# derivatives to this work, or any other work intended for use with
-%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-%# you are the copyright holder for those contributions and you grant
-%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
-%# royalty-free, perpetual, license to use, copy, create derivative
-%# works based on those contributions, and sublicense and distribute
-%# those contributions and any derivatives thereof.
-%#
-%# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, Title => $title &>
-<& /Elements/Tabs &>
-
-% if ($ARGS{'Delete'}) {
-<%$title%>
-<& /Elements/ListActions, actions => \@results &>
-
-% } else {
-<b><&|/l&>Are you sure you want to delete this article?</&></b>
-<table>
-<tr>
-<td align="left">
-<form action="Display.html" method="get">
-<input type="hidden" name="id" value="<%$ArticleObj->Id%>" />
-<input type="submit" value="<&|/l&>No</&>" />
-</form>
-
-</td>
-<td align="right">
-<form action="Delete.html" method="post">
-<input type="hidden" name="id" value="<%$ArticleObj->Id%>" />
-<input type="hidden" name="Delete" value="yes" />
-<input type="submit" value="<&|/l&>Yes</&>" />
-</form>
-</td>
-
-</tr>
-</table>
-% }
-<%INIT>
-
-my @results;
-
-my $title;
-my $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
-
-
-$ArticleObj->Load($id);
-unless ( $ArticleObj->id ) {
- $m->comp("/Elements/Error", Why => loc("Unable to load article") );
-}
-
-
-unless ( $ArticleObj->CurrentUserHasRight('ModifyArticle') ) {
- $m->comp("/Elements/Error", Why => loc("No permission to modify article"));
-}
-
-if ($ARGS{'Delete'} eq 'yes') {
- $ArticleObj->Delete();
- $title = loc('Article #[_1] deleted', $ArticleObj->Id);
-}
-
-else {
- $title = loc('Delete article #[_1]', $ArticleObj->Id);
-}
-</%INIT>
-<%ARGS>
-$id => undef
-</%ARGS>
diff --git a/share/html/Articles/Article/Edit.html b/share/html/Articles/Article/Edit.html
index 609450b..763cdb2 100644
--- a/share/html/Articles/Article/Edit.html
+++ b/share/html/Articles/Article/Edit.html
@@ -198,7 +198,7 @@ else {
Why => loc("Unable to load article") );
}
- my @attribs = qw(Name Summary Class);
+ my @attribs = qw(Name Summary Class Disabled);
@results = UpdateRecordObject(
AttributesRef => \@attribs,
diff --git a/share/html/Articles/Article/Elements/EditBasics b/share/html/Articles/Article/Elements/EditBasics
index 705cb0d..787cc12 100644
--- a/share/html/Articles/Article/Elements/EditBasics
+++ b/share/html/Articles/Article/Elements/EditBasics
@@ -64,6 +64,17 @@
% }
</td>
</tr>
+% if ($ARGS{'id'} eq 'new' || $ArticleObj->CurrentUserHasRight('DisableArticle')) {
+<tr>
+<td class="label"><&|/l&>Disabled</&></td>
+<td>
+ <select name="Disabled">
+ <option <% ( $ArticleObj->id && $ArticleObj->Disabled || $ARGS{'Disabled'} ) ? 'selected="selected"' : '' |n %> value="1"><&|/l&>Yes</&></option>
+ <option <% ( $ArticleObj->id && $ArticleObj->Disabled || $ARGS{'Disabled'} ) ? '' : 'selected="selected"' |n %> value="0"><&|/l&>No</&></option>
+ </select>
+</td>
+</tr>
+% }
<%INIT>
</%INIT>
<%ARGS>
diff --git a/share/html/Elements/EditLinks b/share/html/Elements/EditLinks
index 31415f0..ae619b2 100644
--- a/share/html/Elements/EditLinks
+++ b/share/html/Elements/EditLinks
@@ -55,6 +55,7 @@
<td class="labeltop"><& ShowRelationLabel, Object => $Object, Label => loc('Depends on').':', Relation => 'DependsOn' &></td>
<td class="value">
% while (my $link = $Object->DependsOn->Next) {
+% next if UNIVERSAL::isa($link->TargetObj, 'RT::Article') && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& ShowLink, URI => $link->TargetURI &></label><br />
% }
@@ -64,6 +65,7 @@
<td class="labeltop"><& ShowRelationLabel, Object => $Object, Label => loc('Depended on by').':', Relation => 'DependedOnBy' &></td>
<td class="value">
% while (my $link = $Object->DependedOnBy->Next) {
+% next if UNIVERSAL::isa($link->BaseObj, 'RT::Article') && $link->BaseObj->Disabled;
<input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& ShowLink, URI => $link->BaseURI &></label><br />
% }
@@ -73,6 +75,7 @@
<td class="labeltop"><& ShowRelationLabel, Object => $Object, Label => loc('Parents').':', Relation => 'Parents' &></td>
<td class="value">
% while (my $link = $Object->MemberOf->Next) {
+% next if UNIVERSAL::isa($link->TargetObj, 'RT::Article') && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& ShowLink, URI => $link->TargetURI &></label><br />
% }
@@ -82,6 +85,7 @@
<td class="labeltop"><& ShowRelationLabel, Object => $Object, Label => loc('Children').':', Relation => 'Children' &></td>
<td class="value">
% while (my $link = $Object->Members->Next) {
+% next if UNIVERSAL::isa($link->BaseObj, 'RT::Article') && $link->BaseObj->Disabled;
<input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& ShowLink, URI => $link->BaseURI &></label><br />
% }
@@ -91,6 +95,7 @@
<td class="labeltop"><& ShowRelationLabel, Object => $Object, Label => loc('Refers to').':', Relation => 'RefersTo' &></td>
<td class="value">
% while (my $link = $Object->RefersTo->Next) {
+% next if UNIVERSAL::isa($link->TargetObj, 'RT::Article') && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& ShowLink, URI => $link->TargetURI &></label><br />
%}
@@ -101,6 +106,7 @@
<td class="value">
% while (my $link = $Object->ReferredToBy->Next) {
% # Skip reminders
+% next if UNIVERSAL::isa($link->BaseObj, 'RT::Article') && $link->BaseObj->Disabled;
% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Ticket') && $link->BaseObj->Type eq 'reminder');
<input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& ShowLink, URI => $link->BaseURI &></label><br />
diff --git a/share/html/Elements/ShowLinksOfType b/share/html/Elements/ShowLinksOfType
index 9b332da..54b8d37 100644
--- a/share/html/Elements/ShowLinksOfType
+++ b/share/html/Elements/ShowLinksOfType
@@ -89,6 +89,7 @@ my $ModeObj = "${mode}Obj";
my (@active, @inactive, @not_tickets);
while (my $link = $links->Next) {
my $ToObj = $link->$ModeObj;
+ next if UNIVERSAL::isa($ToObj,'RT::Article') && $ToObj->Disabled;
if ($ToObj and $ToObj->isa('RT::Ticket')) {
next if $Type eq "ReferredToBy"
and $ToObj->Type eq 'reminder';
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index b2ff96d..d8cbbf8 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -890,7 +890,6 @@ my $build_main_nav = sub {
$tabs->child( display => title => loc('Display'), path => "/Articles/Article/Display.html?id=".$id );
$tabs->child( history => title => loc('History'), path => "/Articles/Article/History.html?id=".$id );
$tabs->child( modify => title => loc('Modify'), path => "/Articles/Article/Edit.html?id=".$id );
- $tabs->child( delete => title => loc('Delete'), path => "/Articles/Article/Delete.html?id=".$id );
}
}
@@ -914,9 +913,6 @@ my $build_main_nav = sub {
if ( $obj->CurrentUserHasRight('ModifyArticle') ) {
$tabs->child(modify => title => loc('Modify'), path => '/Articles/Article/Edit.html?id=' . $id );
}
- if ( $obj->CurrentUserHasRight('DeleteArticle') ) {
- $tabs->child(delete => title => loc('Delete'), path => '/Articles/Article/Delete.html?id=' . $id );
- }
}
}
diff --git a/t/articles/article.t b/t/articles/article.t
index 7a3474f..5c7fe06 100644
--- a/t/articles/article.t
+++ b/t/articles/article.t
@@ -80,7 +80,7 @@ ok ($val, "Article Deleted: $msg");
$a2 = RT::Article->new($RT::SystemUser);
$a2->Load($id);
-ok (!$a2->Id, "Did not find the article");
+ok ($a2->Disabled, "the article is disabled");
# NOT OK
#$RT::Handle->SimpleQuery("DELETE FROM Links");
diff --git a/t/articles/uri-articles.t b/t/articles/uri-articles.t
index 9ad4b07..52544df 100644
--- a/t/articles/uri-articles.t
+++ b/t/articles/uri-articles.t
@@ -36,13 +36,7 @@ ok ($uri->ParseURI("fsck.com-article://example.com/article/$article_id"),
ok ($article->Delete(), 'Deleted article');
-my $ret;
-warning_like {
- $ret = $uri->ParseURI("fsck.com-article://example.com/article/$article_id");
-} qr/Unable to load article for id $article_id. It may have been deleted/,
- "Warned about missing article";
-
-ok (!$ret, 'Returned false on missing article');
+ok($article->Disabled, 'deleted article is actually just disabled');
ok (!$uri->ParseURI("fsck.com-article://foo.com/article/$article_id"),
'ParseURI returned false with incorrect Organization');
-----------------------------------------------------------------------
More information about the rt-commit
mailing list