[vhffs-dev] [1195] Let's honour tags visibility...

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1195
Author:   beuss
Date:     2008-05-18 21:04:08 +0200 (Sun, 18 May 2008)

Log Message:
-----------
Let's honour tags visibility...

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Constants.pm
    trunk/vhffs-api/src/Vhffs/Tag/Category.pm
    trunk/vhffs-api/src/Vhffs/Tag.pm
    trunk/vhffs-panel/group/prefs.pl


Modified: trunk/vhffs-api/src/Vhffs/Constants.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Constants.pm	2008-05-17 01:04:48 UTC (rev 1194)
+++ trunk/vhffs-api/src/Vhffs/Constants.pm	2008-05-18 19:04:08 UTC (rev 1195)
@@ -77,7 +77,7 @@
     TYPE_ML => 61,
     TYPE_CRON => 70,
     
-# Tags visibility
+# Tags visibility MUST BE ORDERED BY PRIVILEGE LEVEL!
 	TAG_VISIBILITY_PUBLIC		=> 1,
 	TAG_VISIBILITY_MODERATORS	=> 2,
 	TAG_VISIBILITY_ADMINS		=> 3,

Modified: trunk/vhffs-api/src/Vhffs/Tag/Category.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag/Category.pm	2008-05-17 01:04:48 UTC (rev 1194)
+++ trunk/vhffs-api/src/Vhffs/Tag/Category.pm	2008-05-18 19:04:08 UTC (rev 1195)
@@ -88,7 +88,7 @@
 	my $sql = q{SELECT tag_category_id, label, description, visibility, updated, updater_id
 		FROM vhffs_tag_category};
 	if(defined $visibility) {
-		$sql .= q{ WHERE visibility = ?};
+		$sql .= q{ WHERE visibility <= ?};
 		push  @params, $visibility;
 	}
 	$sql .= q{ ORDER BY label};

Modified: trunk/vhffs-api/src/Vhffs/Tag.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag.pm	2008-05-17 01:04:48 UTC (rev 1194)
+++ trunk/vhffs-api/src/Vhffs/Tag.pm	2008-05-18 19:04:08 UTC (rev 1195)
@@ -173,7 +173,7 @@
 
 =head2 get_tags
 
-    my $tags = $o->get_tags();
+    my $tags = $o->get_tags($access_level);
 Returns an array of all tag categories for an object. Each
 element contains {label, tags}, tags is an array containing
 all tags of the given category for this object ({tag_id, label}).
@@ -181,16 +181,18 @@
 =cut
 
 sub get_tags {
-	my ($o) = @_;
+	my ($o, $visibility) = @_;
 	
 	my $dbh = $o->get_db_object();
 	my $tags = [];
 	
-	my $sql = q{SELECT t.tag_id, t.label as tag_label, c.label as cat_label FROM vhffs_tag t INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
-			INNER JOIN vhffs_object_tag ot ON ot.tag_id = t.tag_id WHERE ot.object_id = ? ORDER BY c.label, t.label};
+	my $sql = q{SELECT t.tag_id, t.label as tag_label, c.label as cat_label
+			FROM vhffs_tag t INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
+			INNER JOIN vhffs_object_tag ot ON ot.tag_id = t.tag_id
+			WHERE ot.object_id = ? AND visibility <= ? ORDER BY c.label, t.label};
 	
 	my $sth = $dbh->prepare($sql);
-	$sth->execute($o->get_oid()) or return undef;
+	$sth->execute($o->get_oid(), $visibility) or return undef;
 
 	my $cat = undef;
 		

Modified: trunk/vhffs-panel/group/prefs.pl
===================================================================
--- trunk/vhffs-panel/group/prefs.pl	2008-05-17 01:04:48 UTC (rev 1194)
+++ trunk/vhffs-panel/group/prefs.pl	2008-05-18 19:04:08 UTC (rev 1195)
@@ -299,13 +299,17 @@
 }
 
 sub fill_tags {
-	my $categories = Vhffs::Tag::Category::get_all($vhffs);
+	my $visibility = ($user->is_admin() ? Vhffs::Constants::TAG_VISIBILITY_ADMINS :
+				($user->is_moderator() ? Vhffs::Constants::TAG_VISIBILITY_MODERATORS :
+					Vhffs::Constants::TAG_VISIBILITY_PUBLIC) ); 
+	my $categories =
+		Vhffs::Tag::Category::get_all($vhffs, $visibility);
 	foreach my $c (@{$categories}) {
 		$c->{tags} = Vhffs::Tag::get_by_category_id($vhffs, $c->{category_id});
 	}
 	$template->param( CATEGORIES => $categories );
 	
-	$template->param( CURRENT_TAGS => $group->get_tags );
+	$template->param( CURRENT_TAGS => $group->get_tags($visibility) );
 }
 
 sub add_tag {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/