[Bps-public-commit] r16344 - in sd/trunk: . lib/App/SD/CLI/Command/Ticket lib/App/SD/CLI/Model
jesse at bestpractical.com
jesse at bestpractical.com
Fri Oct 17 22:18:16 EDT 2008
Author: jesse
Date: Fri Oct 17 22:18:16 2008
New Revision: 16344
Modified:
sd/trunk/ (props changed)
sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm
sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm
sd/trunk/lib/App/SD/CLI/Model/Ticket.pm
sd/trunk/lib/App/SD/Model/Ticket.pm
Log:
r46995 at 31b: jesse | 2008-10-17 23:02:11 +0100
* Switching our implementation of immutable props
* outfactoring some reusable code
Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm (original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Create.pm Fri Oct 17 22:18:16 2008
@@ -34,7 +34,6 @@
my %args = validate( @_, { template => 1, edited => 1, record => 1 } );
my $record = $args{record};
- my $do_not_edit = $record->props_not_to_edit;
my $updated = $args{edited};
( my $props_ref, my $comment ) = $self->parse_record_template($updated);
Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm (original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Update.pm Fri Oct 17 22:18:16 2008
@@ -30,7 +30,6 @@
my %args = validate( @_, { template => 1, edited => 1, record => 1 } );
my $record = $args{record};
- my $do_not_edit = $record->props_not_to_edit;
my $updated = $args{edited};
my ( $props_ref, $comment ) = $self->parse_record_template($updated);
@@ -40,9 +39,11 @@
# (deleting is currently the equivalent of setting to '', and
# we want to do this all in one changeset)
for my $prop ( keys %{ $record->get_props } ) {
- unless ( $prop =~ $do_not_edit ) {
+ next if ( grep { $_ eq $prop } $record->immutable_props );
+
+
$props_ref->{$prop} = '' if !exists $props_ref->{$prop};
- }
+
}
# don't add props that didn't change to the changeset
Modified: sd/trunk/lib/App/SD/CLI/Model/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Model/Ticket.pm (original)
+++ sd/trunk/lib/App/SD/CLI/Model/Ticket.pm Fri Oct 17 22:18:16 2008
@@ -86,41 +86,49 @@
=cut
sub create_record_template {
- my $self = shift;
+ my $self = shift;
my $record = shift;
- my $update ;
+ my $update;
- if ($record) { $update = 1 }
+ if ($record) { $update = 1 }
else {
-
- $record = $self->_get_record_object;
- $update = 0;
- }
+ $record = $self->_get_record_object;
+ $update = 0;
+ }
- my $props_not_to_edit = $record->props_not_to_edit;
- my (@metadata_order, @editable_order);
- my (%immutable_props, %editable_props);
+ my @do_not_edit = $record->immutable_props;
+ my ( @metadata_order, @editable_order );
+ my ( %immutable_props, %editable_props );
# separate out user-editable props so we can both show all
# the props that will be added to the new ticket and prevent
# users from being able to break things by changing props
# that shouldn't be changed, such as uuid
- for my $prop ($record->props_to_show) {
- if ($prop =~ $props_not_to_edit) {
- if ($prop eq 'id' && $update) {
+ #
+ # filter out props we don't want to present for editing
+ my %do_not_edit = map { $_ => 1 } @do_not_edit;
+
+
+ for my $prop ( $record->props_to_show ) {
+ if ( $do_not_edit{$prop}) {
+ if ( $prop eq 'id' && $update ) {
+
# id isn't a *real* prop, so we have to mess with it some more
push @metadata_order, $prop;
- $immutable_props{$prop} = $record->luid . ' (' . $record->uuid . ")";
- }
- elsif (!(($prop eq 'id' or $prop eq 'created') && !$update)) {
+ $immutable_props{$prop}
+ = $record->luid . ' (' . $record->uuid . ")";
+ } elsif ( !( ( $prop eq 'id' or $prop eq 'created' ) && !$update ) )
+ {
push @metadata_order, $prop;
+
# which came first, the chicken or the egg?
#
# we don't want to display id/created for ticket creates
# because they can't by their nature be specified until the
# ticket is actually created
- $immutable_props{$prop} = $update ? $record->prop($prop) : undef;
+ $immutable_props{$prop}
+ = $update ? $record->prop($prop) : undef;
}
} else {
push @editable_order, $prop;
@@ -129,14 +137,15 @@
}
# fill in prop defaults if we're creating a new ticket
- if (! $update) {
- $record->default_props(\%immutable_props);
- $record->default_props(\%editable_props);
+ if ( !$update ) {
+ $record->default_props( \%immutable_props );
+ $record->default_props( \%editable_props );
}
# fill in props specified on the commandline (overrides defaults)
- if ($self->has_arg('edit')) {
- map { $editable_props{$_} = $self->prop($_) if $self->has_prop($_) } @editable_order;
+ if ( $self->has_arg('edit') ) {
+ map { $editable_props{$_} = $self->prop($_) if $self->has_prop($_) }
+ @editable_order;
$self->delete_arg('edit');
}
@@ -150,23 +159,24 @@
);
# glue all the parts together
- return join( "\n\n",
+ return join(
+ "\n\n",
- $self->_build_template_section(
- header => metadata_separator,
- data => $immutable_props_string
- ),
-
- $self->_build_template_section(
- header => editable_props_separator,
- data => $editable_props_string
- ),
- $self->_build_template_section(
- header => comment_separator,
- data => ''
- )
+ $self->_build_template_section(
+ header => metadata_separator,
+ data => $immutable_props_string
+ ),
+
+ $self->_build_template_section(
+ header => editable_props_separator,
+ data => $editable_props_string
+ ),
+ $self->_build_template_section(
+ header => comment_separator,
+ data => ''
+ )
-);
+ );
}
sub _build_template_section {
Modified: sd/trunk/lib/App/SD/Model/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/Model/Ticket.pm (original)
+++ sd/trunk/lib/App/SD/Model/Ticket.pm Fri Oct 17 22:18:16 2008
@@ -76,14 +76,16 @@
=cut
sub validate_prop_status {
- my ($self, %args) = @_;
-
+ my ( $self, %args ) = @_;
# XXX: validater not called when a value is unset, so can't do
# mandatory check here
- return 1 if scalar grep { $args{props}{status} eq $_ } qw(new open closed stalled);
- $args{errors}{status} = "'".$args{props}->{status}."' is not a valid status";
+ return 1
+ if scalar grep { $args{props}{status} eq $_ }
+ @{ $self->app_handle->setting( label => 'statuses' )->get() };
+
+ $args{errors}{status} = "'" . $args{props}->{status} . "' is not a valid status";
return 0;
}
@@ -141,7 +143,7 @@
=cut
-sub props_not_to_edit { qr/^(id|creator|created|original_replica)$/ }
+sub immutable_props { qw(id creator created original_replica) }
=head2 is_overdue [$date]
More information about the Bps-public-commit
mailing list