Sfoglia il codice sorgente

Fix #47 - dedup tags related to visibility

George S. Baugh 5 anni fa
parent
commit
81ba2a1835
3 ha cambiato i file con 15 aggiunte e 3 eliminazioni
  1. 7 0
      lib/Trog/Data/DUMMY.pm
  2. 6 3
      lib/Trog/Routes/HTML.pm
  3. 2 0
      www/templates/acls.tx

+ 7 - 0
lib/Trog/Data/DUMMY.pm

@@ -11,6 +11,7 @@ use JSON::MaybeXS;
 use File::Slurper;
 use File::Copy;
 use Mojo::File;
+use List::Util;
 
 =head1 WARNING
 
@@ -196,10 +197,16 @@ sub _process ($post) {
     delete $post->{route};
     delete $post->{domain};
 
+    # Handle acls/tags
     $post->{tags} //= [];
+    @{$post->{tags}} = grep { my $subj = $_; !grep { $_ eq $subj} qw{public private unlisted} } @{$post->{tags}};
     push(@{$post->{tags}}, delete $post->{acls}) if $post->{visibility} eq 'private';
     push(@{$post->{tags}}, delete $post->{visibility});
 
+    #Filter adding the same acl twice
+    @{$post->{tags}} = List::Util::uniq(@{$post->{tags}});
+
+    # Handle multimedia content types
     if ($post->{href}) {
         my $mf = Mojo::File->new("www/$post->{href}");
         my $ext = '.'.$mf->extname();

+ 6 - 3
lib/Trog/Routes/HTML.pm

@@ -433,6 +433,7 @@ sub post ($query, $render_cb) {
     if (!$query->{user}) {
         return login($query, $render_cb);
     }
+    $query->{acls} = _coerce_array($query->{acls});
     return forbidden($query, $render_cb) unless grep { $_ eq 'admin' } @{$query->{acls}};
 
     my $tags  = _coerce_array($query->{tag});
@@ -443,9 +444,11 @@ sub post ($query, $render_cb) {
     my (undef, $acls) = _post_helper({}, ['series'], $query->{acls});
 
     my $app = 'file';
-    $app = 'image' if $query->{route} =~ m/image$/;
-    $app = 'video' if $query->{route} =~ m/video$/;
-    $app = 'audio' if $query->{route} =~ m/audio$/;
+    if ($query->{route}) {
+        $app = 'image' if $query->{route} =~ m/image$/;
+        $app = 'video' if $query->{route} =~ m/video$/;
+        $app = 'audio' if $query->{route} =~ m/audio$/;
+    }
 
     return $render_cb->('post.tx', {
         title       => 'New Post',

+ 2 - 0
www/templates/acls.tx

@@ -8,7 +8,9 @@ Visibility<br />
     ACLs / Series<br/ >
     <select multiple class="cooltext" name="acls">
         : for $acls -> $acl {
+            : if ($acl.aclname != 'public' && $acl.aclname != 'private' && $acl.aclname != 'unlisted') {
             <option value="<: $acl.aclname :>"><: $acl.data :></option>
+            : }
         : }
     </select>
 </div>