global files and image no longer require a name/identifier
authorTony Cook <tony@develop-help.com>
Sat, 10 Aug 2013 04:16:03 +0000 (14:16 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 10 Aug 2013 04:16:03 +0000 (14:16 +1000)
site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/Edit/Site.pm
site/cgi-bin/modules/BSE/TB/ArticleFile.pm
site/cgi-bin/modules/BSE/TB/SiteCommon.pm
t/050-local/010-api.t

index 64d6ee21fe2cdc23a001d5e36127824d3ad092bd..b500bb04035255b7e633419ad54878ee7dae80a5 100644 (file)
@@ -16,7 +16,7 @@ use List::Util qw(first);
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
-our $VERSION = "1.039";
+our $VERSION = "1.040";
 
 =head1 NAME
 
@@ -3045,12 +3045,7 @@ sub save_image_changes {
     my $name = $cgi->param("name$id");
     if (defined $name && $name ne $image->{name}) {
       if ($name eq '') {
-       if ($article->{id} > 0) {
-         $changes{$id}{name} = '';
-       }
-       else {
-         $errors{"name$id"} = "Identifiers are required for global images";
-       }
+       $changes{$id}{name} = '';
       }
       elsif ($name =~ /^[a-z_]\w*$/i) {
        my $msg;
@@ -3840,12 +3835,7 @@ sub req_save_image {
       }
     }
     else {
-      if ($article->{id} == -1) {
-       $errors{name} = "Identifiers are required for global images";
-      }
-      else {
-       $image->{name} = '';
-      }
+      $image->{name} = '';
     }
   }
   my $filename = $cgi->param('image');
@@ -4090,9 +4080,6 @@ sub fileadd {
   $file{category}       ||= '';
 
   defined $file{name} or $file{name} = '';
-  if ($article->{id} == -1 && $file{name} eq '') {
-    $errors{name} = 'Identifier is required for global files';
-  }
   if (!$errors{name} && length $file{name} && $file{name} !~/^\w+$/) {
     $errors{name} = "Identifier must be a single word";
   }
@@ -4278,9 +4265,6 @@ sub filesave {
          $errors{"name_$id"} = "Invalid file identifier $name";
        }
       }
-      elsif ($article->{id} == -1) {
-       $errors{"name_$id"} = "Identifier is required for global files";
-      }
     }
     else {
       push @{$names{$file->{name}}}, $id
@@ -4683,10 +4667,6 @@ sub req_save_file {
        $errors{name} = "Invalid file identifier $name";
       }
     }
-    if (!$errors{name} && $article->{id} == -1) {
-      length $name
-       or $errors{name} = "Identifier is required for global files";
-    }
   }
 
   my @meta;
index 19341adf5a7b3435b6ce56f1f1a9bc2b2c23687a..2fb5bd52dbdfae27f0ed0cd69479131a74604c56 100644 (file)
@@ -15,7 +15,7 @@ BSE::Edit::Site - edit interface for the site itself.
 
 =cut
 
-our $VERSION = "1.011";
+our $VERSION = "1.012";
 
 use base 'BSE::Edit::Article';
 use BSE::TB::Site;
@@ -73,16 +73,6 @@ sub get_files {
   Articles->global_files;
 }
 
-sub validate_image_name {
-  my ($self, $name, $rmsg) = @_;
-
-  length $name and return 1;
-
-  $$rmsg = "Name must be supplied for global images";
-
-  return 0;
-}
-
 sub req_tagshow {
   my ($self, $req, $article, $articles, $msg, $errors) = @_;
 
index 494657d7a2d7603f82435d731b5f5cbd38d18e55..cad5f9bb516f011cb89980a5f41d15b306ad83d7 100644 (file)
@@ -6,7 +6,7 @@ use vars qw/@ISA/;
 @ISA = qw/Squirrel::Row/;
 use Carp 'confess';
 
-our $VERSION = "1.009";
+our $VERSION = "1.010";
 
 sub columns {
   return qw/id articleId displayName filename sizeInBytes description 
@@ -448,8 +448,6 @@ sub update {
   }
 
   my $name = $opts{name};
-  $self->id != -1 || defined $name && $name =~ /\S/
-    or die "name is required for global files\n";
   if (defined $name && $name =~ /\S/) {
     $name =~ /^\w+$/
       or die "name must be a single word\n";
index 5ac5cfd76284a22c13586f7190163d95721e2be1..d65453356607fbea2f6ceff6c335f07d487bcbdf 100644 (file)
@@ -2,7 +2,7 @@ package BSE::TB::SiteCommon;
 use strict;
 use Carp qw(confess);
 
-our $VERSION = "1.014";
+our $VERSION = "1.015";
 
 =head1 NAME
 
@@ -446,8 +446,6 @@ sub add_file {
   }
 
   my $name = $opts{name};
-  $self->id != -1 || defined $name && $name =~ /\S/
-    or die "name is required for global files\n";
   if (defined $name && $name =~ /\S/) {
     $name =~ /^\w+$/
       or die "name must be a single word\n";
index ee7fad35c67c424d572a681f14b16d105204a70e..2184103cb526474b4c989d127a179b1c76f0d32f 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use BSE::Test qw(make_ua base_url);
-use Test::More tests => 67;
+use Test::More tests => 68;
 use File::Spec;
 use File::Slurp;
 use Carp qw(confess);
@@ -243,6 +243,13 @@ undef $art;
     );
   ok($im3, "make a global image (a)");
 
+  my $im4 = bse_add_global_image
+    (
+     $cfg,
+     file => "t/data/govhouse.jpg",
+    );
+  ok($im4, "make a global image (no name)");
+
   my $site = bse_site();
   my @images = $site->images;
   cmp_ok(@images, '>=', 3, "we have some global images");
@@ -258,10 +265,8 @@ undef $art;
   my $named = $site->image_by_name($prefix . "A");
   is($named->id, $im3->id, "check we got the right image by name");
 
-  # fetch by index
-  my $byindex = $site->image_by_index(1);
-  is($byindex, undef, "all images named, none available by index");
-
+  ok($im4->remove, "remove the global image (no name)");
+  undef $im4;
   ok($im3->remove, "remove the global image");
   undef $im3;
   ok($im2->remove, "remove the global image");
@@ -272,6 +277,7 @@ undef $art;
     $im1->remove if $im1;
     $im2->remove if $im2;
     $im3->remove if $im3;
+    $im4->remove if $im4;
   }
 }